Write down the cutover for asxpio-services step by step, with the times measured in the rehearsal: backup 6 minutes, restore of 29 GB 3 minutes. The backup script now tolerates files changing under tar in live mode, which a running Minecraft world always does; in final mode, with the servers stopped, that remains an error. The restore script can leave the containers stopped for a restore test. Also checked on the test server before it was deleted: the production network layout (interfaces matched by MAC, static IPv6, the private network on enp7s0) comes up after a reboot with the same routes the Debian host has. Assisted-by: Claude:fable-5-2
47 lines
1.6 KiB
Bash
Executable file
47 lines
1.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Runs on the freshly installed NixOS host. Restores service data from the
|
|
# archives written by backup-services.sh, verifies each against SHA256SUMS,
|
|
# then lets the containers start.
|
|
#
|
|
# RCLONE_CONFIG=/run/rclone.conf restore-services.sh <remote:path> [name...]
|
|
#
|
|
# Without names it restores everything the host needs. The rclone config
|
|
# with the object-storage keys is supplied by the operator for the run and
|
|
# removed afterwards; it is not part of the system.
|
|
set -euo pipefail
|
|
|
|
src=${1:?usage: restore-services.sh <remote:path> [name...]}
|
|
shift
|
|
names=("$@")
|
|
[ ${#names[@]} -gt 0 ] || names=(minecraft minecraft-fossils sillytavern forgejo-runner)
|
|
|
|
rc() { rclone --s3-region hel1 --s3-no-check-bucket "$@"; }
|
|
|
|
sums=$(mktemp)
|
|
rc cat "$src/SHA256SUMS" >"$sums"
|
|
|
|
for name in "${names[@]}"; do
|
|
want=$(awk -v f="$name.tar.zst" '$2 == f {print $1}' "$sums")
|
|
[ -n "$want" ] || { echo "no checksum for $name" >&2; exit 1; }
|
|
echo "== restoring $name"
|
|
got=$(rc cat "$src/$name.tar.zst" \
|
|
| tee >(zstd -d | tar --numeric-owner --acls --xattrs -xpf - -C /) \
|
|
| sha256sum | cut -d' ' -f1)
|
|
wait
|
|
[ "$got" = "$want" ] || { echo "checksum mismatch for $name" >&2; exit 1; }
|
|
echo "ok $name"
|
|
done
|
|
rm -f "$sums"
|
|
|
|
# RESTORE_NO_START=1 leaves everything stopped (restore tests)
|
|
if [ -n "${RESTORE_NO_START:-}" ]; then
|
|
echo "== data restored; containers left stopped"
|
|
exit 0
|
|
fi
|
|
|
|
touch /opt/.restored
|
|
echo "== data restored; starting containers"
|
|
systemctl start --no-block \
|
|
podman-minecraft.service podman-minecraft-fossils.service \
|
|
podman-minecraft-fossils-wlsync.service podman-sillytavern.service \
|
|
podman-forgejo-runner.service
|