Add "prune database" command to lbs-util.
[cumulus.git] / lbs-util
index 33c9c75..4342601 100755 (executable)
--- a/lbs-util
+++ b/lbs-util
@@ -22,6 +22,16 @@ def get_passphrase():
     if not os.environ.has_key(ENV_KEY):
         os.environ[ENV_KEY] = getpass.getpass()
 
+# Delete old snapshots from the local database, though do not actually schedule
+# any segment cleaning.
+# Syntax: $0 --localdb=LOCALDB prune-db
+def cmd_prune_db():
+    db = lbs.LocalDatabase(options.localdb)
+
+    # Delete old snapshots from the local database.
+    db.garbage_collect()
+    db.commit()
+
 # Run the segment cleaner.
 # Syntax: $0 --localdb=LOCALDB clean
 def cmd_clean(clean_threshold=7.0):
@@ -68,10 +78,14 @@ def cmd_list_snapshot_sizes():
         previous = set(segments)
         print "%s: %.3f +%.3f -%.3f" % (s, size / 1024.0**2, added / 1024.0**2, removed / 1024.0**2)
 
-# Build checksum list for objects in the given segments
+# Build checksum list for objects in the given segments, or all segments if
+# none are specified.
 def cmd_object_checksums(segments):
+    get_passphrase()
     lowlevel = lbs.LowlevelDataStore(options.store)
     store = lbs.ObjectStore(lowlevel)
+    if len(segments) == 0:
+        segments = sorted(lowlevel.list_segments())
     for s in segments:
         for (o, data) in store.load_segment(s):
             csum = lbs.ChecksumCreator().update(data).compute()
@@ -121,6 +135,8 @@ cmd = args[0]
 args = args[1:]
 if cmd == 'clean':
     cmd_clean()
+elif cmd == 'prune-db':
+    cmd_prune_db()
 elif cmd == 'list-snapshots':
     cmd_list_snapshots()
 elif cmd == 'object-sums':