tkgray commited on
Commit
e993114
·
verified ·
1 Parent(s): b490f62

Upload restore.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. restore.sh +39 -0
restore.sh ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ # Restore /data/webui.db from the HF backups dataset repo if it doesn't exist.
3
+ # Requires HF_TOKEN env var to be set (Space secret).
4
+
5
+ set -eu
6
+
7
+ DB_PATH="/data/webui.db"
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
+ "