check Backup
This commit is contained in:
+7
-3
@@ -567,9 +567,13 @@ def backup_move(request: MoveRequest):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/backup/check", dependencies=[Depends(verify_api_key)])
|
class BackupCheckRequest(BaseModel):
|
||||||
def backup_check():
|
uuid: str
|
||||||
return {"message": run_command([f"{BIN_PATH}/checkBackup"])}
|
|
||||||
|
|
||||||
|
@app.post("/backup/check", dependencies=[Depends(verify_api_key)])
|
||||||
|
def backup_check(request: BackupCheckRequest):
|
||||||
|
return {"message": run_command([f"{BIN_PATH}/checkBackup", request.uuid])}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/backup/borgpush", dependencies=[Depends(verify_api_key)])
|
@app.get("/backup/borgpush", dependencies=[Depends(verify_api_key)])
|
||||||
|
|||||||
+17
-28
@@ -1,49 +1,38 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from datetime import date, timedelta
|
|
||||||
|
|
||||||
BACKUP_ROOT = Path("/BACKUP")
|
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()):
|
uuid = sys.argv[1]
|
||||||
if not directory.is_dir():
|
directory = BACKUP_ROOT / uuid
|
||||||
continue
|
|
||||||
|
|
||||||
if directory.name == "default":
|
if not directory.is_dir():
|
||||||
continue
|
print(f"ERROR: directory not found for UUID {uuid}")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
latest_file = None
|
latest_date = None
|
||||||
latest_date = "00000000"
|
|
||||||
|
|
||||||
for zip_file in directory.rglob("*.zip"):
|
for zip_file in directory.rglob("*.zip"):
|
||||||
name = zip_file.name
|
name = zip_file.name
|
||||||
|
|
||||||
# expected format: YYYYMMDD_HHMM.zip
|
|
||||||
try:
|
try:
|
||||||
date_part = name.split("_")[0]
|
date_part = name.split("_")[0]
|
||||||
|
|
||||||
if len(date_part) != 8 or not date_part.isdigit():
|
if len(date_part) != 8 or not date_part.isdigit():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if date_part > latest_date:
|
if latest_date is None or date_part > latest_date:
|
||||||
latest_date = date_part
|
latest_date = date_part
|
||||||
latest_file = zip_file
|
|
||||||
|
|
||||||
if latest_file is None:
|
if latest_date is None:
|
||||||
print(f"{directory.name} -> NO BACKUPS")
|
print("NO BACKUPS")
|
||||||
continue
|
sys.exit(1)
|
||||||
|
|
||||||
status = "STALE" if latest_date < cutoff else "OK"
|
# Format as yyyy-mm-dd
|
||||||
|
print(f"{latest_date[:4]}-{latest_date[4:6]}-{latest_date[6:8]}")
|
||||||
print(
|
|
||||||
f"{directory.name} -> "
|
|
||||||
f"{latest_file.name} -> "
|
|
||||||
f"{latest_date} -> "
|
|
||||||
f"{status}"
|
|
||||||
)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user