From 91e4ea6e2fd4a112301adf64dc6f6fc7df1c64bd Mon Sep 17 00:00:00 2001 From: Leo Koppelkamm Date: Mon, 27 Jul 2015 22:09:58 +0200 Subject: [PATCH] Infer target_type from url --- management/backup.py | 16 +++++++++------- management/daemon.py | 1 - management/templates/system-backup.html | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/management/backup.py b/management/backup.py index 26426313..b974902b 100755 --- a/management/backup.py +++ b/management/backup.py @@ -22,8 +22,7 @@ backup_root = os.path.join(load_environment()["STORAGE_ROOT"], 'backup') # that depends on it is this many days old. default_config = { "max_age_in_days": 3, - "target": "file://" + os.path.join(backup_root, 'encrypted'), - "target_type": "file" + "target": "file://" + os.path.join(backup_root, 'encrypted') } def backup_status(env): @@ -164,12 +163,16 @@ def get_env(): env = { "PASSPHRASE" : get_passphrase() } - if config["target_type"] == 's3': + if get_target_type(config) == 's3': env["AWS_ACCESS_KEY_ID"] = config["target_user"] env["AWS_SECRET_ACCESS_KEY"] = config["target_pass"] return env - + +def get_target_type(config): + protocol = config["target"].split(":")[0] + return protocol + def perform_backup(full_backup): env = load_environment() @@ -267,7 +270,7 @@ def perform_backup(full_backup): # Change ownership of backups to the user-data user, so that the after-bcakup # script can access them. - if config["target_type"] == 'file': + if get_target_type(config) == 'file': shell('check_call', ["/bin/chown", "-R", env["STORAGE_USER"], backup_dir]) # Execute a post-backup script that does the copying to a remote server. @@ -304,7 +307,7 @@ def run_duplicity_verification(): ], get_env()) -def backup_set_custom(target, target_user, target_pass, target_type, max_age): +def backup_set_custom(target, target_user, target_pass, max_age): config = get_backup_config() # max_age must be an int @@ -314,7 +317,6 @@ def backup_set_custom(target, target_user, target_pass, target_type, max_age): config["target"] = target config["target_user"] = target_user config["target_pass"] = target_pass - config["target_type"] = target_type config["max_age_in_days"] = max_age write_backup_config(config) diff --git a/management/daemon.py b/management/daemon.py index c8d98eb1..3380e757 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -416,7 +416,6 @@ def backup_set_custom(): request.form.get('target', ''), request.form.get('target_user', ''), request.form.get('target_pass', ''), - request.form.get('target_type', ''), request.form.get('max_age', '') )) diff --git a/management/templates/system-backup.html b/management/templates/system-backup.html index fbad719f..7ff67d0d 100644 --- a/management/templates/system-backup.html +++ b/management/templates/system-backup.html @@ -142,8 +142,9 @@ function show_custom_backup() { "GET", { }, function(r) { + var target_type = r.target.split(':')[0] $("#target").val(r.target); - $("#target-type").val(r.target_type); + $("#target-type").val(target_type); $("#target-user").val(r.target_user); $("#target-pass").val(r.target_pass); $("#max-age").val(r.max_age_in_days); @@ -162,7 +163,6 @@ function set_custom_backup() { "POST", { target: target, - target_type: target_type, target_user: target_user, target_pass: target_pass, max_age: max_age