# Back up, restore and migrate

> Choose the streaming client by WAL history, verify an independent restore and plan a major upgrade.

---

LLMS index: [llms.txt](/llms.txt)

---

## Choose the physical backup path {#backup}

Use the binaries paired with the source revision. Set `PGHOST`, `PGPORT` and `PGUSER` for a replication-authorized connection. Choose a new `BACKUP` path on protected storage. Use data checksums on the source, keep the default online page verification enabled and suspend key rotation until the backup finishes. These examples assume the default tablespace layout. With encrypted WAL, r4 excludes cascading physical replication and a restarted standby receiving WAL again from the start of a segment (RISK-36).

**Only relations encrypted, WAL always plaintext.** With no server WAL key history, the paired ordinary client can stream a plain-format backup:

```sh
pg_basebackup -D "$BACKUP" -Fp -X stream
```

**Encrypted WAL or a source referred to the TDE client.** The current switch alone is insufficient if WAL keys were configured previously. For the local example, run the following with read access to the source `PGDATA`. On a separate backup host securely stage the same `pg_tde` metadata from the source. Supply the configured provider files, credentials and historical keys there so the server key can be opened. The file provider in the example uses an absolute path; make that path available to the backup and restore accounts. For providers with relative paths, retain their locations relative to the target. Use the plain directory format with streamed WAL:

```sh
mkdir -m 700 "$BACKUP"
cp -Rp "$PGDATA/pg_tde" "$BACKUP/pg_tde"
pg_tde_basebackup -D "$BACKUP" -E -Fp -X stream
```

## Read the backup independently {#restore}

Before starting a restored copy, verify the backup manifest and all its WAL ranges with the matching reader and keys. Keep an independent inventory of the expected encrypted objects and mappings. Reject a backup with a missing mapping even if both online and manifest checks pass.

1. On an isolated host, make a working copy of the complete backup owned by the database service account. Keep the original backup intact. Supply the same-major Mimus server, matching preloads and the original provider material. For a file keyring, restore its protected copy separately. If external tablespaces were used, restore their files and mappings.
2. Set the restore host’s port and socket directory so your client can only reach the copy. Keep it isolated from replication peers and shared archive destinations. Start the copy with `pg_ctl -D "$RESTORE" -l "$RESTORE_LOG" -w start`. For PITR, provision the continuous WAL archive, restore command, recovery target and `recovery.signal` before the first start.
3. Connect explicitly to the restored database. For the [ledger example](/docs/tde/tables/), run the following. Expect the committed row `1,100`, encryption on table and index, and the `tde` requirement. For a real backup also compare an out-of-line value, row counts and application invariants with the backup-time baseline.

```sql
SELECT id, balance FROM public.ledger ORDER BY id;
SELECT pg_tde_is_encrypted('public.ledger'::regclass),
       pg_tde_is_encrypted('public.ledger_pkey'::regclass);
SHOW mimus_required_features;
```

Compare the heap, indexes and TOAST storage with the saved encryption inventory. Shut down the restored copy cleanly and run `pg_tde_checksums --check -D "$RESTORE"`. Require exit code 0 and `Bad checksums` of 0.

Installing `pg_tde` can create recovery dependencies before the first encrypted user table exists. An older backup may cross this activation point during replay. Equip the recovery host before replay and retain the original marker and key metadata. A missing historical key makes the affected backup unreadable even with intact relation files.

## Cross-major migration {#upgrade}

Use logical dump and restore into a new cluster for a major upgrade. Prepare roles, the target extension and its own keys before loading encrypted objects. Review the dump’s extension entries, table access methods and ownership. Use the target major’s `pg_dump -Fc` and `pg_restore --exit-on-error`, then verify constraints, sequences, rows and encryption on the target. Protect the logical archive as plaintext. Keep the source until the checks pass. Physical `pg_upgrade` of a TDE-marked cluster is outside the 19.0.1 path. [Percona backup procedure](/docs/tde/upstream/how-to/backup-wal-enabled/)

---

Backlinks:

- [Version and verification](/docs/intro/status/)
- [Recovery, failover and rollback](/docs/spock/recovery/)
- [PG TDE](/docs/tde/)
- [Keys and WAL encryption](/docs/tde/keys/)
- [Major upgrade](/docs/tde/upstream/command-line-tools/pg-tde-upgrade/)
- [Backup with WAL encryption enabled](/docs/tde/upstream/how-to/backup-wal-enabled/)
- [Restore encrypted backups](/docs/tde/upstream/how-to/restore-backups/)
- [Uninstall pg_tde](/docs/tde/upstream/how-to/uninstall/)
- [Upgrade pg_tde](/docs/tde/upstream/how-to/upgrade/)
