File size: 871 Bytes
dd39d95 debd125 15172c9 debd125 dd39d95 debd125 15172c9 4a70373 15172c9 debd125 15172c9 debd125 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #!/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
|