From e693802091c04e88da0755d0d3d5ea6afc3996c2 Mon Sep 17 00:00:00 2001 From: Leo Koppelkamm Date: Mon, 27 Jul 2015 22:18:19 +0200 Subject: [PATCH] Rename max_age to min_age Also clarify a comment and remove an unneeded type check --- management/backup.py | 29 +++++++++++-------------- management/templates/system-backup.html | 8 +++---- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/management/backup.py b/management/backup.py index 8448bbce..3cccf1ff 100755 --- a/management/backup.py +++ b/management/backup.py @@ -18,10 +18,11 @@ from utils import exclusive_process, load_environment, shell, wait_for_service backup_root = os.path.join(load_environment()["STORAGE_ROOT"], 'backup') # Default settings -# Destroy backups when the most recent increment in the chain -# that depends on it is this many days old. +# min_age_in_days is the minimum amount of days a backup will be kept before +# it is eligble to be removed. Backups might be kept much longer if there's no +# new full backup yet. default_config = { - "max_age_in_days": 3, + "min_age_in_days": 3, "target": "file://" + os.path.join(backup_root, 'encrypted') } @@ -101,11 +102,11 @@ def backup_status(env): # when the threshold is met. deleted_in = None if incremental_count > 0 and first_full_size is not None: - deleted_in = "approx. %d days" % round(config["max_age_in_days"] + (.5 * first_full_size - incremental_size) / (incremental_size/incremental_count) + .5) + deleted_in = "approx. %d days" % round(config["min_age_in_days"] + (.5 * first_full_size - incremental_size) / (incremental_size/incremental_count) + .5) # When will a backup be deleted? saw_full = False - days_ago = now - datetime.timedelta(days=config["max_age_in_days"]) + days_ago = now - datetime.timedelta(days=config["min_age_in_days"]) for bak in backups: if deleted_in: # Subsequent backups are deleted when the most recent increment @@ -248,7 +249,7 @@ def perform_backup(full_backup): shell('check_call', [ "/usr/bin/duplicity", "remove-older-than", - "%dD" % config["max_age_in_days"], + "%dD" % config["min_age_in_days"], "--archive-dir", backup_cache_dir, "--force", config["target"] @@ -307,17 +308,17 @@ def run_duplicity_verification(): ], get_env()) -def backup_set_custom(target, target_user, target_pass, max_age): +def backup_set_custom(target, target_user, target_pass, min_age): config = get_backup_config() - # max_age must be an int - if isinstance(max_age, str): - max_age = int(max_age) + # min_age must be an int + if isinstance(min_age, str): + min_age = int(min_age) config["target"] = target config["target_user"] = target_user config["target_pass"] = target_pass - config["max_age_in_days"] = max_age + config["min_age_in_days"] = min_age write_backup_config(config) @@ -332,11 +333,7 @@ def get_backup_config(): merged_config = default_config.copy() merged_config.update(config) - - # max_age must be an int - if isinstance(merged_config["max_age_in_days"], str): - merged_config["max_age_in_days"] = int(merged_config["max_age_in_days"]) - + return config def write_backup_config(newconfig): diff --git a/management/templates/system-backup.html b/management/templates/system-backup.html index 7ff67d0d..ed344281 100644 --- a/management/templates/system-backup.html +++ b/management/templates/system-backup.html @@ -26,7 +26,7 @@
- +
@@ -147,7 +147,7 @@ function show_custom_backup() { $("#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); + $("#min-age").val(r.min_age_in_days); toggle_form() }) } @@ -157,7 +157,7 @@ function set_custom_backup() { var target_type = $("#target-type").val(); var target_user = $("#target-user").val(); var target_pass = $("#target-pass").val(); - var max_age = $("#max-age").val(); + var min_age = $("#min-age").val(); api( "/system/backup/custom", "POST", @@ -165,7 +165,7 @@ function set_custom_backup() { target: target, target_user: target_user, target_pass: target_pass, - max_age: max_age + min_age: min_age }, function(r) { // Responses are multiple lines of pre-formatted text.