Spaces:
Configuration error
Configuration error
perf: skip backup when no files changed using mtime fingerprint
Browse filesAvoids 20-min upload cycles by comparing file size+mtime before staging.
Only uploads when something actually changed; saves state in .backup_state.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4 unmodified lines56789101113 unmodified lines25262728293031323334353637383940414243444546474849505138 unmodified lines9091929394959697989910010110210310410510640 unmodified lines1471481491501511521531541551561574 unmodified lines python3 sync.py restore -- download DB from HF on startup python3 sync.py backup -- upload DB to HF (called in loop)"""import jsonimport osimport sysimport shutil13 unmodified linesALLOW_HIDDEN = {".hmac"}SKIP_NAMES = {"LOCK"} # held open by Dolt — always skip
def _quick_hash(data_dir): """Build a fingerprint from file sizes+mtimes — fast, no file reads.""" entries = {} for root, dirs, files in os.walk(data_dir): is_inside_dolt = ".dolt" in root.replace("\\", "/").split("/") if not is_inside_dolt: dirs[:] = [d for d in dirs if not d.startswith(".") or d == ".dolt"] for f in files: if f in SKIP_FILES or f in SKIP_NAMES: continue if f.startswith(".") and f not in ALLOW_HIDDEN: continue full = os.path.join(root, f) rel = os.path.relpath(full, data_dir).replace("\\", "/") try: s = os.stat(full) entries[rel] = (s.st_size, s.st_mtime) except OSError: pass return json.dumps(entries, sort_keys=True)
def get_api(): return HfApi(token=HF_TOKEN)
38 unmodified lines return api = get_api()
# Fast change detection — skip everything if nothing modified state_file = os.path.join(DATA_DIR, ".backup_state") current_state = _quick_hash(DATA_DIR) if os.path.exists(state_file): try: if open(state_file).read() == current_state: print("[sync] no changes — skipping backup") return except Exception: pass
# Ensure repo exists try: api.repo_info(REPO_ID, repo_type="dataset")40 unmodified lines commit_message="sync: periodic backup", ) print("[sync] backup complete") # Save state fingerprint so next cycle skips if nothing changed try: open(state_file, "w").write(current_state) except Exception: pass except Exception as e: print(f"[sync] backup error: {e}") finally:sync.py+38