1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 16:26:11 +00:00

forget: Ensure future snapshots do not affect --keep-within-*

Ensure that only snapshots made in the past are taken into account when running restic forget with the within switches (--keep-within, --keep-within- hourly, and friends)
This commit is contained in:
Magnus Thor Torfason 2021-07-24 15:58:26 +00:00
parent 74ebc650ab
commit 2081bd12fb

View file

@ -147,15 +147,19 @@ func always(d time.Time, nr int) int {
return nr
}
// findLatestTimestamp returns the time stamp for the newest snapshot.
// findLatestTimestamp returns the time stamp for the latest (newest) snapshot,
// for use with policies based on time relative to latest.
func findLatestTimestamp(list Snapshots) time.Time {
if len(list) == 0 {
panic("list of snapshots is empty")
}
var latest time.Time
now := time.Now()
for _, sn := range list {
if sn.Time.After(latest) {
// Find the latest snapshot in the list
// The latest snapshot must, however, not be in the future.
if sn.Time.After(latest) && sn.Time.Before(now) {
latest = sn.Time
}
}