mirror of
https://github.com/restic/restic.git
synced 2025-03-13 20:00:51 +00:00
Merge pull request #490 from Thor77/backupExcludeFile
add backup --exclude-file
This commit is contained in:
commit
32a5778602
@ -167,6 +167,20 @@ You can even backup individual files in the same repository.
|
|||||||
In fact several hosts may use the same repository to backup directories and
|
In fact several hosts may use the same repository to backup directories and
|
||||||
files leading to a greater de-duplication.
|
files leading to a greater de-duplication.
|
||||||
|
|
||||||
|
You can exclude folders and files by specifying exclude-patterns.
|
||||||
|
Either specify them with multiple `--exclude`'s or one `--exclude-file`
|
||||||
|
|
||||||
|
$ cat exclude
|
||||||
|
# exclude go-files
|
||||||
|
*.go
|
||||||
|
# exclude foo/x/y/z/bar foo/x/bar foo/bar
|
||||||
|
foo/**/bar
|
||||||
|
$ restic -r /tmp/backup backup ~/work --exclude=*.c --exclude-file=exclude
|
||||||
|
|
||||||
|
Patterns use [`filepath.Glob`](https://golang.org/pkg/path/filepath/#Glob) internally,
|
||||||
|
see [`filepath.Match`](https://golang.org/pkg/path/filepath/#Match) for syntax.
|
||||||
|
Additionally `**` exludes arbitrary subdirectories.
|
||||||
|
|
||||||
# List all snapshots
|
# List all snapshots
|
||||||
|
|
||||||
Now, you can list all the snapshots stored in the repository:
|
Now, you can list all the snapshots stored in the repository:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -17,9 +18,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CmdBackup struct {
|
type CmdBackup struct {
|
||||||
Parent string `short:"p" long:"parent" description:"use this parent snapshot (default: last snapshot in repo that has the same target)"`
|
Parent string `short:"p" long:"parent" description:"use this parent snapshot (default: last snapshot in repo that has the same target)"`
|
||||||
Force bool `short:"f" long:"force" description:"Force re-reading the target. Overrides the \"parent\" flag"`
|
Force bool `short:"f" long:"force" description:"Force re-reading the target. Overrides the \"parent\" flag"`
|
||||||
Excludes []string `short:"e" long:"exclude" description:"Exclude a pattern (can be specified multiple times)"`
|
Excludes []string `short:"e" long:"exclude" description:"Exclude a pattern (can be specified multiple times)"`
|
||||||
|
ExcludeFile string `long:"exclude-file" description:"Read exclude-patterns from file"`
|
||||||
|
|
||||||
global *GlobalOptions
|
global *GlobalOptions
|
||||||
}
|
}
|
||||||
@ -299,6 +301,23 @@ func (cmd CmdBackup) Execute(args []string) error {
|
|||||||
|
|
||||||
cmd.global.Verbosef("scan %v\n", target)
|
cmd.global.Verbosef("scan %v\n", target)
|
||||||
|
|
||||||
|
// add patterns from file
|
||||||
|
if cmd.ExcludeFile != "" {
|
||||||
|
file, err := os.Open(cmd.ExcludeFile)
|
||||||
|
if err != nil {
|
||||||
|
cmd.global.Warnf("error reading exclude patterns: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
if !strings.HasPrefix(line, "#") {
|
||||||
|
cmd.Excludes = append(cmd.Excludes, line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
selectFilter := func(item string, fi os.FileInfo) bool {
|
selectFilter := func(item string, fi os.FileInfo) bool {
|
||||||
matched, err := filter.List(cmd.Excludes, item)
|
matched, err := filter.List(cmd.Excludes, item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user