Created
March 17, 2020 01:51
-
-
Save negasora/be7af103cabf708f1c902ddcef735ba0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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