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 lines567891013 unmodified lines24252627282938 unmodified lines68697071727340 unmodified lines1141151161171181194 unmodified linespython3 sync.py restore -- download DB from HF on startuppython3 sync.py backup -- upload DB to HF (called in loop)"""import osimport sysimport shutil13 unmodified linesALLOW_HIDDEN = {".hmac"}SKIP_NAMES = {"LOCK"} # held open by Dolt — always skipdef get_api():return HfApi(token=HF_TOKEN)38 unmodified linesreturnapi = get_api()# Ensure repo existstry:api.repo_info(REPO_ID, repo_type="dataset")40 unmodified linescommit_message="sync: periodic backup",)print("[sync] backup complete")except Exception as e:print(f"[sync] backup error: {e}")finally:4 unmodified lines56789101113 unmodified lines25262728293031323334353637383940414243444546474849505138 unmodified lines9091929394959697989910010110210310410510640 unmodified lines1471481491501511521531541551561574 unmodified linespython3 sync.py restore -- download DB from HF on startuppython3 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 skipdef _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:continueif f.startswith(".") and f not in ALLOW_HIDDEN:continuefull = 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:passreturn json.dumps(entries, sort_keys=True)def get_api():return HfApi(token=HF_TOKEN)38 unmodified linesreturnapi = get_api()# Fast change detection — skip everything if nothing modifiedstate_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")returnexcept Exception:pass# Ensure repo existstry:api.repo_info(REPO_ID, repo_type="dataset")40 unmodified linescommit_message="sync: periodic backup",)print("[sync] backup complete")# Save state fingerprint so next cycle skips if nothing changedtry:open(state_file, "w").write(current_state)except Exception:passexcept Exception as e:print(f"[sync] backup error: {e}")finally:
sync.py+38