Cold restore and disaster recovery
Backups and restore drills is about proving a backup works while the forge is still running. This page is the other half: the machine is gone, the nightly backup is all that is left, and you have to bring the forge back.
It is written for anyone who runs Forgejo on PostgreSQL with nightly forgejo dump archives in an encrypted off-site repository. The commands are the
ones that worked, and the notes explain the traps that cost time.
This is an operator procedure, not a button. Fjord restores managed forges for Team and Pro customers on request; see Backups and restore for what is covered. Nothing here lets a customer restore their own forge.
What this page covers
The core path: stop writers, restore into clean destinations, start, verify, and only then send customers back. It does not yet give a hardened retry procedure, a full fence against outbound effects such as webhooks and mirrors, or a scripted cutover. Cold restore: retries, fences and cutover adds them, and Known gaps says what is still untested. If the restore must survive failures or the backup holds mirrors, webhooks or mail, read that page before step 3.
Pick the right recovery path first
There are two unrelated mechanisms, and mixing them up wastes the outage.
| You want | Use | What it restores |
|---|---|---|
| Resume a forge you suspended | A whole-machine image snapshot taken at suspend | The machine as it was, including its disks. |
| Rebuild a forge whose machine is gone | This runbook, from the nightly dump | Repositories, database and configuration, onto a new machine. |
An image snapshot exists only for a forge that went through suspend. The nightly dump is the backup product, and it is the one this page restores.
Decision points before you touch anything
Stop at each of these and answer it. Each one changes what you can promise.
- Is the machine really gone? A forge that is slow, unreachable or unhealthy is not a cold restore. Check the cloud console and the machine’s own state first. Restoring over a live forge, or rebuilding while the original may come back, is how you end up with two forges and one hostname.
- Is there a backup, and how old is it? Read the last-success evidence the backup job reported. A populated value proves a dump shipped, and on an older job it may mean only that, not that it shipped last night’s data. Read the date out of the dump’s own filename when you can. Remember what the dump is: if it was taken from a forge that was taking writes, it is at best crash-consistent (see Dump a quiet forge), so tell the customer that changes from the last stretch before the dump may be missing.
- Are you inside the retention horizon? Backups are not kept forever. When service lapses, nightly ageing stops with the machine, and the backups are then deleted on a schedule. Past that horizon there is nothing to restore, and you should not promise otherwise.
- Can you reach the backup credentials for a forge that no longer exists? Credentials that are derived from a key you hold survive the machine. Credentials that were handed to the box and stored there do not. Many self-service “reveal credentials” paths also refuse a forge that is not in a healthy state, which is exactly the one you are rebuilding. Find the route before the outage, not during it.
- Where is the backup relative to where you are restoring? If one backup target serves every region, a forge in a distant region restores by pulling across regions. Expect the pull, not the load, to dominate for a large forge. There is no automatic region failover in this procedure: restoring into another region is this same runbook onto a machine you provision there.
- Who is the incident owner, and what is the severity? Name an owner, record the start time and what the customer sees, and preserve evidence (forge id, machine id, deployment ids) before you delete or recreate anything. A managed forge that is down for a paying customer is a high-severity incident. A data exposure or a credential leak is the top one, and it comes first.
Never print a derived secret into a ticket, a shared terminal or a transcript. Write secrets to a file that only you can read, and refer to their lengths.
Step 1: confirm the backup exists
Query your own records for the forge: its id, plan, the version of the secret scheme it was created under, whether it is marked deleted, and the last-success time. Do this before you commit to a time. A soft-deleted record still has what you need.
Step 2: re-derive the credentials and prove the key
Rebuild the repository address, the repository password and the storage login from the stored identifiers and the key you hold. Use the same code that provisioned the forge to derive them. A second implementation of the derivation will eventually disagree with the first, and you will find out during an outage.
Write them into an environment file readable only by you, and delete it when the procedure ends (step 9). Then prove the key before you build anything:
. ./backup.env
export RESTIC_REPOSITORY RESTIC_PASSWORD
restic snapshots- If it lists snapshots, the key is right and the rest is mechanical.
- If it fails to authenticate, re-check which version of the secret scheme the forge was created under.
- If it authenticates but cannot decrypt, stop and escalate. The derivation inputs are wrong, and guessing will not help.
Step 3: provision the replacement and stop Forgejo
Provision a machine of the same plan and the same shape through your normal path,
so the compose file and environment are written for you. Let it boot once so that it
writes its own app.ini. You want a machine that is up and healthy, but whose
content you are about to discard.
Also switch off the replacement machine’s own nightly backup job until the restore is verified. Record which scheduler entry you disable so you can re-enable it in step 8. A fresh, empty forge that backs up into the same repository before you restore would create a newer snapshot of nothing, and a restore that picks “the latest” would then restore that.
Steps 3 to 7 share variables, so write them as one script and run it with bash.
A failed check ends the script with exit, and in an interactive shell that would
close your session. These commands need Docker Compose v2, jq, curl, restic,
and PostgreSQL 13 or newer in the database container. Refer to the compose project
and its services explicitly instead of relying on the current directory. Use paths
without spaces, and load the credentials file by sourcing it, not with --env-file,
which replaces the environment the compose file already has.
set -euo pipefail
umask 077
export COMPOSE="docker compose --project-directory /path/to/compose -f /path/to/compose/docker-compose.yml"
# Service names and the application's database identity, from your compose file and
# app.ini. The managed shape uses db, forgejo, and a role and database named forgejo.
SVC_DB=db; SVC_FORGEJO=forgejo; APP_ROLE=forgejo; APP_DB=forgejo
for name in "$SVC_DB" "$SVC_FORGEJO"; do
$COMPOSE config --services | grep -qx -- "$name" || { echo "no compose service $name"; exit 1; }
done
for ident in "$APP_ROLE" "$APP_DB"; do
[[ "$ident" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || { echo "unsafe database identifier: $ident"; exit 1; }
done
# Where the files go on this machine, from the compose volumes.
REPOS_DIR=/path/to/forgejo/git/repositories
DATA_DIR=/path/to/forgejo/data
# A private directory for the one thing you cannot get back: the replacement's own
# database settings. It sits outside both destinations, and you delete it in step 9.
KEEP=/var/lib/cold-restore/FORGE_ID # replace FORGE_ID
for d in "$REPOS_DIR" "$DATA_DIR" "$KEEP"; do
[[ "$d" =~ ^/[^/]+/[^/]+/[^/]+ ]] || { echo "refusing an unsafe path: $d"; exit 1; }
[ "$(realpath -m -- "$d")" = "$d" ] || { echo "path must be canonical, with no symlinks: $d"; exit 1; }
done
[[ "$KEEP/" != "$REPOS_DIR/"* && "$KEEP/" != "$DATA_DIR/"* && "$REPOS_DIR/" != "$KEEP/"* && "$DATA_DIR/" != "$KEEP/"* ]] \
|| { echo "KEEP must be separate from the destinations"; exit 1; }
install -d -m 0700 "$KEEP"
$COMPOSE stop "$SVC_FORGEJO"
# Save the replacement's [database] section once and never overwrite it. On a re-run
# the file in the data directory may already be a restored one.
if [ ! -s "$KEEP/database-section.ini" ]; then
awk '/^\[database\]/{f=1;print;next} /^\[/{f=0} f' "$DATA_DIR/conf/app.ini" > "$KEEP/database-section.tmp"
[ -s "$KEEP/database-section.tmp" ] || { echo "no [database] section to save: let the replacement boot once first"; exit 1; }
mv "$KEEP/database-section.tmp" "$KEEP/database-section.ini"
fi
STAGE=$(mktemp -d /var/tmp/cold-restore.XXXXXX) # mode 0700 under the umask above
trap 'rm -rf "$STAGE"' EXIT # staging only; never $KEEPStop Forgejo before you touch the database. Leaving it running lets it re-sync the schema underneath your load.
The restore decrypts private repositories, instance secrets and SQL containing
account data, so the staging directory is private and is removed however the script
ends. $KEEP holds the replacement’s database credentials, so it is private too,
but it is kept, because the replacement’s [database] section is the only copy of
the credentials the replacement database accepts.
Step 4: pull the snapshot and choose the dump
List the snapshots and choose one by id. Do not restore “the latest” by name: a repository can hold snapshots from more than one machine, and from tests or earlier restores, and the newest is not necessarily the forge you are rebuilding. Check the host and the time of the one you pick against the forge’s records.
restic snapshots
SNAP=REPLACE_WITH_SNAPSHOT_ID
[[ "$SNAP" =~ ^[0-9a-f]{8,64}$ ]] || { echo "set SNAP to the snapshot id you chose"; exit 1; }
restic restore "$SNAP" --target "$STAGE/restore"The restore recreates the original directory layout under the target, so find the dump instead of guessing its path, and stop if the answer is not exactly one file:
mapfile -t FOUND < <(find "$STAGE/restore" -name 'forgejo-dump-*.zip')
[ "${#FOUND[@]}" -eq 1 ] || { echo "expected one dump, found ${#FOUND[@]}: choose by filename date"; exit 1; }
DUMP="${FOUND[0]}"
[ -s "$DUMP" ] || { echo "empty dump, do not proceed"; exit 1; }
mkdir -p "$STAGE/unpacked" && unzip -q -o "$DUMP" -d "$STAGE/unpacked"A snapshot of a whole dump directory can hold several archives from different nights, and the check above will stop you. Read the date out of each filename and unpack the one you want, rather than assuming the newest is the night you wanted. A snapshot of one validated file holds exactly one.
A forgejo dump archive unpacks to a few parts, and each has its own destination:
| Entry | Goes to |
|---|---|
forgejo-db.sql | the PostgreSQL database |
repos/ | the repositories directory |
data/ | Forgejo’s data directory |
app.ini | Forgejo’s configuration |
Step 5: restore the database
Run the database commands inside the database container, through the compose project, so the service name and the credentials mean the same thing they mean to Forgejo. Use a role that is allowed to do the load: the one setting below needs a superuser session. Keep that separate from the application role, which stays the database owner with its normal privileges.
# The administrator is the database's bootstrap role: POSTGRES_USER as the container
# first started. The official image uses "postgres" when it is unset, so default to
# that inside the container, where the variable actually lives, and validate it.
DB_ADMIN=$($COMPOSE exec -T "$SVC_DB" sh -c 'printf %s "${POSTGRES_USER:-postgres}"')
[[ "$DB_ADMIN" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] \
|| { echo "could not determine a valid database administrator role: '$DB_ADMIN'"; exit 1; }
$COMPOSE exec -T "$SVC_DB" psql -U "$DB_ADMIN" -d postgres -At \
-c "SELECT rolsuper FROM pg_roles WHERE rolname = current_user" | grep -qx t \
|| { echo "$DB_ADMIN is not a superuser: fix the role before loading"; exit 1; }
PSQL_ADMIN="$COMPOSE exec -T $SVC_DB psql -U $DB_ADMIN -q"
PSQL_APP="$COMPOSE exec -T $SVC_DB psql -U $APP_ROLE -d $APP_DB -q"Two traps here, and both are silent if you rush.
The dump is not self-cleaning. It is written with CREATE TABLE IF NOT EXISTS and has no DROP TABLE. Loaded over a schema that already exists, table
creation is skipped, index creation errors, and the inserts can land on top of
existing rows. Start from an empty database. This is also the clean starting point
for every retry: after any failed load, drop and recreate before you try again,
because earlier statements may have committed.
$PSQL_ADMIN -d postgres -v ON_ERROR_STOP=1 \
-c "DROP DATABASE IF EXISTS $APP_DB WITH (FORCE);" \
-c "CREATE DATABASE $APP_DB OWNER $APP_ROLE;"The statements are emitted in an order that violates their own foreign keys. Some CREATE TABLE statements reference tables the file creates later, so a plain
load with ON_ERROR_STOP=1 aborts within the first few lines. Do not respond by
dropping ON_ERROR_STOP: that leaves tables missing and rows half-loaded.
The file is one statement per line, so split it by kind and load it in a
dependency-safe order. CREATE TABLE IF NOT EXISTS is idempotent, so replaying
it is safe and resolves the ordering. Each later phase runs as a single transaction,
so it either lands completely or not at all:
F="$STAGE/unpacked/forgejo-db.sql"; O="$STAGE/split"; mkdir -p "$O"
grep -E '^CREATE TABLE' "$F" > "$O/10-tables.sql"
grep -E '^CREATE (UNIQUE )?INDEX' "$F" > "$O/20-indexes.sql"
grep -E '^INSERT INTO' "$F" > "$O/30-data.sql"
grep -E '^SELECT setval' "$F" > "$O/40-sequences.sql"
{ echo 'SET session_replication_role = replica;'; cat "$O/30-data.sql"; } > "$O/31-data-wrapped.sql"
# Replay the tables until the forward references resolve. Two passes is normal.
# Without ON_ERROR_STOP, psql exits 0 on SQL errors and non-zero when it cannot
# connect, and so does a compose failure. Treat any non-zero exit as an
# infrastructure failure, not as a dependency error. Only a pass that exits 0 with
# no errors counts as converged.
converged=0
for pass in 1 2 3 4 5; do
rc=0
$PSQL_APP < "$O/10-tables.sql" >/dev/null 2>"$STAGE/err" || rc=$?
[ "$rc" -eq 0 ] || { echo "table load could not run (exit $rc):"; cat "$STAGE/err"; exit 1; }
n=$(grep -c -E 'ERROR:|FATAL:' "$STAGE/err" || true); echo "tables pass $pass: $n errors"
[ "$n" -eq 0 ] && { converged=1; break; }
done
[ "$converged" -eq 1 ] || { echo "tables never converged: drop the database and start again"; exit 1; }
$PSQL_ADMIN -d "$APP_DB" --single-transaction -v ON_ERROR_STOP=1 < "$O/20-indexes.sql"
$PSQL_ADMIN -d "$APP_DB" --single-transaction -v ON_ERROR_STOP=1 < "$O/31-data-wrapped.sql"
$PSQL_ADMIN -d "$APP_DB" --single-transaction -v ON_ERROR_STOP=1 < "$O/40-sequences.sql"If any step stops, the script stops. Do not carry on to the next phase, and do not retry the failed phase on top of what is there: drop the database, recreate it, and begin again from the tables.
Why each part matters:
session_replication_role = replicaturns off foreign-key triggers for the load, because the inserts are grouped per table and not in dependency order. It lasts for the session, and only a superuser session may set it, which is why the data load uses the admin role.- Sequences run last. Their
setvalcalls read the maximum id, so running them before the rows land leaves every sequence at 1, and the forge fails on its next insert. - Indexes and data run with
ON_ERROR_STOP=1on purpose. Once the tables exist, there is no legitimate error left, so any error is real.
Confirm the counts, then save and validate the backup version while Forgejo is still stopped:
$PSQL_APP -At -c "
SELECT (SELECT count(*) FROM information_schema.tables WHERE table_schema='public'),
(SELECT count(*) FROM \"user\"), (SELECT count(*) FROM repository),
(SELECT count(*) FROM public_key)"
RESTORED=$($PSQL_APP -At -v ON_ERROR_STOP=1 -c 'SELECT version FROM forgejo_sem_ver')
[[ "$RESTORED" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] \
|| { echo "missing or invalid backup version: do not start Forgejo"; exit 1; }
readonly RESTOREDThat last value is the Forgejo version that produced the dump. Restore onto the
same version. This procedure loads the dump’s own schema. Starting a newer image
can migrate it before you check, and an older one cannot read it at all. If the
version is missing or is not a stable major.minor.patch version, stop and
investigate rather than guessing an image tag.
Before continuing, edit only the Forgejo image: in the provisioned compose file
to use that saved version as its exact tag. Keep the existing image repository.
Do not use the current channel pin or latest. Read back the resolved image and
refuse to proceed unless its tag matches:
IMAGE=$($COMPOSE config --format json | jq -er --arg s "$SVC_FORGEJO" '.services[$s].image')
[ "${IMAGE##*:}" = "$RESTORED" ] \
|| { echo "pin the Forgejo image to the backup version before continuing"; exit 1; }
$COMPOSE pull "$SVC_FORGEJO"Keep this pin in the compose file for subsequent restarts. If the exact image cannot be pulled, stop with Forgejo still down; do not substitute a newer version.
Step 6: restore the files
Forgejo is still stopped. Restore into clean destinations. A cp -a overlay
keeps every file that is not in the backup, so a replacement’s first-boot files, or
the trees from an earlier attempt, would survive next to the restored database. A
branch or an attachment from the first attempt could stay visible even though git fsck passes. This content is to be discarded, so empty the destinations, then
copy. The paths were validated in step 3, and this deletion only runs on them:
for d in "$REPOS_DIR" "$DATA_DIR"; do
mkdir -p "$d"
find "$d" -mindepth 1 -delete
done
cp -a "$STAGE/unpacked/repos/." "$REPOS_DIR/"
cp -a "$STAGE/unpacked/data/." "$DATA_DIR/"
mkdir -p "$DATA_DIR/conf"The restored app.ini carries the instance’s secret key, internal token and signing
secret, which stored two-factor enrolments and OAuth applications need. Its [database] section describes the old machine’s database, so keep the restored
file and replace only that section with the one saved from the replacement:
awk '/^\[/{skip = ($0=="[database]")} !skip' "$STAGE/unpacked/app.ini" > "$DATA_DIR/conf/app.ini"
{ echo; cat "$KEEP/database-section.ini"; } >> "$DATA_DIR/conf/app.ini"
chown -R 1000:1000 "$REPOS_DIR" "$DATA_DIR"Do not print either file or put a password on a command line.
- Check the compose environment for overrides. Environment variables take
precedence over
app.ini. List the names only, never the values. A replacement that supplies its own secret key, internal token or signing secret through the environment silently replaces the restored ones at startup, and two-factor enrolments and encrypted credentials stop working while sign-in still passes. Remove such a variable, or set it from the restored file through a secret source. Database overrides must agree with the merged settings and withAPP_DBandAPP_ROLE. - Prove the database login. Use a PostgreSQL client on the Forgejo container’s
network to connect over TCP with the effective host, port, database, user,
password and TLS settings, and run
SELECT 1. The local socket connections in step 5 do not prove that password authentication works. Supply the password through a private password file or an interactive prompt. - SSH host keys are not in the dump. The official image keeps the server’s host keys outside the trees restored here. If you backed them up separately, restore them into place before startup. If not, the replacement presents a new host key, and every client that pinned the old one will refuse to connect after cutover. Decide before step 9: restore the old keys, or publish the new fingerprint through an authenticated channel.
- Fix the ownership.
1000:1000is thegituser in the official image. Skipping thechowngives a forge that boots and then fails every git operation.
Step 7: bring it up, with no customer traffic
# Recheck the pin immediately before startup, in the same shell as step 5.
IMAGE=$($COMPOSE config --format json | jq -er --arg s "$SVC_FORGEJO" '.services[$s].image')
[ "${IMAGE##*:}" = "$RESTORED" ] \
|| { echo "Forgejo image no longer matches the backup version"; exit 1; }
$COMPOSE up -d "$SVC_FORGEJO"
# Probe the endpoint the compose file actually publishes, not a port you remember.
# 3000 is Forgejo's HTTP port inside the official image; use the one in your app.ini.
# Select one binding when Docker publishes both IPv4 and IPv6.
ENDPOINT=$($COMPOSE port "$SVC_FORGEJO" 3000 \
| sed -n '1{s/^0\.0\.0\.0:/127.0.0.1:/;s/^\[::\]:/[::1]:/;p;}')
[[ "$ENDPOINT" =~ ^(\[[0-9a-fA-F:.%]+\]|[0-9.]+):[0-9]+$ ]] \
|| { echo "expected one published Forgejo endpoint; do not repoint any records"; exit 1; }
ready=0
for i in $(seq 1 60); do
if SERVING=$(curl -fsS --connect-timeout 2 --max-time 5 "http://$ENDPOINT/api/v1/version" \
| jq -er '.version | select(type == "string")'); then
[ "$SERVING" = "$RESTORED" ] && { ready=1; break; }
fi
sleep 2
done
[ "$ready" -eq 1 ] || { echo "Forgejo is not serving: read its logs, and do not repoint any records"; $COMPOSE logs --tail 50 "$SVC_FORGEJO"; exit 1; }Do not move on until that check has passed. It requires the running forge to report exactly the backup version saved before startup, so a healthy answer from the wrong image does not count.
Keep customer writes blocked until step 8 passes. Withholding DNS is not
enough, because a published port such as 0.0.0.0:3000 or the SSH port is reachable
by address. Bind both to loopback, or allow only your own addresses at the firewall,
before you start Forgejo. Do not repoint the name, and do not let the CDN or any
proxy send customers here yet. Verify through the local
endpoint instead, sending the forge’s real host name, for example with curl --resolve forge.example.com:PORT:127.0.0.1, or through an SSH tunnel. Once
real users can push or file issues, every verification failure becomes a choice
about whether to throw their work away.
A restored forge that starts is a live forge. Restored push mirrors, queued webhooks, mail and Actions can reach external systems the moment it is up. How to fence them is in Cold restore: retries, fences and cutover. If your backup holds mirrors or webhooks, read it before you start Forgejo.
If a step fails
Before the name is repointed, nobody but you can reach the forge, so a failure is
cheap, provided no one else could reach the forge. Fix the cause and re-run the script from the top. Step 3 stops Forgejo and keeps the
saved settings, step 4 makes fresh staging, step 5 drops and reloads the database and
step 6 empties the destinations. Do not patch a
half-restored tree. The replacement’s database settings survive in $KEEP, so
a retry does not need the original app.ini. A re-run rebuilds app.ini from the
backup and $KEEP, so a correction made only in the live app.ini, or an
integration you disabled there, is lost: make it again, or correct the saved file in $KEEP. If the disk filled, free space first.
If a failure appears after the name is repointed, do not re-run anything. The reload drops the database and empties the data directories, which throws away every push, issue and comment accepted since cutover. Block writes, take a fresh dump of the restored forge and keep it, assess what was written, and get an explicit data loss decision from the incident owner before reloading.
Step 8: verify before you hand it back
Do not report success on an HTTP 200. Check each of these against the local endpoint, before the name is repointed:
| Check | How |
|---|---|
| Repository present | The repository API returns it as not empty. |
| History intact | The commits API, compared with what the customer expects. |
| Content correct | Fetch a known file from the raw endpoint. |
| Object store sound | git fsck in the bare repository, and git rev-list --all --count. |
| Users present | The admin users API. |
| SSH keys present | The user keys API, comparing fingerprints. |
| Database-only content | An organisation and an issue render, which proves more than git restored. |
| Login works | Sign in through the web form, not only with basic auth. |
| Encrypted data decrypts | Sign in as a user with two-factor enabled and complete the second factor. This fails if the instance secrets were replaced. |
| SSH identity understood | Clone over SSH with a client that already trusts the original host key, or have the new fingerprint ready to publish. |
| The interface serves content | Fetch a repository page and a file page with that session. |
| Backup protection restored | Re-enable the nightly backup disabled in step 3, run it once, and confirm a new snapshot with fresh success evidence. |
Private repositories return 404 in the interface under basic auth, so an interface check needs a real session cookie. A 404 there is not evidence of a failed restore. Also compare attachments and LFS objects against the backup, since the checks above can all pass with those missing.
For the backup row, use restic snapshots to confirm a new snapshot for this forge
and replacement machine with a dump filename dated after the restore, and match it to
fresh last-success evidence as described in Know when a backup is missing.
An old success value does not count. Record the snapshot id and time in the incident
record before reporting recovery complete.
Step 9: repoint the name and clean up
Only after every check in step 8 has passed, repoint the records. The restore changes the machine’s address, so the records must follow it. If the web name is proxied through a CDN and the git-over-SSH name must not be, check both. A proxied SSH name resolves and answers on the web port, so git hangs while nothing looks broken. Confirm the records converged instead of assuming they did, then repeat the sign-in and a clone through the real name.
Once a clone through the real name works, delete what held secrets:
rm -rf -- "$KEEP"
rm -f -- ./backup.envTiming, honestly
A drill of this procedure, on a forge with one small repository, took a few minutes of hands-on time: derive credentials, load the database, restore the files, start the service. That figure is the procedure only. Budget separately for:
- provisioning and first-boot setup on the replacement machine,
- the pull from the backup, which scales with repository size and bandwidth,
- records and the CDN converging,
- finding the identifiers and derivation inputs.
Do not quote the hands-on figure to a customer. Quote a window you have measured for a forge of their size, and measure again for anything large.
What a drill of this proved, and did not
The procedure was run end to end against a forge that was genuinely destroyed: containers removed, database and data directories deleted, HTTP dead, with only the backup storage surviving.
Proven:
- The production backup script ran unmodified, confirmed by checksum.
- Credentials re-derived after teardown matched the originals, so deriving them rather than storing them holds across the machine’s death.
- The repository decrypted with the re-derived key alone.
- The restored forge served the right content: identical commit ids, file
contents, users, key fingerprints, an organisation and an issue, a clean
git fsck, and a working web session.
Not proven:
- The drill used a faithful local reconstruction, not the production storage provider or a real cloud machine, so provider quirks and real provisioning time are untested.
- TLS on a live hostname was not exercised.
- The shell blocks on this page were written from the drill’s commands but have not been run end to end as one script.
Say so when you report a drill. A result that omits what it did not cover is a claim you cannot defend later.
Failure modes
| What you see | Usual cause | What to do |
|---|---|---|
| The key lists no snapshots or fails to authenticate | Wrong secret-scheme version, or the wrong repository address. | Re-check the version recorded for the forge. |
| The key authenticates but cannot decrypt | The derivation inputs are wrong. | Stop and escalate. Treat a key-restore failure as a security incident. |
| Table creation errors in the first lines of the load | The statements reference tables created later. | Split and replay the tables as in step 5. |
| Index creation errors, or duplicate rows | The dump was loaded over an existing schema. | Drop and recreate an empty database, then load again. |
The database commands fail with role does not exist, or the administrator comes back empty | The bootstrap role was assumed, or POSTGRES_USER was read from the host instead of the container. | Read it inside the database container with a postgres default, validate it, and check it is a superuser. |
| The restore picks a snapshot of an empty forge | latest was used after the replacement started its own backups. | Switch the replacement’s backup job off, and restore a snapshot chosen by id. |
| The forge cannot reach its database after the restore | The restored app.ini still has the old machine’s [database] section. | Replace that section with the replacement’s, as in step 6. |
| The forge boots but the next insert fails | Sequences were set before the data was loaded. | Run the sequence statements last. |
| The forge boots and every git operation fails | Files are owned by the wrong user. | Fix the ownership. |
| Two-factor codes and OAuth apps stop working | app.ini was not restored, or an environment override replaced the instance secrets. | Restore app.ini, and remove or reconcile the secret overrides in the compose project. |
| The forge starts and then refuses its own data | The image version differs from the dump’s. | Restore onto the same version, then upgrade as a separate step. |
| Every developer’s SSH client warns the host key changed | The host keys were not part of the dump and the replacement generated new ones. | Restore the old host keys, or publish the new fingerprint through an authenticated channel. |
| The web works and git over SSH hangs | The SSH name is proxied. | Make the SSH record unproxied. |
| The backup you need is not there | You are past the retention horizon, or the job had stopped. | Say so plainly. Do not promise a restore. |
Known gaps worth closing
Fix these rather than working around them in the next outage.
- A drilled retry, fence and cutover. The hardening page writes them down and tests only its configuration builder. The egress block, the loopback binding and the phase guard have not been run against a real forge.
- A route for a dead forge’s credentials. If the only way to get the backup credentials is a path that requires a healthy forge, you will derive them by hand under pressure. Provide an operator path that accepts a deleted forge.
- Script steps 4 to 6. They are deterministic. Scripting them turns “we can restore” into a support commitment you can defend, and lets a drill run them the same way an outage will.
- Back up the SSH host keys. They are not in the dump, so a rebuilt forge presents a new identity unless they were saved separately.
- A load that does not need workarounds. The ordering and missing-drop problems are in the dump format, so the split-and-replay is the workaround, not a preference.
Related
- Backups and restore drills: proving a backup works before you need it.
- Forgejo patch upgrades you can prove: the rollback point and why migrations only go forward.
- Backups and restore: what each Fjord tier gets.
- Stephen Way