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:
parent
fa0dd684da
commit
e693802091
@ -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):
|
||||
|
@ -26,7 +26,7 @@
|
||||
<div class="form-group">
|
||||
<label for="target" class="col-sm-2 control-label">Maximum time to keep old backups (in days)</label>
|
||||
<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 class="form-group form-advanced">
|
||||
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user