Nexova / scripts /backup.sh
Nexova
fix: backup/restore use HF commit API, correct auth
15172c9
raw
history blame contribute delete
871 Bytes
#!/bin/sh
set -e
REPO="${HF_DATASET:-jay-hank/Nexova-storage}"
TOKEN="${HF_TOKEN}"
DB="./data/nexova.db"
INTERVAL="${BACKUP_INTERVAL:-1800}"
if [ -z "$TOKEN" ]; then
echo "[backup] HF_TOKEN not set, disabled"
exit 0
fi
echo "[backup] loop every ${INTERVAL}s -> $REPO"
while true; do
sleep "$INTERVAL"
if [ -f "$DB" ]; then
SIZE=$(wc -c < "$DB")
B64=$(base64 -w0 "$DB")
TS=$(date -u +%FT%TZ)
echo "[backup] uploading ($SIZE bytes)..."
HTTP=$(curl -s -w "%{http_code}" -o /dev/null \
-X POST "https://huggingface.co/api/datasets/$REPO/commit/main" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"summary\":\"auto-backup $TS\",\"operations\":[{\"op\":\"upload\",\"path\":\"nexova.db\",\"encoding\":\"base64\",\"content\":\"$B64\"}]}")
echo "[backup] HTTP $HTTP at $TS"
fi
done