From 9867c4bbb457fe6c11f181c209e8888ba3db5fde Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Tue, 25 Aug 2020 22:30:57 +0200 Subject: [PATCH] Add flag --iexclude-file to backup --- changelog/unreleased/issue-2427 | 7 ++++++ cmd/restic/cmd_backup.go | 42 ++++++++++++++++++++------------- doc/040_backup.rst | 1 + doc/manual_rest.rst | 1 + 4 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 changelog/unreleased/issue-2427 diff --git a/changelog/unreleased/issue-2427 b/changelog/unreleased/issue-2427 new file mode 100644 index 000000000..ecd6f88fc --- /dev/null +++ b/changelog/unreleased/issue-2427 @@ -0,0 +1,7 @@ +Enhancement: Add flag `--iexclude-file` to backup command + +The backup command now supports the flag `--iexclude-file` which is a +case-insensitive version of `--exclude-file`. + +https://github.com/restic/restic/issues/2427 +https://github.com/restic/restic/pull/2898 diff --git a/cmd/restic/cmd_backup.go b/cmd/restic/cmd_backup.go index f410fb1fd..7aa9a1d09 100644 --- a/cmd/restic/cmd_backup.go +++ b/cmd/restic/cmd_backup.go @@ -78,22 +78,23 @@ Exit status is 3 if some source data could not be read (incomplete snapshot crea // BackupOptions bundles all options for the backup command. type BackupOptions struct { - Parent string - Force bool - Excludes []string - InsensitiveExcludes []string - ExcludeFiles []string - ExcludeOtherFS bool - ExcludeIfPresent []string - ExcludeCaches bool - Stdin bool - StdinFilename string - Tags []string - Host string - FilesFrom []string - TimeStamp string - WithAtime bool - IgnoreInode bool + Parent string + Force bool + Excludes []string + InsensitiveExcludes []string + ExcludeFiles []string + InsensitiveExcludeFiles []string + ExcludeOtherFS bool + ExcludeIfPresent []string + ExcludeCaches bool + Stdin bool + StdinFilename string + Tags []string + Host string + FilesFrom []string + TimeStamp string + WithAtime bool + IgnoreInode bool } var backupOptions BackupOptions @@ -110,6 +111,7 @@ func init() { f.StringArrayVarP(&backupOptions.Excludes, "exclude", "e", nil, "exclude a `pattern` (can be specified multiple times)") f.StringArrayVar(&backupOptions.InsensitiveExcludes, "iexclude", nil, "same as --exclude `pattern` but ignores the casing of filenames") f.StringArrayVar(&backupOptions.ExcludeFiles, "exclude-file", nil, "read exclude patterns from a `file` (can be specified multiple times)") + f.StringArrayVar(&backupOptions.InsensitiveExcludeFiles, "iexclude-file", nil, "same as --exclude-file but ignores casing of `file`names in patterns") f.BoolVarP(&backupOptions.ExcludeOtherFS, "one-file-system", "x", false, "exclude other file systems") f.StringArrayVar(&backupOptions.ExcludeIfPresent, "exclude-if-present", nil, "takes `filename[:header]`, exclude contents of directories containing filename (except filename itself) if header of that file is as provided (can be specified multiple times)") f.BoolVar(&backupOptions.ExcludeCaches, "exclude-caches", false, `excludes cache directories that are marked with a CACHEDIR.TAG file. See https://bford.info/cachedir/ for the Cache Directory Tagging Standard`) @@ -239,6 +241,14 @@ func collectRejectByNameFuncs(opts BackupOptions, repo *repository.Repository, t opts.Excludes = append(opts.Excludes, excludes...) } + if len(opts.InsensitiveExcludeFiles) > 0 { + excludes, err := readExcludePatternsFromFiles(opts.InsensitiveExcludeFiles) + if err != nil { + return nil, err + } + opts.InsensitiveExcludes = append(opts.InsensitiveExcludes, excludes...) + } + if len(opts.InsensitiveExcludes) > 0 { fs = append(fs, rejectByInsensitivePattern(opts.InsensitiveExcludes)) } diff --git a/doc/040_backup.rst b/doc/040_backup.rst index 4185bb914..a3a354475 100644 --- a/doc/040_backup.rst +++ b/doc/040_backup.rst @@ -142,6 +142,7 @@ the exclude options are: - ``--iexclude`` Same as ``--exclude`` but ignores the case of paths - ``--exclude-caches`` Specified once to exclude folders containing a special file - ``--exclude-file`` Specified one or more times to exclude items listed in a given file +- ``--iexclude-file`` Same as ``exclude-file`` but ignores cases like in ``--iexclude`` - ``--exclude-if-present foo`` Specified one or more times to exclude a folder's content if it contains a file called ``foo`` (optionally having a given header, no wildcards for the file name supported) Please see ``restic help backup`` for more specific information about each exclude option. diff --git a/doc/manual_rest.rst b/doc/manual_rest.rst index e2fc51a6e..76ced2653 100644 --- a/doc/manual_rest.rst +++ b/doc/manual_rest.rst @@ -97,6 +97,7 @@ command: -h, --help help for backup -H, --host hostname set the hostname for the snapshot manually. To prevent an expensive rescan use the "parent" flag --iexclude pattern same as --exclude pattern but ignores the casing of filenames + --iexclude-file file same as --exclude-file but ignores casing of filenames in patterns --ignore-inode ignore inode number changes when checking for modified files -x, --one-file-system exclude other file systems --parent snapshot use this parent snapshot (default: last snapshot in the repo that has the same target files/directories)