forked from TrueCloudLab/restic
Merge pull request #675 from restic/parent-check-hostname
Use the hostname filter to find a parent snasphot
This commit is contained in:
commit
e5617b5fd1
2 changed files with 10 additions and 4 deletions
|
@ -354,7 +354,13 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
|
||||||
|
|
||||||
// Find last snapshot to set it as parent, if not already set
|
// Find last snapshot to set it as parent, if not already set
|
||||||
if !opts.Force && parentSnapshotID == nil {
|
if !opts.Force && parentSnapshotID == nil {
|
||||||
id, err := restic.FindLatestSnapshot(repo, target, "")
|
hostname, err := os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
debug.Log("os.Hostname() returned err: %v", err)
|
||||||
|
hostname = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
id, err := restic.FindLatestSnapshot(repo, target, hostname)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
parentSnapshotID = &id
|
parentSnapshotID = &id
|
||||||
} else if err != restic.ErrNoSnapshotFound {
|
} else if err != restic.ErrNoSnapshotFound {
|
||||||
|
|
|
@ -145,8 +145,8 @@ func SamePaths(expected, actual []string) bool {
|
||||||
// ErrNoSnapshotFound is returned when no snapshot for the given criteria could be found.
|
// ErrNoSnapshotFound is returned when no snapshot for the given criteria could be found.
|
||||||
var ErrNoSnapshotFound = errors.New("no snapshot found")
|
var ErrNoSnapshotFound = errors.New("no snapshot found")
|
||||||
|
|
||||||
// FindLatestSnapshot finds latest snapshot with optional target/directory and source filters
|
// FindLatestSnapshot finds latest snapshot with optional target/directory and hostname filters.
|
||||||
func FindLatestSnapshot(repo Repository, targets []string, source string) (ID, error) {
|
func FindLatestSnapshot(repo Repository, targets []string, hostname string) (ID, error) {
|
||||||
var (
|
var (
|
||||||
latest time.Time
|
latest time.Time
|
||||||
latestID ID
|
latestID ID
|
||||||
|
@ -158,7 +158,7 @@ func FindLatestSnapshot(repo Repository, targets []string, source string) (ID, e
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ID{}, errors.Errorf("Error listing snapshot: %v", err)
|
return ID{}, errors.Errorf("Error listing snapshot: %v", err)
|
||||||
}
|
}
|
||||||
if snapshot.Time.After(latest) && SamePaths(snapshot.Paths, targets) && (source == "" || source == snapshot.Hostname) {
|
if snapshot.Time.After(latest) && SamePaths(snapshot.Paths, targets) && (hostname == "" || hostname == snapshot.Hostname) {
|
||||||
latest = snapshot.Time
|
latest = snapshot.Time
|
||||||
latestID = snapshotID
|
latestID = snapshotID
|
||||||
found = true
|
found = true
|
||||||
|
|
Loading…
Reference in a new issue