Add iexclude option to backup command
This commit is contained in:
parent
6dc7cca597
commit
db82e6b80c
2 changed files with 30 additions and 14 deletions
|
@ -68,20 +68,21 @@ given as the arguments.
|
||||||
|
|
||||||
// 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
|
||||||
ExcludeFiles []string
|
InsensitiveExcludes []string
|
||||||
ExcludeOtherFS bool
|
ExcludeFiles []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
|
||||||
|
WithAtime bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var backupOptions BackupOptions
|
var backupOptions BackupOptions
|
||||||
|
@ -93,6 +94,7 @@ func init() {
|
||||||
f.StringVar(&backupOptions.Parent, "parent", "", "use this parent snapshot (default: last snapshot in the repo that has the same target files/directories)")
|
f.StringVar(&backupOptions.Parent, "parent", "", "use this parent snapshot (default: last snapshot in the repo that has the same target files/directories)")
|
||||||
f.BoolVarP(&backupOptions.Force, "force", "f", false, `force re-reading the target files/directories (overrides the "parent" flag)`)
|
f.BoolVarP(&backupOptions.Force, "force", "f", false, `force re-reading the target files/directories (overrides the "parent" flag)`)
|
||||||
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` 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.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)")
|
||||||
|
@ -222,6 +224,10 @@ func collectRejectByNameFuncs(opts BackupOptions, repo *repository.Repository, t
|
||||||
opts.Excludes = append(opts.Excludes, excludes...)
|
opts.Excludes = append(opts.Excludes, excludes...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(opts.InsensitiveExcludes) > 0 {
|
||||||
|
fs = append(fs, rejectByInsensitivePattern(opts.InsensitiveExcludes))
|
||||||
|
}
|
||||||
|
|
||||||
if len(opts.Excludes) > 0 {
|
if len(opts.Excludes) > 0 {
|
||||||
fs = append(fs, rejectByPattern(opts.Excludes))
|
fs = append(fs, rejectByPattern(opts.Excludes))
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,16 @@ func rejectByPattern(patterns []string) RejectByNameFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Same as `rejectByPattern` but case insensitive.
|
||||||
|
func rejectByInsensitivePattern(patterns []string) RejectByNameFunc {
|
||||||
|
for index, path := range patterns {
|
||||||
|
patterns[index] = strings.ToLower(path)
|
||||||
|
}
|
||||||
|
return func(item string) bool {
|
||||||
|
return rejectByPattern(patterns)(strings.ToLower(item))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// rejectIfPresent returns a RejectByNameFunc which itself returns whether a path
|
// rejectIfPresent returns a RejectByNameFunc which itself returns whether a path
|
||||||
// should be excluded. The RejectByNameFunc considers a file to be excluded when
|
// should be excluded. The RejectByNameFunc considers a file to be excluded when
|
||||||
// it resides in a directory with an exclusion file, that is specified by
|
// it resides in a directory with an exclusion file, that is specified by
|
||||||
|
|
Loading…
Reference in a new issue