62 lines
2 KiB
Python
62 lines
2 KiB
Python
import argparse
|
|
import os
|
|
import logging
|
|
import datetime
|
|
import sys
|
|
|
|
from deltachat_rpc_client import DeltaChat, Rpc
|
|
|
|
def main():
|
|
homedir = default=os.getenv("HOME", ".")
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument(
|
|
"--db_path", type=str, default=homedir + "/.config/DeltaChat/accounts",
|
|
help="Path to DeltaChat directory",
|
|
)
|
|
parser.add_argument("--account", type=str, help="email address of the account to backup")
|
|
parser.add_argument("--output_dir", default=homedir, type=str, help="output directory")
|
|
parser.add_argument(
|
|
"--passphrase", type=str, default=os.environ.get("DC_BACKUP_PASSPHRASE", ""),
|
|
help="passphrase to encrypt the backup file. environment variable: DC_BACKUP_PASSPHRASE"
|
|
)
|
|
parser.add_argument("-v", "--verbose", action="store_true", help="print logs")
|
|
args = parser.parse_args()
|
|
|
|
if args.verbose:
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
path = os.environ.get("PATH")
|
|
venv_path = sys.argv[0].strip("backup-dc-from-db-cli")
|
|
os.environ["PATH"] = path + ":" + venv_path
|
|
|
|
with Rpc(accounts_dir=args.db_path) as rpc:
|
|
deltachat = DeltaChat(rpc)
|
|
system_info = deltachat.get_system_info()
|
|
logging.info("Running deltachat core %s", system_info.deltachat_core_version)
|
|
|
|
if not args.account:
|
|
print("Select an account:\n")
|
|
accounts = deltachat.get_all_accounts()
|
|
i = 0
|
|
for ac in accounts:
|
|
addr = ac.get_config('addr')
|
|
if addr == args.account:
|
|
account = ac
|
|
break
|
|
else:
|
|
print(f"{i}: {addr}")
|
|
i += 1
|
|
else:
|
|
try:
|
|
account = accounts[int(input("\nWhich account do you want to backup? "))]
|
|
except:
|
|
import pdb; pdb.set_trace()
|
|
|
|
print("Exporting backup...")
|
|
account.export_backup(args.output_dir, passphrase=args.passphrase)
|
|
print(f"Done. Backup written to {args.output_dir} directory")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|