64 lines
2.4 KiB
Bash
64 lines
2.4 KiB
Bash
#!/bin/bash
|
|
# Sets up Ghost (Docker-based) from a backup stored in B2.
|
|
# Assumes B2 at ${BUCKET_PATH} contains:
|
|
# db.sql — mysqldump of the ghost database
|
|
# content/ — Ghost content directory
|
|
#
|
|
# Run ghost_server-migrate first to populate B2, then run this.
|
|
|
|
set -euo pipefail
|
|
|
|
# shellcheck source=ghost_server-env
|
|
. "${HOME}"/"${USER}"-env
|
|
|
|
echo -e "\n[+] setting up ghost\n\n-------\n"
|
|
|
|
TMP_DIR="/tmp/${USER}-restore"
|
|
|
|
mkdir -p "${VOLUME_PATH}"/{content,mysql}
|
|
mkdir -p "${TMP_DIR}"
|
|
|
|
envsubst <"${HOME}"/"${USER}"-compose_template.yaml >"${HOME}"/"${USER}"-compose.yaml
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 1. Start MySQL; Ghost stays down until data is restored
|
|
# ---------------------------------------------------------------------------
|
|
echo "[+] starting MySQL..."
|
|
sudo docker compose -f "${HOME}"/"${USER}"-compose.yaml up -d db
|
|
|
|
echo "[+] waiting for MySQL to be healthy..."
|
|
until sudo docker exec ghost-mysql mysqladmin ping -h localhost -u root --password="${DB_ROOT_PASSWORD}" --silent 2>/dev/null; do
|
|
sleep 3
|
|
done
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 2. Restore database from B2
|
|
# ---------------------------------------------------------------------------
|
|
echo "[+] downloading database dump from B2..."
|
|
rclone copyto "${BUCKET_PATH}/db.sql" "${TMP_DIR}/db.sql"
|
|
|
|
echo "[+] restoring database..."
|
|
cat "${TMP_DIR}/db.sql" | sudo docker exec -i ghost-mysql mysql -u root --password="${DB_ROOT_PASSWORD}" ghost
|
|
|
|
echo "[+] database restored"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 3. Restore content directory from B2
|
|
# ---------------------------------------------------------------------------
|
|
echo "[+] downloading content from B2..."
|
|
rclone copy "${BUCKET_PATH}/content/" "${VOLUME_PATH}/content/"
|
|
|
|
echo "[+] content restored"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 4. Start Ghost — it will run schema migrations (V5 -> V6) automatically
|
|
# ---------------------------------------------------------------------------
|
|
echo "[+] starting Ghost..."
|
|
sudo docker compose -f "${HOME}"/"${USER}"-compose.yaml up -d ghost
|
|
|
|
rm -rf "${TMP_DIR}"
|
|
|
|
echo -e "\n-----\nINFO\n-----"
|
|
echo "[i] Ghost is starting and running database migrations. This may take a minute."
|
|
echo "[i] Check logs: sudo docker compose -f ~/ghost_server-compose.yaml logs -f ghost"
|