Spaces:
Running
Running
Upload restore.sh with huggingface_hub
Browse files- restore.sh +3 -36
restore.sh
CHANGED
|
@@ -1,39 +1,6 @@
|
|
| 1 |
#!/bin/sh
|
| 2 |
-
# Restore
|
| 3 |
-
#
|
| 4 |
-
|
| 5 |
set -eu
|
| 6 |
|
| 7 |
-
|
| 8 |
-
REPO_ID="tkgray/open-webui-backups"
|
| 9 |
-
FILE_IN_REPO="backups/webui.db"
|
| 10 |
-
|
| 11 |
-
if [ -f "$DB_PATH" ]; then
|
| 12 |
-
echo "[restore] $DB_PATH already exists — skipping restore."
|
| 13 |
-
exit 0
|
| 14 |
-
fi
|
| 15 |
-
|
| 16 |
-
if [ -z "${HF_TOKEN:-}" ]; then
|
| 17 |
-
echo "[restore] HF_TOKEN not set — skipping restore."
|
| 18 |
-
exit 0
|
| 19 |
-
fi
|
| 20 |
-
|
| 21 |
-
echo "[restore] $DB_PATH not found — attempting restore from $REPO_ID:$FILE_IN_REPO ..."
|
| 22 |
-
python3 -c "
|
| 23 |
-
from huggingface_hub import hf_hub_download
|
| 24 |
-
import os, sys
|
| 25 |
-
try:
|
| 26 |
-
path = hf_hub_download(
|
| 27 |
-
repo_id='$REPO_ID',
|
| 28 |
-
filename='$FILE_IN_REPO',
|
| 29 |
-
repo_type='dataset',
|
| 30 |
-
token=os.environ['HF_TOKEN']
|
| 31 |
-
)
|
| 32 |
-
import shutil
|
| 33 |
-
os.makedirs('/data', exist_ok=True)
|
| 34 |
-
shutil.copy2(path, '$DB_PATH')
|
| 35 |
-
print('[restore] Restore OK')
|
| 36 |
-
except Exception as e:
|
| 37 |
-
print(f'[restore] Restore FAILED (first boot or no backup yet?): {e}', file=sys.stderr)
|
| 38 |
-
sys.exit(0) # don't fail boot if no backup exists yet
|
| 39 |
-
"
|
|
|
|
| 1 |
#!/bin/sh
|
| 2 |
+
# Restore Open WebUI user data from the HF backups dataset when the DB is
|
| 3 |
+
# missing (fresh volume / factory reset). No-op when the DB is already present.
|
|
|
|
| 4 |
set -eu
|
| 5 |
|
| 6 |
+
exec python3 /restore.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|