Skip to content

Instantly share code, notes, and snippets.

@0x1F9F1
Last active February 25, 2019 01:53
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save 0x1F9F1/64725fbe9acdeafaf39e048e03f4dd9d to your computer and use it in GitHub Desktop.
import sqlite3
import contextlib
import os
import sys
def clean_binja_snapshots(conn, limit = 1):
with conn as cur:
for section in [ 'snapshot', 'file_data' ]:
cur.execute(f'DELETE FROM {section} WHERE id NOT IN (SELECT id FROM {section} ORDER BY id DESC LIMIT ?)', (limit,))
with conn as cur:
cur.execute('VACUUM')
if __name__ == '__main__':
if len(sys.argv) > 1:
db_file = sys.argv[1]
else:
db_file = input('Enter *.bndn name: ')
if os.path.isfile(db_file):
with contextlib.closing(sqlite3.connect(db_file)) as conn:
conn.set_trace_callback(print)
clean_binja_snapshots(conn, 1)
else:
print('%s does not exist' % db_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment