Last active
February 25, 2019 01:53
-
-
Save 0x1F9F1/64725fbe9acdeafaf39e048e03f4dd9d 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 | |
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