1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-11-22 02:17:26 +00:00

Rename max_age to min_age

Also clarify a comment and remove an unneeded type check
This commit is contained in:
Leo Koppelkamm 2015-07-27 22:18:19 +02:00
parent fa0dd684da
commit e693802091
2 changed files with 17 additions and 20 deletions

View File

@ -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') backup_root = os.path.join(load_environment()["STORAGE_ROOT"], 'backup')
# Default settings # Default settings
# Destroy backups when the most recent increment in the chain # min_age_in_days is the minimum amount of days a backup will be kept before
# that depends on it is this many days old. # it is eligble to be removed. Backups might be kept much longer if there's no
# new full backup yet.
default_config = { default_config = {
"max_age_in_days": 3, "min_age_in_days": 3,
"target": "file://" + os.path.join(backup_root, 'encrypted') "target": "file://" + os.path.join(backup_root, 'encrypted')
} }
@ -101,11 +102,11 @@ def backup_status(env):
# when the threshold is met. # when the threshold is met.
deleted_in = None deleted_in = None
if incremental_count > 0 and first_full_size is not 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? # When will a backup be deleted?
saw_full = False 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: for bak in backups:
if deleted_in: if deleted_in:
# Subsequent backups are deleted when the most recent increment # Subsequent backups are deleted when the most recent increment
@ -248,7 +249,7 @@ def perform_backup(full_backup):
shell('check_call', [ shell('check_call', [
"/usr/bin/duplicity", "/usr/bin/duplicity",
"remove-older-than", "remove-older-than",
"%dD" % config["max_age_in_days"], "%dD" % config["min_age_in_days"],
"--archive-dir", backup_cache_dir, "--archive-dir", backup_cache_dir,
"--force", "--force",
config["target"] config["target"]
@ -307,17 +308,17 @@ def run_duplicity_verification():
], get_env()) ], 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() config = get_backup_config()
# max_age must be an int # min_age must be an int
if isinstance(max_age, str): if isinstance(min_age, str):
max_age = int(max_age) min_age = int(min_age)
config["target"] = target config["target"] = target
config["target_user"] = target_user config["target_user"] = target_user
config["target_pass"] = target_pass config["target_pass"] = target_pass
config["max_age_in_days"] = max_age config["min_age_in_days"] = min_age
write_backup_config(config) write_backup_config(config)
@ -333,10 +334,6 @@ def get_backup_config():
merged_config = default_config.copy() merged_config = default_config.copy()
merged_config.update(config) 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 return config
def write_backup_config(newconfig): def write_backup_config(newconfig):

View File

@ -26,7 +26,7 @@
<div class="form-group"> <div class="form-group">
<label for="target" class="col-sm-2 control-label">Maximum time to keep old backups (in days)</label> <label for="target" class="col-sm-2 control-label">Maximum time to keep old backups (in days)</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="number" class="form-control" rows="1" id="max-age"></input> <input type="number" class="form-control" rows="1" id="min-age"></input>
</div> </div>
</div> </div>
<div class="form-group form-advanced"> <div class="form-group form-advanced">
@ -147,7 +147,7 @@ function show_custom_backup() {
$("#target-type").val(target_type); $("#target-type").val(target_type);
$("#target-user").val(r.target_user); $("#target-user").val(r.target_user);
$("#target-pass").val(r.target_pass); $("#target-pass").val(r.target_pass);
$("#max-age").val(r.max_age_in_days); $("#min-age").val(r.min_age_in_days);
toggle_form() toggle_form()
}) })
} }
@ -157,7 +157,7 @@ function set_custom_backup() {
var target_type = $("#target-type").val(); var target_type = $("#target-type").val();
var target_user = $("#target-user").val(); var target_user = $("#target-user").val();
var target_pass = $("#target-pass").val(); var target_pass = $("#target-pass").val();
var max_age = $("#max-age").val(); var min_age = $("#min-age").val();
api( api(
"/system/backup/custom", "/system/backup/custom",
"POST", "POST",
@ -165,7 +165,7 @@ function set_custom_backup() {
target: target, target: target,
target_user: target_user, target_user: target_user,
target_pass: target_pass, target_pass: target_pass,
max_age: max_age min_age: min_age
}, },
function(r) { function(r) {
// Responses are multiple lines of pre-formatted text. // Responses are multiple lines of pre-formatted text.