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

add an option to disable backups

This commit is contained in:
Joshua Tauberer 2015-08-09 20:15:43 +00:00
parent cdd3a64638
commit 9ca116d545
2 changed files with 21 additions and 6 deletions

View File

@ -24,6 +24,10 @@ def backup_status(env):
config = get_backup_config(env) config = get_backup_config(env)
now = datetime.datetime.now(dateutil.tz.tzlocal()) now = datetime.datetime.now(dateutil.tz.tzlocal())
# Are backups dissbled?
if config["target"] == "off":
return { }
backups = { } backups = { }
backup_cache_dir = os.path.join(backup_root, 'cache') 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_cache_dir = os.path.join(backup_root, 'cache')
backup_dir = os.path.join(backup_root, 'encrypted') 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 # In an older version of this script, duplicity was called
# such that it did not encrypt the backups it created (in # such that it did not encrypt the backups it created (in
# backup/duplicity), and instead openssl was called separately # 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. # Validate.
try: try:
if config["target"] != "local": if config["target"] not in ("off", "local"):
# "local" isn't supported by the following function, which expects a full url in the target key, # 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 # which is what is there except when loading the config prior to saving
list_target_files(config) list_target_files(config)
except ValueError as e: except ValueError as e:

View File

@ -14,6 +14,7 @@
<label for="backup-target-type" class="col-sm-2 control-label">Backup to:</label> <label for="backup-target-type" class="col-sm-2 control-label">Backup to:</label>
<div class="col-sm-2"> <div class="col-sm-2">
<select class="form-control" rows="1" id="backup-target-type" onchange="toggle_form()"> <select class="form-control" rows="1" id="backup-target-type" onchange="toggle_form()">
<option value="off">Nowhere (Disable Backups)</option>
<option value="local">{{hostname}}</option> <option value="local">{{hostname}}</option>
<option value="s3">Amazon S3</option> <option value="s3">Amazon S3</option>
</select> </select>
@ -29,7 +30,7 @@
<div>Backups are stored in an Amazon Web Services S3 bucket. You must have an AWS account already.</div> <div>Backups are stored in an Amazon Web Services S3 bucket. You must have an AWS account already.</div>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group backup-target-local backup-target-s3">
<label for="min-age" class="col-sm-2 control-label">How many days should backups be kept?</label> <label for="min-age" class="col-sm-2 control-label">How many days should backups be kept?</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input type="number" class="form-control" rows="1" id="min-age"> <input type="number" class="form-control" rows="1" id="min-age">
@ -122,7 +123,11 @@ function show_system_backup() {
$('#backup-status tbody').html(""); $('#backup-status tbody').html("");
var total_disk_size = 0; var total_disk_size = 0;
if (r.backups.length == 0) { if (typeof r.backups == "undefined") {
var tr = $('<tr><td colspan="3">Backups are turned off.</td></tr>');
$('#backup-status tbody').append(tr);
return;
} else if (r.backups.length == 0) {
var tr = $('<tr><td colspan="3">No backups have been made yet.</td></tr>'); var tr = $('<tr><td colspan="3">No backups have been made yet.</td></tr>');
$('#backup-status tbody').append(tr); $('#backup-status tbody').append(tr);
} }
@ -157,6 +162,8 @@ function show_custom_backup() {
function(r) { function(r) {
if (r.target == "file://" + r.file_target_directory) { if (r.target == "file://" + r.file_target_directory) {
$("#backup-target-type").val("local"); $("#backup-target-type").val("local");
} else if (r.target == "off") {
$("#backup-target-type").val("off");
} else if (r.target.substring(0, 5) == "s3://") { } else if (r.target.substring(0, 5) == "s3://") {
$("#backup-target-type").val("s3"); $("#backup-target-type").val("s3");
var hostpath = r.target.substring(5).split('/'); var hostpath = r.target.substring(5).split('/');
@ -179,7 +186,7 @@ function set_custom_backup() {
var target_pass = $("#backup-target-pass").val(); var target_pass = $("#backup-target-pass").val();
var target; var target;
if (target_type == "local") if (target_type == "local" || target_type == "off")
target = target_type; target = target_type;
else if (target_type == "s3") else if (target_type == "s3")
target = "s3://" + $("#backup-target-s3-host").val() + "/" + $("#backup-target-s3-path").val(); target = "s3://" + $("#backup-target-s3-host").val() + "/" + $("#backup-target-s3-path").val();
@ -196,7 +203,7 @@ function set_custom_backup() {
}, },
function(r) { function(r) {
// Responses are multiple lines of pre-formatted text. // Responses are multiple lines of pre-formatted text.
show_modal_error("Backup configuration", $("<pre/>").text(r)); show_modal_error("Backup configuration", $("<pre/>").text(r), function() { show_system_backup(); }); // refresh after modal
}, },
function(r) { function(r) {
show_modal_error("Backup configuration (error)", r); show_modal_error("Backup configuration (error)", r);