diff --git a/tests/test_backup.py b/tests/test_backup.py index cf95f6d3c91d2cf6cdd725d492b5856159d493fd..5b8a40840f21853efcdb650b19b66af0aa3142c3 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