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):
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
......
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