Skip to content
Snippets Groups Projects
Commit 5ea501d2 authored by Florent Thiery's avatar Florent Thiery
Browse files

rewrite local backup check, refs #21677

parent 3a70e20e
No related branches found
No related tags found
No related merge requests found
...@@ -67,40 +67,37 @@ def test_backup_space(server): ...@@ -67,40 +67,37 @@ def test_backup_space(server):
return False return False
def check_local_backup(path, descend=True): def check_local_backup(path):
all_ok = True all_ok = True
for d in os.listdir(path): backup_folder = os.path.dirname(path)
subd = os.path.join(path, d) latest = os.path.join(backup_folder, 'latest')
if os.path.isdir(subd): if os.path.exists(latest):
latest = os.path.join(subd, 'latest') mtime = os.path.getmtime(latest)
print('Checking %s' % latest) d = datetime.fromtimestamp(mtime)
if os.path.exists(latest): now = datetime.now()
mtime = os.path.getmtime(latest) diff_seconds = (now - d).total_seconds()
d = datetime.fromtimestamp(mtime) if diff_seconds > 25*3600:
now = datetime.now() print('Backup %s is older than a day' % backup_folder)
diff_seconds = (now - d).total_seconds() all_ok = False
if diff_seconds > 25*3600:
print('Backup %s is older than a day' % subd)
all_ok = False
else:
print('Backup %s is fine' % subd)
else: else:
if descend: print('Backup %s is fine' % backup_folder)
for dd in os.listdir(subd): elif os.path.exists(os.path.join(backup_folder, 'backup.inprogress')):
subsubd = os.path.join(subd, dd) print('Backup %s still running' % backup_folder)
if os.path.isdir(subsubd): all_ok = False
all_ok = min(all_ok, check_local_backup(subsubd, descend=False)) else:
print('Backup %s is not working' % latest)
all_ok = False
return all_ok return all_ok
def check_local_backups(paths): def check_local_backups(paths):
all_ok = True all_ok = True
blacklist = ('lost+found')
folders = paths.split(',') folders = paths.split(',')
for f in folders: for f in folders:
if f not in blacklist: cmd = "find %s -maxdepth 4 -name backup.marker" % f
print('Checking top folder %s' % f) status, out = subprocess.getstatusoutput(cmd)
all_ok = min(check_local_backup(f), all_ok) for bf in out.split('\n'):
all_ok = min(check_local_backup(bf), all_ok)
return all_ok return all_ok
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment