mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2026-03-23 18:57:23 +01:00
Change to the structure of the custom.yaml file
The structure of the custom.yaml file has been modified in order to simplify the reading and maintainability of the backup.py code and definitively fix problems related to backups on S3-compatible services not provided by AWS. In addition to improved code readability, it is now verified that backup also works on MinIO, solving issue #717.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
<h3>Configuration</h3>
|
||||
|
||||
<form class="form-horizontal" role="form" onsubmit="set_custom_backup(); return false;">
|
||||
<form class="form-horizontal" role="form" onsubmit="set_backup_configuration(); return false;">
|
||||
<div class="form-group">
|
||||
<label for="backup-target-type" class="col-sm-2 control-label">Backup to:</label>
|
||||
<div class="col-sm-2">
|
||||
@@ -78,33 +78,33 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group backup-target-s3">
|
||||
<label for="backup-target-s3-host" class="col-sm-2 control-label">S3 Host / Endpoint</label>
|
||||
<label for="backup-target-url" class="col-sm-2 control-label">S3 Target URL</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" placeholder="Endpoint" class="form-control" rows="1" id="backup-target-s3-host">
|
||||
<input type="text" placeholder="s3://your-bucket-name/your-backup-directory" class="form-control" rows="1" id="backup-target-url">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group backup-target-s3">
|
||||
<label for="backup-target-s3-region" class="col-sm-2 control-label">S3 Region</label>
|
||||
<label for="backup-s3-endpoint-url" class="col-sm-2 control-label">S3 Endpoint URL</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" placeholder="Region" class="form-control" rows="1" id="backup-target-s3-region">
|
||||
<input type="text" placeholder="https://objectstorage.example.org:9199" class="form-control" rows="1" id="backup-s3-endpoint-url">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group backup-target-s3">
|
||||
<label for="backup-target-s3-path" class="col-sm-2 control-label">S3 Path</label>
|
||||
<label for="backup-s3-region-name" class="col-sm-2 control-label">S3 Region Name</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" placeholder="your-bucket-name/backup-directory" class="form-control" rows="1" id="backup-target-s3-path">
|
||||
<input type="text" placeholder="region-name-1" class="form-control" rows="1" id="backup-s3-region-name">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group backup-target-s3">
|
||||
<label for="backup-target-user" class="col-sm-2 control-label">S3 Access Key</label>
|
||||
<label for="backup-s3-access-key-id" class="col-sm-2 control-label">S3 Access Key Id</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" rows="1" id="backup-target-user">
|
||||
<input type="text" class="form-control" rows="1" id="backup-s3-access-key-id">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group backup-target-s3">
|
||||
<label for="backup-target-pass" class="col-sm-2 control-label">S3 Secret Access Key</label>
|
||||
<label for="backup-s3-secret-access-key" class="col-sm-2 control-label">S3 Secret Access Key</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" class="form-control" rows="1" id="backup-target-pass">
|
||||
<input type="text" class="form-control" rows="1" id="backup-s3-secret-access-key">
|
||||
</div>
|
||||
</div>
|
||||
<!-- Backblaze -->
|
||||
@@ -186,7 +186,7 @@ function nice_size(bytes) {
|
||||
}
|
||||
|
||||
function show_system_backup() {
|
||||
show_custom_backup()
|
||||
show_backup_configuration()
|
||||
|
||||
$('#backup-status tbody').html("<tr><td colspan='2' class='text-muted'>Loading...</td></tr>")
|
||||
api(
|
||||
@@ -233,41 +233,57 @@ function show_system_backup() {
|
||||
})
|
||||
}
|
||||
|
||||
function show_custom_backup() {
|
||||
function show_backup_configuration() {
|
||||
$(".backup-target-local, .backup-target-rsync, .backup-target-s3, .backup-target-b2").hide();
|
||||
|
||||
api(
|
||||
"/system/ssh-public-key",
|
||||
"GET",
|
||||
{ },
|
||||
function(r) {
|
||||
$("#ssh-pub-key").val(r);
|
||||
})
|
||||
|
||||
api(
|
||||
"/system/backup/info",
|
||||
"GET",
|
||||
{ },
|
||||
function(r) {
|
||||
$(".backup-location").text(r.encrypted_directory);
|
||||
$(".backup-encpassword-file").text(r.encryption_key_file);
|
||||
})
|
||||
|
||||
api(
|
||||
"/system/backup/config",
|
||||
"GET",
|
||||
{ },
|
||||
function(r) {
|
||||
$("#backup-target-user").val(r.target_user);
|
||||
$("#backup-target-pass").val(r.target_pass);
|
||||
$("#min-age").val(r.min_age_in_days);
|
||||
$(".backup-location").text(r.file_target_directory);
|
||||
$(".backup-encpassword-file").text(r.enc_pw_file);
|
||||
$("#ssh-pub-key").val(r.ssh_pub_key);
|
||||
$("#backup-target-s3-region").val(r.target_region);
|
||||
|
||||
if (r.target == "file://" + r.file_target_directory) {
|
||||
$("#backup-target-type").val("local");
|
||||
} else if (r.target == "off") {
|
||||
if(r.type == "off") {
|
||||
$("#backup-target-type").val("off");
|
||||
} else if (r.target.substring(0, 8) == "rsync://") {
|
||||
} else if(r.type == "local") {
|
||||
$("#backup-target-type").val("local");
|
||||
$("#min-age").val(r.min_age_in_days);
|
||||
} else if(r.type == "rsync") {
|
||||
$("#min-age").val(r.min_age_in_days);
|
||||
$("#backup-target-type").val("rsync");
|
||||
var path = r.target.substring(8).split('//');
|
||||
var path = r.target_url.substring(8).split('//');
|
||||
var host_parts = path.shift().split('@');
|
||||
$("#backup-target-rsync-user").val(host_parts[0]);
|
||||
$("#backup-target-rsync-host").val(host_parts[1]);
|
||||
$("#backup-target-rsync-path").val('/'+path[0]);
|
||||
} else if (r.target.substring(0, 5) == "s3://") {
|
||||
} else if(r.type == "s3") {
|
||||
$("#backup-s3-access-key-id").val(r.s3_access_key_id);
|
||||
$("#backup-s3-secret-access-key").val(r.s3_secret_access_key);
|
||||
$("#backup-target-type").val("s3");
|
||||
var hostpath = r.target.substring(5).split('/');
|
||||
var host = hostpath.shift();
|
||||
$("#backup-target-s3-host").val(host);
|
||||
$("#backup-target-s3-path").val(hostpath.join('/'));
|
||||
} else if (r.target.substring(0, 5) == "b2://") {
|
||||
$("#backup-target-url").val(r.target_url);
|
||||
$("#backup-s3-endpoint").val(r.s3_endpoint_url);
|
||||
$("#backup-s3-region").val(r.s3_region_name);
|
||||
$("#min-age").val(r.min_age_in_days);
|
||||
} else if(r.type == "b2") {
|
||||
$("#min-age").val(r.min_age_in_days);
|
||||
$("#backup-target-type").val("b2");
|
||||
var targetPath = r.target.substring(5);
|
||||
var targetPath = r.target_url.substring(5);
|
||||
var b2_application_keyid = targetPath.split(':')[0];
|
||||
var b2_applicationkey = targetPath.split(':')[1].split('@')[0];
|
||||
var b2_bucket = targetPath.split('@')[1];
|
||||
@@ -275,45 +291,40 @@ function show_custom_backup() {
|
||||
$("#backup-target-b2-pass").val(b2_applicationkey);
|
||||
$("#backup-target-b2-bucket").val(b2_bucket);
|
||||
}
|
||||
|
||||
toggle_form()
|
||||
})
|
||||
}
|
||||
|
||||
function set_custom_backup() {
|
||||
var target_type = $("#backup-target-type").val();
|
||||
var target_user = $("#backup-target-user").val();
|
||||
var target_pass = $("#backup-target-pass").val();
|
||||
function set_backup_configuration() {
|
||||
|
||||
var target;
|
||||
var target_region = '';
|
||||
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();
|
||||
target_region = $("#backup-target-s3-region").val();
|
||||
} else if (target_type == "rsync") {
|
||||
target = "rsync://" + $("#backup-target-rsync-user").val() + "@" + $("#backup-target-rsync-host").val()
|
||||
+ "/" + $("#backup-target-rsync-path").val();
|
||||
target_user = '';
|
||||
} else if (target_type == "b2") {
|
||||
target = 'b2://' + $('#backup-target-b2-user').val() + ':' + $('#backup-target-b2-pass').val()
|
||||
+ '@' + $('#backup-target-b2-bucket').val()
|
||||
target_user = '';
|
||||
target_pass = '';
|
||||
var config = {
|
||||
type: $("#backup-target-type").val()
|
||||
};
|
||||
|
||||
if(config.type == "local") {
|
||||
config["min_age_in_days"] = $("#min-age").val();
|
||||
} else if(config.type == "rsync") {
|
||||
config["target_url"] = "rsync://" + $("#backup-target-rsync-user").val() + "@" + $("#backup-target-rsync-host").val() + "/" + $("#backup-target-rsync-path").val();
|
||||
config["min_age_in_days"] = $("#min-age").val();
|
||||
} else if(config.type == "s3") {
|
||||
config["s3_access_key_id"] = $("#backup-s3-access-key-id").val();
|
||||
config["s3_secret_access_key"] = $("#backup-s3-secret-access-key").val();
|
||||
config["min_age_in_days"] = $("#min-age").val();
|
||||
config["target_url"] = $("#backup-target-url").val();
|
||||
config["s3_endpoint_url"] = $("#backup-s3-endpoint-url").val();
|
||||
if($("#backup-s3-region-name").val()) {
|
||||
config["s3_region_name"] = $("#backup-s3-region-name").val();
|
||||
}
|
||||
} else if(config.type == "b2") {
|
||||
config["target_url"] = "b2://" + $("#backup-target-b2-user").val() + ":" + $("#backup-target-b2-pass").val() + "@" + $("#backup-target-b2-bucket").val()
|
||||
config["min_age_in_days"] = $("#min-age").val();
|
||||
}
|
||||
|
||||
var min_age = $("#min-age").val();
|
||||
|
||||
api(
|
||||
"/system/backup/config",
|
||||
"POST",
|
||||
{
|
||||
target: target,
|
||||
target_user: target_user,
|
||||
target_pass: target_pass,
|
||||
min_age: min_age,
|
||||
target_region: target_region
|
||||
},
|
||||
config,
|
||||
function(r) {
|
||||
// use .text() --- it's a text response, not html
|
||||
show_modal_error("Backup configuration", $("<p/>").text(r), function() { if (r == "OK") show_system_backup(); }); // refresh after modal on success
|
||||
|
||||
Reference in New Issue
Block a user