ca-cube / _backup /scripts /backup_loop.py
Konuktor92's picture
backup _backup/scripts 17:44:23
a5899e5 verified
Raw History Blame Contribute Delete
1.65 kB
"""Every 10 minutes, mirror logs, code, protocol and finished run outputs to HF (TrendeX90/ca-cube/_backup/),
so nothing is lost if the Vast machine stops. Unchanged files are skipped by the hub (no empty commits).
setsid nohup python scripts/backup_loop.py > logs/backup.log 2>&1 &
"""
from __future__ import annotations
import time
import traceback
from pathlib import Path
from huggingface_hub import HfApi
ROOT = Path("/root/trendex-ca")
REPO = "TrendeX90/ca-cube"
ITEMS = [
(ROOT / "logs", "_backup/logs", ["*.log"]),
(ROOT / "scripts", "_backup/scripts", ["*.py", "*.sh"]),
(ROOT / "configs", "_backup/configs", ["*.yaml"]),
(ROOT / "runs" / "v2_ca", "_backup/runs_v2_ca", ["*.json", "*.ubj", "*.parquet", "*.npy", "products/**", "hf_model/**"]),
(ROOT / "data" / "aoi", "_backup/aoi", ["*.json", "aoi_request.geojson"]),
]
def main() -> None:
api = HfApi()
while True:
for folder, dest, patterns in ITEMS:
if not folder.exists():
continue
try:
api.upload_folder(repo_id=REPO, repo_type="dataset", folder_path=str(folder), path_in_repo=dest,
allow_patterns=patterns, ignore_patterns=["__pycache__/*", "*.pyc", "_golden_tmp/*"],
commit_message=f"backup {dest} {time.strftime('%H:%M:%S')}")
print(time.strftime("%H:%M:%S"), "synced", dest, flush=True)
except Exception:
print(time.strftime("%H:%M:%S"), "sync failed", dest, traceback.format_exc(limit=1), flush=True)
time.sleep(600)
if __name__ == "__main__":
main()