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:
parent
5ae75e723c
commit
e288d7730b
@ -1,14 +1,12 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
# This script performs a backup of all user data:
|
||||
# 1) System services are stopped while a copy of user data is made.
|
||||
# 2) An incremental encrypted backup is made using duplicity into the
|
||||
# directory STORAGE_ROOT/backup/encrypted. The password used for
|
||||
# encryption is stored in backup/secret_key.txt.
|
||||
# 1) System services are stopped.
|
||||
# 2) An incremental encrypted backup is made using duplicity.
|
||||
# 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 rtyaml
|
||||
|
||||
@ -65,8 +63,8 @@ def backup_status(env):
|
||||
trap=True)
|
||||
if code != 0:
|
||||
# Command failed. This is likely due to an improperly configured remote
|
||||
# destination for the backups.
|
||||
return { }
|
||||
# destination for the backups or the last backup job terminated unexpectedly.
|
||||
raise Exception("Something is wrong with the backup: " + collection_status)
|
||||
for line in collection_status.split('\n'):
|
||||
if line.startswith(" full") or line.startswith(" inc"):
|
||||
backup = parse_line(line)
|
||||
@ -217,7 +215,13 @@ def perform_backup(full_backup):
|
||||
# will fail. Otherwise do a full backup when the size of
|
||||
# the increments since the most recent full backup are
|
||||
# large.
|
||||
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.
|
||||
shell('check_call', ["/usr/sbin/service", "php5-fpm", "stop"])
|
||||
|
@ -422,7 +422,10 @@ def do_updates():
|
||||
@authorized_personnel_only
|
||||
def backup_status():
|
||||
from backup import backup_status
|
||||
try:
|
||||
return json_response(backup_status(env))
|
||||
except Exception as e:
|
||||
return json_response({ "error": str(e) })
|
||||
|
||||
@app.route('/system/backup/config', methods=["GET"])
|
||||
@authorized_personnel_only
|
||||
|
@ -121,6 +121,11 @@ function show_system_backup() {
|
||||
"GET",
|
||||
{ },
|
||||
function(r) {
|
||||
if (r.error) {
|
||||
show_modal_error("Backup Error", $("<pre/>").text(r.error));
|
||||
return;
|
||||
}
|
||||
|
||||
$('#backup-status tbody').html("");
|
||||
var total_disk_size = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user