umer07 commited on
Commit
d741ef7
·
verified ·
1 Parent(s): 6c5aa5d

Add Fathom vLLM backup 20260417_053924

Browse files
Files changed (1) hide show
  1. restore_fathom_vm.sh +92 -98
restore_fathom_vm.sh CHANGED
@@ -1,66 +1,40 @@
1
  #!/usr/bin/env bash
2
  set -euo pipefail
3
 
4
- REPO_ID="umer07/vllm-deployement-backup"
5
- WORKDIR="${PWD}"
 
6
  DOWNLOAD_LATEST=0
7
  START_SERVICES=0
8
- HF_TOKEN="${HF_TOKEN:-}"
9
 
10
  usage() {
11
  cat <<'EOF'
12
  Usage:
13
  restore_fathom_vm.sh [--download-latest] [--start] [--workdir DIR] [--repo-id ID] [--hf-token TOKEN]
14
 
15
- What it does:
16
- 1. Finds the latest matching backup set
17
- 2. Extracts the application archive at /
18
- 3. Recreates and restores Docker volumes
19
- 4. Optionally starts /root/serve.py and docker compose
20
-
21
- Examples:
22
- HF_TOKEN=hf_xxx sudo ./restore_fathom_vm.sh --download-latest --start
23
- sudo ./restore_fathom_vm.sh --workdir /root/backups --start
24
-
25
- Expected files in workdir when not using --download-latest:
26
- vllm_deployement_backup_<timestamp>.tar.gz
27
- fathom_minio_data_<timestamp>.tar.gz
28
- fathom_neo4j_data_<timestamp>.tar.gz
29
- fathom_neo4j_logs_<timestamp>.tar.gz
30
  EOF
31
  }
32
 
33
  while [[ $# -gt 0 ]]; do
34
  case "$1" in
35
- --download-latest)
36
- DOWNLOAD_LATEST=1
37
- shift
38
- ;;
39
- --start)
40
- START_SERVICES=1
41
- shift
42
- ;;
43
- --workdir)
44
- WORKDIR="$2"
45
- shift 2
46
- ;;
47
- --repo-id)
48
- REPO_ID="$2"
49
- shift 2
50
- ;;
51
- --hf-token)
52
- HF_TOKEN="$2"
53
- shift 2
54
- ;;
55
- -h|--help)
56
- usage
57
- exit 0
58
- ;;
59
- *)
60
- echo "Unknown argument: $1" >&2
61
- usage
62
- exit 1
63
- ;;
64
  esac
65
  done
66
 
@@ -77,9 +51,10 @@ if [[ ${DOWNLOAD_LATEST} -eq 1 ]]; then
77
  echo "HF_TOKEN is required with --download-latest." >&2
78
  exit 1
79
  fi
80
-
81
- export REPO_ID HF_TOKEN WORKDIR
82
  python3 - <<'PY'
 
83
  import os
84
  import re
85
  import sys
@@ -87,95 +62,114 @@ from collections import defaultdict
87
  from huggingface_hub import HfApi, hf_hub_download
88
 
89
  repo_id = os.environ["REPO_ID"]
 
90
  token = os.environ["HF_TOKEN"]
91
  workdir = os.environ["WORKDIR"]
92
  api = HfApi(token=token)
93
- files = api.list_repo_files(repo_id=repo_id, repo_type="dataset")
94
 
95
- patterns = {
96
- "app": re.compile(r"^vllm_deployement_backup_(\d{8}_\d{6})\.tar\.gz$"),
97
- "minio": re.compile(r"^fathom_minio_data_(\d{8}_\d{6})\.tar\.gz$"),
98
- "neo4j_data": re.compile(r"^fathom_neo4j_data_(\d{8}_\d{6})\.tar\.gz$"),
99
- "neo4j_logs": re.compile(r"^fathom_neo4j_logs_(\d{8}_\d{6})\.tar\.gz$"),
 
 
 
 
 
 
 
100
  }
101
 
102
- groups = defaultdict(set)
103
  for name in files:
104
  base = name.rsplit("/", 1)[-1]
105
- for key, pattern in patterns.items():
106
- match = pattern.match(base)
107
- if match:
108
- groups[match.group(1)].add(key)
109
-
110
- complete = [ts for ts, keys in groups.items() if set(patterns) <= keys]
 
 
111
  if not complete:
112
- print("No complete backup set found in dataset.", file=sys.stderr)
113
  sys.exit(1)
114
 
115
  ts = sorted(complete)[-1]
116
- targets = [
117
- f"vllm_deployement_backup_{ts}.tar.gz",
118
- f"fathom_minio_data_{ts}.tar.gz",
119
- f"fathom_neo4j_data_{ts}.tar.gz",
120
- f"fathom_neo4j_logs_{ts}.tar.gz",
121
- ]
122
-
123
- for name in targets:
124
  path = hf_hub_download(
125
  repo_id=repo_id,
126
- repo_type="dataset",
127
  filename=name,
128
  token=token,
129
  local_dir=workdir,
130
  )
131
- print(path)
132
  PY
133
  fi
134
 
135
  latest_file() {
136
  local pattern="$1"
137
- ls -1 ${pattern} 2>/dev/null | sort | tail -n 1
138
  }
139
 
140
  APP_ARCHIVE="$(latest_file 'vllm_deployement_backup_*.tar.gz')"
141
  MINIO_ARCHIVE="$(latest_file 'fathom_minio_data_*.tar.gz')"
142
  NEO4J_DATA_ARCHIVE="$(latest_file 'fathom_neo4j_data_*.tar.gz')"
143
  NEO4J_LOGS_ARCHIVE="$(latest_file 'fathom_neo4j_logs_*.tar.gz')"
 
 
144
 
145
- for required in "${APP_ARCHIVE}" "${MINIO_ARCHIVE}" "${NEO4J_DATA_ARCHIVE}" "${NEO4J_LOGS_ARCHIVE}"; do
146
- if [[ -z "${required}" || ! -f "${required}" ]]; then
147
  echo "Missing required backup file in ${WORKDIR}." >&2
148
  exit 1
149
  fi
150
  done
151
 
152
- echo "Using backup set:"
153
- printf ' %s\n' "${APP_ARCHIVE}" "${MINIO_ARCHIVE}" "${NEO4J_DATA_ARCHIVE}" "${NEO4J_LOGS_ARCHIVE}"
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
- echo "Extracting application archive at /"
156
  tar -xzf "${APP_ARCHIVE}" -C /
 
 
157
 
158
- echo "Recreating Docker volumes"
159
- docker volume create fathom_minio_data >/dev/null
160
- docker volume create fathom_neo4j_data >/dev/null
161
- docker volume create fathom_neo4j_logs >/dev/null
162
-
163
- echo "Restoring MinIO volume"
164
- docker run --rm -v fathom_minio_data:/restore -v "${WORKDIR}:/backup" alpine \
165
- sh -c "cd /restore && rm -rf ./* ./.??* 2>/dev/null || true && tar -xzf /backup/$(basename "${MINIO_ARCHIVE}")"
166
-
167
- echo "Restoring Neo4j data volume"
168
- docker run --rm -v fathom_neo4j_data:/restore -v "${WORKDIR}:/backup" alpine \
169
- sh -c "cd /restore && rm -rf ./* ./.??* 2>/dev/null || true && tar -xzf /backup/$(basename "${NEO4J_DATA_ARCHIVE}")"
170
-
171
- echo "Restoring Neo4j logs volume"
172
- docker run --rm -v fathom_neo4j_logs:/restore -v "${WORKDIR}:/backup" alpine \
173
- sh -c "cd /restore && rm -rf ./* ./.??* 2>/dev/null || true && tar -xzf /backup/$(basename "${NEO4J_LOGS_ARCHIVE}")"
174
 
175
  if [[ ${START_SERVICES} -eq 1 ]]; then
176
- echo "Starting host-side model server"
177
- nohup python3 /root/serve.py > /root/serve.log 2>&1 &
178
- sleep 10
 
 
 
 
 
 
179
 
180
  echo "Starting Docker stack"
181
  cd /opt/fathom
 
1
  #!/usr/bin/env bash
2
  set -euo pipefail
3
 
4
+ REPO_ID="${REPO_ID:-umer07/vllm-deployement-backup}"
5
+ REPO_TYPE="${REPO_TYPE:-dataset}"
6
+ WORKDIR="${WORKDIR:-/root/fathom-restore}"
7
  DOWNLOAD_LATEST=0
8
  START_SERVICES=0
9
+ HF_TOKEN="${HF_TOKEN:-${HUGGING_FACE_HUB_TOKEN:-}}"
10
 
11
  usage() {
12
  cat <<'EOF'
13
  Usage:
14
  restore_fathom_vm.sh [--download-latest] [--start] [--workdir DIR] [--repo-id ID] [--hf-token TOKEN]
15
 
16
+ Restores the latest Fathom vLLM VM backup from Hugging Face.
17
+
18
+ Expected current runtime:
19
+ - vLLM via systemd: fathom-vllm.service
20
+ - vLLM OpenAI-compatible API: http://127.0.0.1:8000/v1
21
+ - Backend: http://127.0.0.1:7860
22
+ - Dashboard: http://127.0.0.1:3000
23
+
24
+ The target VM should be a ROCm/vLLM-capable image. The DigitalOcean vLLM ROCm
25
+ marketplace image provides the expected container named "rocm".
 
 
 
 
 
26
  EOF
27
  }
28
 
29
  while [[ $# -gt 0 ]]; do
30
  case "$1" in
31
+ --download-latest) DOWNLOAD_LATEST=1; shift ;;
32
+ --start) START_SERVICES=1; shift ;;
33
+ --workdir) WORKDIR="$2"; shift 2 ;;
34
+ --repo-id) REPO_ID="$2"; shift 2 ;;
35
+ --hf-token) HF_TOKEN="$2"; shift 2 ;;
36
+ -h|--help) usage; exit 0 ;;
37
+ *) echo "Unknown argument: $1" >&2; usage; exit 1 ;;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  esac
39
  done
40
 
 
51
  echo "HF_TOKEN is required with --download-latest." >&2
52
  exit 1
53
  fi
54
+ python3 -m pip install --break-system-packages -q -U huggingface_hub >/dev/null 2>&1 || true
55
+ export REPO_ID REPO_TYPE HF_TOKEN WORKDIR
56
  python3 - <<'PY'
57
+ import json
58
  import os
59
  import re
60
  import sys
 
62
  from huggingface_hub import HfApi, hf_hub_download
63
 
64
  repo_id = os.environ["REPO_ID"]
65
+ repo_type = os.environ["REPO_TYPE"]
66
  token = os.environ["HF_TOKEN"]
67
  workdir = os.environ["WORKDIR"]
68
  api = HfApi(token=token)
69
+ files = api.list_repo_files(repo_id=repo_id, repo_type=repo_type)
70
 
71
+ required = {
72
+ "app": r"^vllm_deployement_backup_(\d{8}_\d{6})\.tar\.gz$",
73
+ "minio": r"^fathom_minio_data_(\d{8}_\d{6})\.tar\.gz$",
74
+ "neo4j_data": r"^fathom_neo4j_data_(\d{8}_\d{6})\.tar\.gz$",
75
+ "neo4j_logs": r"^fathom_neo4j_logs_(\d{8}_\d{6})\.tar\.gz$",
76
+ }
77
+ optional = {
78
+ "hf_cache": r"^fathom_hf_cache_(\d{8}_\d{6})\.tar\.gz$",
79
+ "adapters": r"^fathom_adapters_(\d{8}_\d{6})\.tar\.gz$",
80
+ "guide": r"^VM_RECOVERY_GUIDE_(\d{8}_\d{6})\.md$",
81
+ "manifest": r"^vllm_deployement_backup_manifest_(\d{8}_\d{6})\.txt$",
82
+ "restore": r"^restore_fathom_vm\.sh$",
83
  }
84
 
85
+ groups = defaultdict(dict)
86
  for name in files:
87
  base = name.rsplit("/", 1)[-1]
88
+ if "/" in name and not name.startswith("backups/"):
89
+ continue
90
+ for key, pattern in {**required, **optional}.items():
91
+ m = re.match(pattern, base)
92
+ if m:
93
+ groups[m.group(1) if key != "restore" else "restore"][key] = name
94
+
95
+ complete = [ts for ts, found in groups.items() if ts != "restore" and set(required) <= set(found)]
96
  if not complete:
97
+ print("No complete backup set found.", file=sys.stderr)
98
  sys.exit(1)
99
 
100
  ts = sorted(complete)[-1]
101
+ targets = dict(groups[ts])
102
+ if "restore" in groups:
103
+ targets.update(groups["restore"])
104
+
105
+ print(f"Downloading backup timestamp {ts}")
106
+ for key, name in sorted(targets.items()):
 
 
107
  path = hf_hub_download(
108
  repo_id=repo_id,
109
+ repo_type=repo_type,
110
  filename=name,
111
  token=token,
112
  local_dir=workdir,
113
  )
114
+ print(f"{key}: {path}")
115
  PY
116
  fi
117
 
118
  latest_file() {
119
  local pattern="$1"
120
+ find "${WORKDIR}" -maxdepth 3 -type f -name "${pattern}" -printf '%f\t%p\n' 2>/dev/null | sort | tail -n 1 | cut -f2-
121
  }
122
 
123
  APP_ARCHIVE="$(latest_file 'vllm_deployement_backup_*.tar.gz')"
124
  MINIO_ARCHIVE="$(latest_file 'fathom_minio_data_*.tar.gz')"
125
  NEO4J_DATA_ARCHIVE="$(latest_file 'fathom_neo4j_data_*.tar.gz')"
126
  NEO4J_LOGS_ARCHIVE="$(latest_file 'fathom_neo4j_logs_*.tar.gz')"
127
+ HF_CACHE_ARCHIVE="$(latest_file 'fathom_hf_cache_*.tar.gz' || true)"
128
+ ADAPTERS_ARCHIVE="$(latest_file 'fathom_adapters_*.tar.gz' || true)"
129
 
130
+ for required_file in "${APP_ARCHIVE}" "${MINIO_ARCHIVE}" "${NEO4J_DATA_ARCHIVE}" "${NEO4J_LOGS_ARCHIVE}"; do
131
+ if [[ -z "${required_file}" || ! -f "${required_file}" ]]; then
132
  echo "Missing required backup file in ${WORKDIR}." >&2
133
  exit 1
134
  fi
135
  done
136
 
137
+ restore_volume() {
138
+ local volume="$1"
139
+ local archive="$2"
140
+ if [[ -z "${archive}" || ! -f "${archive}" ]]; then
141
+ echo "Skipping optional volume ${volume}; archive not present."
142
+ return
143
+ fi
144
+ echo "Restoring Docker volume ${volume}"
145
+ docker volume create "${volume}" >/dev/null
146
+ docker run --rm \
147
+ -v "${volume}:/restore" \
148
+ -v "$(dirname "${archive}"):/backup" \
149
+ alpine sh -c "cd /restore && rm -rf ./* ./.??* 2>/dev/null || true && tar -xzf /backup/$(basename "${archive}")"
150
+ }
151
 
152
+ echo "Extracting application/vLLM archive at /"
153
  tar -xzf "${APP_ARCHIVE}" -C /
154
+ chmod +x /usr/local/bin/fathom-vllm-start /usr/local/bin/fathom-vllm-stop 2>/dev/null || true
155
+ systemctl daemon-reload || true
156
 
157
+ restore_volume fathom_minio_data "${MINIO_ARCHIVE}"
158
+ restore_volume fathom_neo4j_data "${NEO4J_DATA_ARCHIVE}"
159
+ restore_volume fathom_neo4j_logs "${NEO4J_LOGS_ARCHIVE}"
160
+ restore_volume fathom_hf_cache "${HF_CACHE_ARCHIVE}"
161
+ restore_volume fathom_fathom_adapters "${ADAPTERS_ARCHIVE}"
 
 
 
 
 
 
 
 
 
 
 
162
 
163
  if [[ ${START_SERVICES} -eq 1 ]]; then
164
+ echo "Starting vLLM service"
165
+ systemctl enable fathom-vllm.service >/dev/null 2>&1 || true
166
+ systemctl restart fathom-vllm.service || true
167
+ for i in $(seq 1 40); do
168
+ if curl -fsS http://127.0.0.1:8000/v1/models >/dev/null 2>&1; then
169
+ break
170
+ fi
171
+ sleep 15
172
+ done
173
 
174
  echo "Starting Docker stack"
175
  cd /opt/fathom