Skip to content

Instantly share code, notes, and snippets.

@myersjustinc
Created March 6, 2023 04:03
Show Gist options
  • Save myersjustinc/cf134b370a2b8e1bb6b4062d9eef6236 to your computer and use it in GitHub Desktop.
Save myersjustinc/cf134b370a2b8e1bb6b4062d9eef6236 to your computer and use it in GitHub Desktop.
Diff two KeePassXC databases
#!/usr/bin/env python
from getpass import getpass
import sys
from pykeepass import PyKeePass
def main(db_1_path, db_2_path, key_file_path):
password = getpass()
db_1 = PyKeePass(db_1_path, password=password, keyfile=key_file_path)
db_2 = PyKeePass(db_2_path, password=password, keyfile=key_file_path)
db_1_entries = set(map(str, db_1.entries))
db_2_entries = set(map(str, db_2.entries))
in_1_but_not_2 = db_1_entries - db_2_entries
if in_1_but_not_2:
print('In {0} but not {1}:'.format(db_1_path, db_2_path))
print(' {0}'.format('\n '.join(sorted(in_1_but_not_2))))
in_2_but_not_1 = db_2_entries - db_1_entries
if in_2_but_not_1:
print('In {0} but not {1}:'.format(db_2_path, db_1_path))
print(' {0}'.format('\n '.join(sorted(in_2_but_not_1))))
if __name__ == '__main__':
try:
main(*sys.argv[1:])
except TypeError:
sys.stderr.write((
'Usage: {0} KDBX_PATH_1 KDBX_PATH_2 KEY_FILE_PATH\n'
).format(sys.argv[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment