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
|
## do optional processing
|
||||||
##
|
##
|
||||||
if snapshot.rank == 2:
|
if snapshot.rank == 2:
|
||||||
|
|
||||||
## snapshot serialization
|
## snapshot serialization
|
||||||
# if there's a previous Rank 2 snapshot, compute a diff against it
|
# 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
|
# 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.
|
Drops old snapshots.
|
||||||
|
|
||||||
If the only arg is "greedy", drops ALL snapshots except the youngest
|
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:
|
if args:
|
||||||
newest = list_snapshots(2)[-1]
|
if args[0] == "greedy":
|
||||||
|
newest = list_snapshots(2)[-1]
|
||||||
|
|
||||||
if newest:
|
if newest:
|
||||||
print(">>> Dropping all snapshots except the newest Rank 2 in 5 s...")
|
print(">>> Dropping all snapshots except the newest Rank 2 in 5 s...")
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
for snap in list_snapshots():
|
for snap in list_snapshots():
|
||||||
if snap.name != newest.name:
|
if snap.name != newest.name:
|
||||||
snap.drop()
|
snap.drop()
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("!!! no Rank 2 snapshot exists")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("!!! no Rank 2 snapshot exists")
|
try:
|
||||||
sys.exit(1)
|
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:
|
else:
|
||||||
counts = [0, 0, 0] # Rank 0, 1, 2
|
counts = [0, 0, 0] # Rank 0, 1, 2
|
||||||
|
@ -565,6 +583,9 @@ Verbs:
|
||||||
|
|
||||||
gc greedy
|
gc greedy
|
||||||
Drop ALL snapshots except the newest Rank 2.
|
Drop ALL snapshots except the newest Rank 2.
|
||||||
|
|
||||||
|
gc COUNT
|
||||||
|
Drop COUNT oldest snapshots.
|
||||||
""".format(cmd=sys.argv[0]))
|
""".format(cmd=sys.argv[0]))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue