45 lines
948 B
Python
Executable File
45 lines
948 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
BACKUP_ROOT = Path("/BACKUP")
|
|
|
|
if len(sys.argv) < 2:
|
|
print("Usage: checkBackup <uuid>")
|
|
sys.exit(1)
|
|
|
|
uuid = sys.argv[1]
|
|
directory = BACKUP_ROOT / uuid
|
|
|
|
if not directory.is_dir():
|
|
print(f"ERROR: directory not found for UUID {uuid}")
|
|
sys.exit(1)
|
|
|
|
latest_date = None
|
|
latest_file = None
|
|
|
|
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
|
|
except Exception:
|
|
continue
|
|
|
|
if latest_date is None or date_part > latest_date:
|
|
latest_date = date_part
|
|
latest_file = zip_file
|
|
|
|
if latest_date is None:
|
|
print("NO BACKUPS")
|
|
sys.exit(1)
|
|
|
|
if latest_file.stat().st_size < 1000:
|
|
print("01-01-2000")
|
|
sys.exit(0)
|
|
|
|
# Format as yyyy-mm-dd
|
|
print(f"{latest_date[:4]}-{latest_date[4:6]}-{latest_date[6:8]}")
|