From 5ea501d246b3dc312539177f843fd8a76507f267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florent=20Thi=C3=A9ry?= <florent.thiery@ubicast.eu> Date: Thu, 1 Jun 2017 11:35:31 +0200 Subject: [PATCH] rewrite local backup check, refs #21677 --- tests/test_backup.py | 47 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/tests/test_backup.py b/tests/test_backup.py index cf95f6d3..5b8a4084 100755 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -67,40 +67,37 @@ def test_backup_space(server): return False -def check_local_backup(path, descend=True): +def check_local_backup(path): all_ok = True - for d in os.listdir(path): - subd = os.path.join(path, d) - if os.path.isdir(subd): - latest = os.path.join(subd, 'latest') - print('Checking %s' % latest) - if os.path.exists(latest): - mtime = os.path.getmtime(latest) - d = datetime.fromtimestamp(mtime) - now = datetime.now() - diff_seconds = (now - d).total_seconds() - if diff_seconds > 25*3600: - print('Backup %s is older than a day' % subd) - all_ok = False - else: - print('Backup %s is fine' % subd) + backup_folder = os.path.dirname(path) + latest = os.path.join(backup_folder, 'latest') + if os.path.exists(latest): + mtime = os.path.getmtime(latest) + d = datetime.fromtimestamp(mtime) + now = datetime.now() + diff_seconds = (now - d).total_seconds() + if diff_seconds > 25*3600: + print('Backup %s is older than a day' % backup_folder) + all_ok = False else: - if descend: - for dd in os.listdir(subd): - subsubd = os.path.join(subd, dd) - if os.path.isdir(subsubd): - all_ok = min(all_ok, check_local_backup(subsubd, descend=False)) + print('Backup %s is fine' % backup_folder) + elif os.path.exists(os.path.join(backup_folder, 'backup.inprogress')): + print('Backup %s still running' % backup_folder) + all_ok = False + else: + print('Backup %s is not working' % latest) + all_ok = False return all_ok def check_local_backups(paths): all_ok = True - blacklist = ('lost+found') folders = paths.split(',') for f in folders: - if f not in blacklist: - print('Checking top folder %s' % f) - all_ok = min(check_local_backup(f), all_ok) + cmd = "find %s -maxdepth 4 -name backup.marker" % f + status, out = subprocess.getstatusoutput(cmd) + for bf in out.split('\n'): + all_ok = min(check_local_backup(bf), all_ok) return all_ok -- GitLab