Skip to content

Instantly share code, notes, and snippets.

@negasora
Created March 17, 2020 01:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save negasora/be7af103cabf708f1c902ddcef735ba0 to your computer and use it in GitHub Desktop.
Save negasora/be7af103cabf708f1c902ddcef735ba0 to your computer and use it in GitHub Desktop.
import sqlite3, argparse
def remove_snapshots(fn):
conn = sqlite3.connect(fn)
c = conn.cursor()
c.execute("SELECT id,contents from snapshot ORDER BY id DESC LIMIT 1;")
last_snapshot,last_contents = c.fetchone()
c.execute(f"UPDATE snapshot set parent=NULL;")
c.execute(f"DELETE FROM snapshot WHERE id!={last_snapshot};")
c.execute(f"DELETE FROM file_contents WHERE id!={last_contents};")
c.execute(f"DELETE FROM file_section WHERE contents!={last_contents};")
conn.commit()
c.execute("VACUUM;")
conn.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Remove old snapshots from BNDB')
parser.add_argument('database', type=str, help='Database to trim')
args = parser.parse_args()
remove_snapshots(args.database)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment