From 744649e04436821337fd8ec3b2a1a31aa92c33c7 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Wed, 9 Dec 2015 13:29:58 +0000 Subject: [PATCH] add management/backup.py --restore --- CHANGELOG.md | 1 + management/backup.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 79314c84..4651873d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ System: * Z-Push (Exchange/ActiveSync) logs now exclude warnings and are now rotated to save disk space. * Fix pip command that might have not installed all necessary Python packages. * The control panel and backup would not work on Google Compute Engine because they install a conflicting boto package. +* Added a new command `management/backup.py --restore` to restore files from a backup to a target directory (command line arguments are passed to `duplicity restore`). v0.14 (November 4, 2015) ------------------------ diff --git a/management/backup.py b/management/backup.py index 63b8aa66..b627e1d1 100755 --- a/management/backup.py +++ b/management/backup.py @@ -314,6 +314,18 @@ def run_duplicity_verification(): env["STORAGE_ROOT"], ], get_env(env)) +def run_duplicity_restore(args): + env = load_environment() + config = get_backup_config(env) + backup_cache_dir = os.path.join(env["STORAGE_ROOT"], 'backup', 'cache') + shell('check_call', [ + "/usr/bin/duplicity", + "restore", + "--archive-dir", backup_cache_dir, + config["target"], + ] + args, + get_env(env)) + def list_target_files(config): import urllib.parse try: @@ -443,6 +455,11 @@ if __name__ == "__main__": ret = backup_status(load_environment()) print(rtyaml.dump(ret["backups"])) + elif len(sys.argv) >= 2 and sys.argv[1] == "--restore": + # Run duplicity restore. Rest of command line passed as arguments + # to duplicity. The restore path should be specified. + run_duplicity_restore(sys.argv[2:]) + else: # Perform a backup. Add --full to force a full backup rather than # possibly performing an incremental backup.