summaryrefslogtreecommitdiffstats
path: root/files/reprepro/snapshots
diff options
context:
space:
mode:
authorintrigeri <intrigeri@boum.org>2016-05-07 10:31:05 +0000
committerintrigeri <intrigeri@boum.org>2016-05-07 10:32:05 +0000
commit2817d9e379bca79229cb1728f7a5e2a1f3f56048 (patch)
tree7a04db1661d0b8898c2347004b7f933a657296bf /files/reprepro/snapshots
parentbad7187c56f135e14162f6fd10dc0443cb9ee331 (diff)
Add a tool to compact a reprepro DB.
Or any Berkeley DB, really.
Diffstat (limited to 'files/reprepro/snapshots')
-rwxr-xr-xfiles/reprepro/snapshots/time_based/tails-compact-reprepro-db34
1 files changed, 34 insertions, 0 deletions
diff --git a/files/reprepro/snapshots/time_based/tails-compact-reprepro-db b/files/reprepro/snapshots/time_based/tails-compact-reprepro-db
new file mode 100755
index 0000000..aba9b1d
--- /dev/null
+++ b/files/reprepro/snapshots/time_based/tails-compact-reprepro-db
@@ -0,0 +1,34 @@
+#!/usr/bin/python3
+
+import argparse
+import os.path
+
+from bsddb3 import db
+
+def print_stats(path, d):
+ d.stat_print()
+ print()
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--path', required=True,
+ help="Path to the file that contains the database")
+parser.add_argument('--db', required=True,
+ help="Name of the database (for example: references)")
+parser.add_argument('--compact-fillpercent', default=90, type=int,
+ help="Any page in the database below this percentage full is considered for compaction")
+args = parser.parse_args()
+
+size_before = os.path.getsize(args.path)
+print("Before compacting: {size} bytes".format(size=size_before))
+
+d = db.DB()
+d.open(args.path, dbname=args.db)
+for i in range(0, 10):
+ d.compact(compact_fillpercent=args.compact_fillpercent,
+ flags=db.DB_FREE_SPACE)
+d.close()
+
+size_after = os.path.getsize(args.path)
+print("After compacting: {size} bytes".format(size=size_after))
+
+print("⇒ saved {size} bytes".format(size=size_before - size_after))