forked from TrueCloudLab/restic
Add flag --iexclude-file to backup
This commit is contained in:
parent
efb4a981cf
commit
9867c4bbb4
4 changed files with 35 additions and 16 deletions
7
changelog/unreleased/issue-2427
Normal file
7
changelog/unreleased/issue-2427
Normal file
|
@ -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
|
|
@ -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.
|
// BackupOptions bundles all options for the backup command.
|
||||||
type BackupOptions struct {
|
type BackupOptions struct {
|
||||||
Parent string
|
Parent string
|
||||||
Force bool
|
Force bool
|
||||||
Excludes []string
|
Excludes []string
|
||||||
InsensitiveExcludes []string
|
InsensitiveExcludes []string
|
||||||
ExcludeFiles []string
|
ExcludeFiles []string
|
||||||
ExcludeOtherFS bool
|
InsensitiveExcludeFiles []string
|
||||||
ExcludeIfPresent []string
|
ExcludeOtherFS bool
|
||||||
ExcludeCaches bool
|
ExcludeIfPresent []string
|
||||||
Stdin bool
|
ExcludeCaches bool
|
||||||
StdinFilename string
|
Stdin bool
|
||||||
Tags []string
|
StdinFilename string
|
||||||
Host string
|
Tags []string
|
||||||
FilesFrom []string
|
Host string
|
||||||
TimeStamp string
|
FilesFrom []string
|
||||||
WithAtime bool
|
TimeStamp string
|
||||||
IgnoreInode bool
|
WithAtime bool
|
||||||
|
IgnoreInode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var backupOptions BackupOptions
|
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.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.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.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.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.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`)
|
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...)
|
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 {
|
if len(opts.InsensitiveExcludes) > 0 {
|
||||||
fs = append(fs, rejectByInsensitivePattern(opts.InsensitiveExcludes))
|
fs = append(fs, rejectByInsensitivePattern(opts.InsensitiveExcludes))
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,6 +142,7 @@ the exclude options are:
|
||||||
- ``--iexclude`` Same as ``--exclude`` but ignores the case of paths
|
- ``--iexclude`` Same as ``--exclude`` but ignores the case of paths
|
||||||
- ``--exclude-caches`` Specified once to exclude folders containing a special file
|
- ``--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
|
- ``--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)
|
- ``--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.
|
Please see ``restic help backup`` for more specific information about each exclude option.
|
||||||
|
|
|
@ -97,6 +97,7 @@ command:
|
||||||
-h, --help help for backup
|
-h, --help help for backup
|
||||||
-H, --host hostname set the hostname for the snapshot manually. To prevent an expensive rescan use the "parent" flag
|
-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 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
|
--ignore-inode ignore inode number changes when checking for modified files
|
||||||
-x, --one-file-system exclude other file systems
|
-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)
|
--parent snapshot use this parent snapshot (default: last snapshot in the repo that has the same target files/directories)
|
||||||
|
|
Loading…
Reference in a new issue