backup: implement --skip-if-unchanged

This commit is contained in:
Michael Eischer
2024-05-22 16:38:00 +02:00
parent 7b4f81d964
commit 6869bdaaa8
6 changed files with 52 additions and 14 deletions

View File

@@ -767,6 +767,8 @@ type SnapshotOptions struct {
Time time.Time
ParentSnapshot *restic.Snapshot
ProgramVersion string
// SkipIfUnchanged omits the snapshot creation if it is identical to the parent snapshot.
SkipIfUnchanged bool
}
// loadParentTree loads a tree referenced by snapshot id. If id is null, nil is returned.
@@ -880,6 +882,13 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps
return nil, restic.ID{}, nil, err
}
if opts.ParentSnapshot != nil && opts.SkipIfUnchanged {
ps := opts.ParentSnapshot
if ps.Tree != nil && rootTreeID.Equal(*ps.Tree) {
return nil, restic.ID{}, arch.summary, nil
}
}
sn, err := restic.NewSnapshot(targets, opts.Tags, opts.Hostname, opts.Time)
if err != nil {
return nil, restic.ID{}, nil, err