Last active
August 17, 2022 10:04
-
-
Save mijorus/d5087c7f9ca4fc1806c9aaa8021016f8 to your computer and use it in GitHub Desktop.
Exports your bitwarden passwords as temporary json, encrypts and uploads the file to your MEGA
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
#!/usr/bin/python3 | |
# both megacmd and bw-cli need to be installed and configured before running this script | |
# bw-cli from snap needs to be configured in order to write in the /tmp folder | |
# files will be uploaded in the /bw folder on MEGA | |
import sys | |
import os | |
import subprocess | |
from getpass import getpass | |
from datetime import datetime | |
def exec(cmd): | |
return subprocess.check_output(args=cmd, shell=True).decode('utf-8').strip() | |
if __name__ == '__main__': | |
print('Runnign backup...') | |
filename = datetime.now().strftime("%m-%d-%Y_%H:%M:%S") | |
filename = 'bw-backup_' + filename | |
pwd = getpass('Enter Bitwarden password: ') | |
session = None | |
try: | |
session = exec(f'bw unlock {pwd} --raw') | |
except Exception as e: | |
print('Failed to unlock your Bitwarden vault') | |
sys.exit(1) | |
try: | |
exec(f'bw sync --session {session}') | |
exec(f'bw export --output /tmp/{filename}.json --format json --session {session}') | |
exec(f'gpg --batch --passphrase {pwd} --symmetric /tmp/{filename}.json') | |
exec(f'mega-put -c /tmp/{filename}.json.gpg bw/{filename}.json.gpg') | |
exec('bw lock') | |
exec('mega-quit') | |
except Exception as e: | |
print(e) | |
finally: | |
if os.path.exists(f'/tmp/{filename}.json'): | |
exec(f'rm /tmp/{filename}.json') | |
if os.path.exists(f'/tmp/{filename}.json.gpg'): | |
exec(f'rm /tmp/{filename}.json.gpg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment