Skip to content

User Interface: Ignoring files/dirs for backup and restore? #226

@fd0

Description

@fd0

I'd like to propose a user interface for selecting and ignoring files to backup and restore (this connects to #86):

Add --exclude and --include to backup and restore, both parameters can be added multiple times and each specifies a pattern.

  • If neither --exclude nor --include is specified, all files are backed up or restored.
  • If only --include is specified (at least once), only the items that match the given pattern are backed up or restored.
  • If only --exclude is specified (at least once), all items except those that match the given pattern are backed up or restored.
  • If both --exclude and --include are specified, only those items are backed up that either
    • don't match any exclude pattern
    • match an exclude pattern and at least one include pattern

As for the pattern, I'd like to implement something that is easy to use. Some examples:

  • /proc matches all items below /proc, e.g. /proc/kcore
  • foo/* matches all items in a subdirectory of a directory called foo, e.g. /home/user/foo/test.txt
  • foo/**/bar*/*.c matches all items with the extension .c in a directory whose name begins with bar that somewhere has a parent directory called foo.

So, the rules are roughly:

  • If the pattern starts with a slash, the following name is meant absolute
  • If the pattern matches a directory, it matches all subdirs/items below, e.g. /proc is the same as /proc/*
  • Similar to shell globbing, * matches everything

Usage examples:

  • Backup everything except /proc,/sys and all vim swap files: restic backup --exclude /proc --exclude /sys --exclude "*.swp" /
  • Backup only c source code files ignoring everything else: restic backup --include "*.c" /home/user
  • Backup the user's home directory, excluding everything except c source code from the directory work: restic backup --exclude /home/user/work --include "*.c" /home/user

I think this can be implemented fairly easy by using filepath.Match.

What do you think about this approach? Are you aware of any use cases that aren't covered?

@restic/devs, @ceh, @rubenv, @howeyc, @rakoo

connects to #223 #161 #86

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions