mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 21:05:10 +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:
parent
74ebc650ab
commit
2081bd12fb
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user