Commit 3dc04cf0 authored by Robert Ricci's avatar Robert Ricci

Working version of the prune command

I still need to add a 'dry run' flag and one to limit the pruning
to a specific place
parent e1b0c7d9
......@@ -76,21 +76,21 @@ class Calendar:
k,r = all_candidates(self.today_by_hour, self.hour_target)
keep.extend(k)
remove.extend(r)
print("### Hourly: Keep {}, Remove {}, K: {}".format(len(k),len(r),k))
#print("### Hourly: Keep {}, Remove {}, K: {}".format(len(k),len(r),k))
k,r = all_candidates(self.this_month_by_day, self.day_target)
keep.extend(k)
remove.extend(r)
print("### Daily: Keep {}, Remove {}, K: {}".format(len(k),len(r),k))
#print("### Daily: Keep {}, Remove {}, K: {}".format(len(k),len(r),k))
k,r = all_candidates(self.this_year_by_month, self.month_target)
keep.extend(k)
remove.extend(r)
print("### Monthly Keep {}, Remove {}".format(len(k),len(r)))
#print("### Monthly Keep {}, Remove {}".format(len(k),len(r)))
k,r = all_candidates(self.previous_years_by_year, self.year_target)
keep.extend(k)
remove.extend(r)
print("### Yearly: Keep {}, Remove {}".format(len(k),len(r)))
#print("### Yearly: Keep {}, Remove {}".format(len(k),len(r)))
return list(map(lambda x: str(int(x.timestamp())), keep)), list(map(lambda x: str(int(x.timestamp())), remove))
......@@ -161,6 +161,15 @@ def prune():
cal = calendar.Calendar(snapshots[name])
count = len(snapshots[name])
keep, remove = cal.prune()
print ("%s: Total: %d Keep %d Remove %d" % (name,count,len(keep),len(remove)))
print("%s: Total: %d Keep %d Remove %d" % (name,count,len(keep),len(remove)))
for s in remove:
snap = snapshots[place.name][s]
print("Removing snapshot {}".format(s))
if snap.hasTarsnap() == Snapshot.Status.complete or snap.hasTarsnap() == Snapshot.Status.partial:
print(" ... tarsnap portion".format(snap))
tarsnap.deleteSnap(snap)
if snap.hasZFS() == Snapshot.Status.complete:
print(" ... zfs portion".format(snap))
zfs.deleteSnap(snap)
newCommand("prune", None, "Suggest which snapshots to prune", prune)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment