|
|
#!/bin/bash |
|
|
set -e |
|
|
|
|
|
echo "[Restore] Data restoration script started." |
|
|
|
|
|
|
|
|
LIVE_DATA_DIR="/app/server/storage" |
|
|
LIVE_DB_FILE="/app/server/anythingllm.db" |
|
|
STAGE_DIR="/tmp/restore_stage" |
|
|
RESTORE_SOURCE="" |
|
|
|
|
|
|
|
|
echo "[Restore] Forcing a clean slate..." |
|
|
rm -rf "${LIVE_DATA_DIR}" "${LIVE_DB_FILE}" "${STAGE_DIR}" || { |
|
|
echo "[Warning] Failed to clean some directories, continuing anyway..." |
|
|
} |
|
|
mkdir -p "${STAGE_DIR}" || { |
|
|
echo "[Error] Failed to create staging directory" |
|
|
exit 1 |
|
|
} |
|
|
|
|
|
|
|
|
if [ -n "${WEBDAV_URL}" ]; then |
|
|
echo "[Restore] Attempting to restore from WebDAV to staging area..." |
|
|
if rclone copy "webdav:anythingllm_backup/" "${STAGE_DIR}/" --max-depth 20; then |
|
|
|
|
|
if [ -f "${STAGE_DIR}/anythingllm.db" ]; then |
|
|
echo "[Restore] WebDAV restore to staging area successful." |
|
|
RESTORE_SOURCE="${STAGE_DIR}" |
|
|
else |
|
|
echo "[Restore] WebDAV backup seems incomplete. Ignoring." |
|
|
fi |
|
|
else |
|
|
echo "[Restore] WebDAV restore failed." |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ -z "${RESTORE_SOURCE}" ] && [ -n "${GITHUB_REPO}" ]; then |
|
|
echo "[Restore] Attempting to restore from GitHub to staging area..." |
|
|
if git clone https://${GITHUB_TOKEN}@github.com/${GITHUB_REPO} "${STAGE_DIR}"; then |
|
|
if [ -f "${STAGE_DIR}/anythingllm.db" ]; then |
|
|
echo "[Restore] GitHub restore to staging area successful." |
|
|
RESTORE_SOURCE="${STAGE_DIR}" |
|
|
else |
|
|
echo "[Restore] GitHub backup seems incomplete. Ignoring." |
|
|
fi |
|
|
else |
|
|
echo "[Restore] GitHub restore failed." |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ -n "${RESTORE_SOURCE}" ]; then |
|
|
echo "[Restore] Deploying data from ${RESTORE_SOURCE} to live location..." |
|
|
|
|
|
mkdir -p "${LIVE_DATA_DIR}" |
|
|
|
|
|
rsync -a "${RESTORE_SOURCE}/storage/" "${LIVE_DATA_DIR}/" |
|
|
mv "${RESTORE_SOURCE}/anythingllm.db" "${LIVE_DB_FILE}" |
|
|
echo "[Restore] Deployment successful." |
|
|
else |
|
|
echo "[Restore] No valid remote backups found to restore from. Starting fresh." |
|
|
fi |
|
|
|
|
|
|
|
|
echo "[Restore] Cleaning up staging area..." |
|
|
rm -rf "${STAGE_DIR}" |