mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 23:06:32 +00:00
cmd_backup: filter non-existing target files/dirs
This commit is contained in:
parent
cbe4c92c83
commit
57eb1a4eea
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -202,6 +203,25 @@ func findLatestSnapshot(repo *repository.Repository, targets []string) (backend.
|
|||||||
return latestID, nil
|
return latestID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// filterExisting returns a slice of all existing items, or an error if no
|
||||||
|
// items exist at all.
|
||||||
|
func filterExisting(items []string) (result []string, err error) {
|
||||||
|
for _, item := range items {
|
||||||
|
_, err := os.Lstat(item)
|
||||||
|
if err != nil && os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
result = append(result, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result) == 0 {
|
||||||
|
return nil, errors.New("all target directories/files do not exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (cmd CmdBackup) Execute(args []string) error {
|
func (cmd CmdBackup) Execute(args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
|
return fmt.Errorf("wrong number of parameters, Usage: %s", cmd.Usage())
|
||||||
@ -215,6 +235,11 @@ func (cmd CmdBackup) Execute(args []string) error {
|
|||||||
target = append(target, d)
|
target = append(target, d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
target, err := filterExisting(target)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
repo, err := cmd.global.OpenRepository()
|
repo, err := cmd.global.OpenRepository()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user