check Backup

This commit is contained in:
Oliver
2026-05-27 18:47:38 -03:00
parent ea975db6ff
commit 9af1570a29
2 changed files with 31 additions and 38 deletions
+24 -35
View File
@@ -1,49 +1,38 @@
#!/usr/bin/env python3
import sys
from pathlib import Path
from datetime import date, timedelta
BACKUP_ROOT = Path("/BACKUP")
STALE_DAYS = 2
cutoff = (date.today() - timedelta(days=STALE_DAYS)).strftime("%Y%m%d")
if len(sys.argv) < 2:
print("Usage: checkBackup <uuid>")
sys.exit(1)
for directory in sorted(BACKUP_ROOT.iterdir()):
if not directory.is_dir():
continue
uuid = sys.argv[1]
directory = BACKUP_ROOT / uuid
if directory.name == "default":
continue
if not directory.is_dir():
print(f"ERROR: directory not found for UUID {uuid}")
sys.exit(1)
latest_file = None
latest_date = "00000000"
latest_date = None
for zip_file in directory.rglob("*.zip"):
name = zip_file.name
# expected format: YYYYMMDD_HHMM.zip
try:
date_part = name.split("_")[0]
if len(date_part) != 8 or not date_part.isdigit():
continue
except Exception:
for zip_file in directory.rglob("*.zip"):
name = zip_file.name
try:
date_part = name.split("_")[0]
if len(date_part) != 8 or not date_part.isdigit():
continue
if date_part > latest_date:
latest_date = date_part
latest_file = zip_file
if latest_file is None:
print(f"{directory.name} -> NO BACKUPS")
except Exception:
continue
status = "STALE" if latest_date < cutoff else "OK"
if latest_date is None or date_part > latest_date:
latest_date = date_part
print(
f"{directory.name} -> "
f"{latest_file.name} -> "
f"{latest_date} -> "
f"{status}"
)
if latest_date is None:
print("NO BACKUPS")
sys.exit(1)
# Format as yyyy-mm-dd
print(f"{latest_date[:4]}-{latest_date[4:6]}-{latest_date[6:8]}")