Be Your Own Cloud code · PART 4 — MAKING IT RESILIENT
Chapter 19 Restore Drills: Proving Your Backups Actually Work
Restore to a Throwaway Location First
# p. 86
# root shell: restic.env and much of /opt/stacks are root-owned
sudo -i
# the credentials file from Chapter 18
source /opt/scripts/restic.env
# List available snapshots
restic snapshots
# Restore the latest /opt/stacks snapshot to a scratch folder
restic restore latest --path /opt/stacks --target /tmp/restore-test
# Check it actually looks right
ls -la /tmp/restore-test/opt/stacks
diff -rq /tmp/restore-test/opt/stacks /opt/stacks The Drill That Actually Matters: One Real Service
# p. 86
cd /opt/stacks/privatebin
docker compose down
mv data data-original-backup
restic restore latest --path /opt/stacks --target / \
--include /opt/stacks/privatebin/data
docker compose up -d
# Confirm the service comes up and your test paste is still there Databases Get Their Own Drill
# p. 86
restic restore latest --path /opt/stacks --target /tmp/restore-test \
--include /opt/stacks/immich/db-dump.sql.gz
# A throwaway database from the same image as Immich's -- the live one
# is never touched
docker run -d --name restore-drill \
-e POSTGRES_PASSWORD=drill -e POSTGRES_DB=immich \
ghcr.io/immich-app/postgres:14-vectorchord0.4.3-pgvectors0.2.0
sleep 15 # give Postgres a moment to start
# This sed line does the same job as the one in Immich's restore
# guide: it switches Postgres's search path back on
gunzip -c /tmp/restore-test/opt/stacks/immich/db-dump.sql.gz \
| sed "s/\('search_path', \)'', false/\1'public, pg_catalog', true/" \
| docker exec -i restore-drill \
psql -U postgres -d immich -q -o /dev/null \
--single-transaction --set ON_ERROR_STOP=on
docker exec restore-drill psql -U postgres -d immich \
-c 'SELECT count(*) AS users FROM "user";' \
-c 'SELECT count(*) AS photos FROM asset;'
docker rm -f restore-drill Reproduced exactly from Be Your Own Cloud, Chapter 19. The book explains what each line does and what to do when it doesn't work. About the book
Something here not working as the book describes? Tell the author.