Add btv gc NUMBER command
This commit is contained in:
parent
f58353fe87
commit
5c57e26652
1 changed files with 34 additions and 13 deletions
45
btv
45
btv
|
@ -327,7 +327,6 @@ def do_create(args):
|
|||
## do optional processing
|
||||
##
|
||||
if snapshot.rank == 2:
|
||||
|
||||
## snapshot serialization
|
||||
# if there's a previous Rank 2 snapshot, compute a diff against it
|
||||
# if not or if the process fails, demote this snap to Rank 1
|
||||
|
@ -493,23 +492,42 @@ def do_gc(args=None):
|
|||
Drops old snapshots.
|
||||
|
||||
If the only arg is "greedy", drops ALL snapshots except the youngest
|
||||
Rank 2.
|
||||
Rank 2. If it's a number, drops that many oldest snapshots.
|
||||
"""
|
||||
|
||||
if args and "greedy" in args:
|
||||
newest = list_snapshots(2)[-1]
|
||||
if args:
|
||||
if args[0] == "greedy":
|
||||
newest = list_snapshots(2)[-1]
|
||||
|
||||
if newest:
|
||||
print(">>> Dropping all snapshots except the newest Rank 2 in 5 s...")
|
||||
time.sleep(5)
|
||||
if newest:
|
||||
print(">>> Dropping all snapshots except the newest Rank 2 in 5 s...")
|
||||
time.sleep(5)
|
||||
|
||||
for snap in list_snapshots():
|
||||
if snap.name != newest.name:
|
||||
snap.drop()
|
||||
for snap in list_snapshots():
|
||||
if snap.name != newest.name:
|
||||
snap.drop()
|
||||
|
||||
else:
|
||||
print("!!! no Rank 2 snapshot exists")
|
||||
sys.exit(1)
|
||||
|
||||
else:
|
||||
print("!!! no Rank 2 snapshot exists")
|
||||
sys.exit(1)
|
||||
try:
|
||||
count = int(args[0])
|
||||
except ValueError:
|
||||
print("!!! %s is not a count of snapshots to delete" %(args[0]))
|
||||
sys.exit(1)
|
||||
|
||||
snaps = list_snapshots()[:count]
|
||||
|
||||
for snap in snaps:
|
||||
print(" %d %s %s" %(snap.rank, snap.name, ", ".join(snap.notes)))
|
||||
|
||||
print(">>> These snapshots will be dropped in 5 s...")
|
||||
time.sleep(5)
|
||||
|
||||
for snap in snaps:
|
||||
snap.drop()
|
||||
|
||||
else:
|
||||
counts = [0, 0, 0] # Rank 0, 1, 2
|
||||
|
@ -565,6 +583,9 @@ Verbs:
|
|||
|
||||
gc greedy
|
||||
Drop ALL snapshots except the newest Rank 2.
|
||||
|
||||
gc COUNT
|
||||
Drop COUNT oldest snapshots.
|
||||
""".format(cmd=sys.argv[0]))
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue