From 9ca116d54537943ee65bb1e3368df9c802e43dcb Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sun, 9 Aug 2015 20:15:43 +0000 Subject: [PATCH] add an option to disable backups --- management/backup.py | 12 ++++++++++-- management/templates/system-backup.html | 15 +++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/management/backup.py b/management/backup.py index 4430103c..9101e28a 100755 --- a/management/backup.py +++ b/management/backup.py @@ -24,6 +24,10 @@ def backup_status(env): config = get_backup_config(env) now = datetime.datetime.now(dateutil.tz.tzlocal()) + # Are backups dissbled? + if config["target"] == "off": + return { } + backups = { } backup_cache_dir = os.path.join(backup_root, 'cache') @@ -174,6 +178,10 @@ def perform_backup(full_backup): backup_cache_dir = os.path.join(backup_root, 'cache') backup_dir = os.path.join(backup_root, 'encrypted') + # Are backups dissbled? + if config["target"] == "off": + return + # In an older version of this script, duplicity was called # such that it did not encrypt the backups it created (in # backup/duplicity), and instead openssl was called separately @@ -357,8 +365,8 @@ def backup_set_custom(env, target, target_user, target_pass, min_age): # Validate. try: - if config["target"] != "local": - # "local" isn't supported by the following function, which expects a full url in the target key, + if config["target"] not in ("off", "local"): + # these aren't supported by the following function, which expects a full url in the target key, # which is what is there except when loading the config prior to saving list_target_files(config) except ValueError as e: diff --git a/management/templates/system-backup.html b/management/templates/system-backup.html index 03eeb2c2..4c628629 100644 --- a/management/templates/system-backup.html +++ b/management/templates/system-backup.html @@ -14,6 +14,7 @@
@@ -29,7 +30,7 @@
Backups are stored in an Amazon Web Services S3 bucket. You must have an AWS account already.
-
+
@@ -122,7 +123,11 @@ function show_system_backup() { $('#backup-status tbody').html(""); var total_disk_size = 0; - if (r.backups.length == 0) { + if (typeof r.backups == "undefined") { + var tr = $('Backups are turned off.'); + $('#backup-status tbody').append(tr); + return; + } else if (r.backups.length == 0) { var tr = $('No backups have been made yet.'); $('#backup-status tbody').append(tr); } @@ -157,6 +162,8 @@ function show_custom_backup() { function(r) { if (r.target == "file://" + r.file_target_directory) { $("#backup-target-type").val("local"); + } else if (r.target == "off") { + $("#backup-target-type").val("off"); } else if (r.target.substring(0, 5) == "s3://") { $("#backup-target-type").val("s3"); var hostpath = r.target.substring(5).split('/'); @@ -179,7 +186,7 @@ function set_custom_backup() { var target_pass = $("#backup-target-pass").val(); var target; - if (target_type == "local") + if (target_type == "local" || target_type == "off") target = target_type; else if (target_type == "s3") target = "s3://" + $("#backup-target-s3-host").val() + "/" + $("#backup-target-s3-path").val(); @@ -196,7 +203,7 @@ function set_custom_backup() { }, function(r) { // Responses are multiple lines of pre-formatted text. - show_modal_error("Backup configuration", $("
").text(r));
+      show_modal_error("Backup configuration", $("
").text(r), function() { show_system_backup(); }); // refresh after modal
     },
     function(r) {
       show_modal_error("Backup configuration (error)", r);