From e288d7730b33771928f63a909e4f056e53063a34 Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Sat, 2 Jan 2016 16:25:36 -0500 Subject: [PATCH] backups: trap an error that occurs as early as getting the current backup status --- management/backup.py | 22 +++++++++++++--------- management/daemon.py | 5 ++++- management/templates/system-backup.html | 5 +++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/management/backup.py b/management/backup.py index b627e1d1..e31a753e 100755 --- a/management/backup.py +++ b/management/backup.py @@ -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. - 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. shell('check_call', ["/usr/sbin/service", "php5-fpm", "stop"]) diff --git a/management/daemon.py b/management/daemon.py index 27e18e8f..d223b040 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -422,7 +422,10 @@ def do_updates(): @authorized_personnel_only def 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"]) @authorized_personnel_only diff --git a/management/templates/system-backup.html b/management/templates/system-backup.html index 9f919bec..1e538ecd 100644 --- a/management/templates/system-backup.html +++ b/management/templates/system-backup.html @@ -121,6 +121,11 @@ function show_system_backup() { "GET", { }, function(r) { + if (r.error) { + show_modal_error("Backup Error", $("
").text(r.error));
+          return;
+      }
+
       $('#backup-status tbody').html("");
       var total_disk_size = 0;