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

optimize local backup check, fixes #33097

parent 4655573c
No related branches found
No related tags found
No related merge requests found
......@@ -137,7 +137,7 @@ def check_backup_is_incremental(path: str) -> bool:
return all_ok
def check_local_backup(path: str) -> bool:
def check_local_backup(backup_folder: str) -> bool:
"""Check that local backup is in a correct state.
:param path: Local backup folder path
......@@ -146,18 +146,17 @@ def check_local_backup(path: str) -> bool:
:rtype: bool
"""
backup_folder = os.path.dirname(path)
print("Checking {}:".format(backup_folder))
all_ok = True
latest = os.path.join(backup_folder, "latest")
if backup_folder.endswith(".disabled"):
latest = backup_folder / "latest"
if backup_folder.name.endswith(".disabled"):
# skip if disabled
lg.info("disabled")
elif os.path.exists(latest):
elif latest.exists():
# resolve symbolic link
latest = os.path.realpath(latest)
latest_date = os.path.basename(latest)
latest = latest.resolve()
latest_date = latest.name
date = datetime.strptime(latest_date, "%Y-%m-%d-%H%M%S")
now = datetime.now()
diff_seconds = (now - date).total_seconds()
......@@ -168,7 +167,7 @@ def check_local_backup(path: str) -> bool:
lg.success("less than {} days old".format(MAX_AGE))
if not check_backup_is_incremental(backup_folder):
all_ok = False
elif os.path.exists(os.path.join(backup_folder, "backup.inprogress")):
elif (backup_folder / "backup.inprogress").exists():
lg.warning("still running")
all_ok = False
else:
......@@ -190,10 +189,17 @@ def check_local_backups(paths: str) -> bool:
all_ok = True
folders = paths.split(",")
for folder in folders:
cmd = "find -L {} -maxdepth 4 -name backup.marker".format(folder)
_, out = subprocess.getstatusoutput(cmd)
for backup_folder in out.split("\n"):
backup_root = Path(folder)
subfolders = {x for x in backup_root.iterdir() if x.is_dir()}
processed = set()
for backup_marker in backup_root.glob("*/backup.marker"):
backup_folder = backup_marker.parent
print("Checking local backups in %s" % backup_folder)
all_ok = min(check_local_backup(backup_folder), all_ok)
processed.add(backup_folder)
unprocessed = [str(x) for x in subfolders - processed]
if len(unprocessed):
lg.warning("Warning, found non-mediavault folders under : %s" % unprocessed)
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