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

backups: trap an error that occurs as early as getting the current backup status

This commit is contained in:
Joshua Tauberer 2016-01-02 16:25:36 -05:00
parent 5ae75e723c
commit e288d7730b
3 changed files with 22 additions and 10 deletions

View File

@ -1,14 +1,12 @@
#!/usr/bin/python3 #!/usr/bin/python3
# This script performs a backup of all user data: # This script performs a backup of all user data:
# 1) System services are stopped while a copy of user data is made. # 1) System services are stopped.
# 2) An incremental encrypted backup is made using duplicity into the # 2) An incremental encrypted backup is made using duplicity.
# directory STORAGE_ROOT/backup/encrypted. The password used for
# encryption is stored in backup/secret_key.txt.
# 3) The stopped services are restarted. # 3) The stopped services are restarted.
# 5) STORAGE_ROOT/backup/after-backup is executd if it exists. # 4) STORAGE_ROOT/backup/after-backup is executd if it exists.
import os, os.path, shutil, glob, re, datetime import os, os.path, shutil, glob, re, datetime, sys
import dateutil.parser, dateutil.relativedelta, dateutil.tz import dateutil.parser, dateutil.relativedelta, dateutil.tz
import rtyaml import rtyaml
@ -65,8 +63,8 @@ def backup_status(env):
trap=True) trap=True)
if code != 0: if code != 0:
# Command failed. This is likely due to an improperly configured remote # Command failed. This is likely due to an improperly configured remote
# destination for the backups. # destination for the backups or the last backup job terminated unexpectedly.
return { } raise Exception("Something is wrong with the backup: " + collection_status)
for line in collection_status.split('\n'): for line in collection_status.split('\n'):
if line.startswith(" full") or line.startswith(" inc"): if line.startswith(" full") or line.startswith(" inc"):
backup = parse_line(line) backup = parse_line(line)
@ -217,7 +215,13 @@ def perform_backup(full_backup):
# will fail. Otherwise do a full backup when the size of # will fail. Otherwise do a full backup when the size of
# the increments since the most recent full backup are # the increments since the most recent full backup are
# large. # large.
full_backup = full_backup or should_force_full(env) try:
full_backup = full_backup or should_force_full(env)
except Exception as e:
# This was the first call to duplicity, and there might
# be an error already.
print(e)
sys.exit(1)
# Stop services. # Stop services.
shell('check_call', ["/usr/sbin/service", "php5-fpm", "stop"]) shell('check_call', ["/usr/sbin/service", "php5-fpm", "stop"])

View File

@ -422,7 +422,10 @@ def do_updates():
@authorized_personnel_only @authorized_personnel_only
def backup_status(): def backup_status():
from backup import backup_status from backup import backup_status
return json_response(backup_status(env)) try:
return json_response(backup_status(env))
except Exception as e:
return json_response({ "error": str(e) })
@app.route('/system/backup/config', methods=["GET"]) @app.route('/system/backup/config', methods=["GET"])
@authorized_personnel_only @authorized_personnel_only

View File

@ -121,6 +121,11 @@ function show_system_backup() {
"GET", "GET",
{ }, { },
function(r) { function(r) {
if (r.error) {
show_modal_error("Backup Error", $("<pre/>").text(r.error));
return;
}
$('#backup-status tbody').html(""); $('#backup-status tbody').html("");
var total_disk_size = 0; var total_disk_size = 0;