52 lines
1.3 KiB
Bash
52 lines
1.3 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
|
|
cd "$(dirname "$0")"
|
|
|
|
archive=${1:-}
|
|
if [ -z "$archive" ] || [ ! -f "$archive" ]; then
|
|
echo "Usage: RESTORE_CONFIRM=restore $0 /path/to/qsfera-TIMESTAMP.tar.gz" >&2
|
|
exit 2
|
|
fi
|
|
|
|
if [ "${RESTORE_CONFIRM:-}" != "restore" ]; then
|
|
echo "Restore replaces the current QSfera configuration and data." >&2
|
|
echo "Re-run with RESTORE_CONFIRM=restore after checking the archive path." >&2
|
|
exit 2
|
|
fi
|
|
|
|
if [ -f "$archive.sha256" ]; then
|
|
archive_directory=$(dirname "$archive")
|
|
archive_name=$(basename "$archive")
|
|
(cd "$archive_directory" && sha256sum --check "$archive_name.sha256")
|
|
fi
|
|
|
|
compose() {
|
|
docker compose "$@"
|
|
}
|
|
|
|
restore_completed=false
|
|
|
|
finish_restore() {
|
|
if [ "$restore_completed" = "true" ]; then
|
|
compose start qsfera >/dev/null
|
|
else
|
|
echo "Restore failed; QSfera remains stopped to protect the data set." >&2
|
|
fi
|
|
}
|
|
|
|
compose config --quiet
|
|
compose stop qsfera
|
|
trap finish_restore EXIT
|
|
trap 'exit 1' HUP INT TERM
|
|
|
|
compose run --rm --no-deps -T --entrypoint /bin/sh qsfera -ec \
|
|
'find /etc/qsfera -mindepth 1 -maxdepth 1 -exec rm -rf {} +; find /var/lib/qsfera -mindepth 1 -maxdepth 1 -exec rm -rf {} +; tar -C / -xzf -' \
|
|
<"$archive"
|
|
|
|
restore_completed=true
|
|
compose start qsfera >/dev/null
|
|
trap - EXIT HUP INT TERM
|
|
|
|
echo "Restore completed. Run sh ./smoke-test.sh to verify startup and health."
|