skip to content

With Barman, how do you restore the timetable server onto a new host to 09:39, just before a bad import ran at 09:40, and what does barman restore set up?

level: seniorimportance: must knowfreq 48%

answer

  1. restore, not recover, since 3.12
  2. a backup that ended earlier
  3. remote SSH to the new host
  4. a target time with its zone
  5. the copy must not archive

basics

~20 s

Run barman restore with --remote-ssh-command to the new host, a backup that ended before 09:39 (or auto), --target-time with an explicit zone and usually --get-wal. Barman copies the files, writes restore_command and the target, creates recovery.signal and disables archive_command; you start PostgreSQL.

solid answer

~40 s

Since Barman 3.12 the command is `barman restore`; `recover` survives only as an alias. Pick a backup that **ended** before 09:39 from `barman list-backups timetable-pg`, or pass `auto` with `--target-time` and Barman chooses the newest suitable one. From the Barman host run `barman restore --remote-ssh-command 'ssh postgres@timetable-new' --target-time '2026-10-06 09:39:00+02' --target-action promote --get-wal timetable-pg auto /var/lib/postgresql/18/main`. Barman copies the backup over SSH, appends `restore_command` (here `barman-wal-restore`, so barman-cli must be on the new host) and the `recovery_target_*` settings to `postgresql.auto.conf`, creates `recovery.signal`, and comments out `archive_command`, setting it to `false` so the copy cannot write into the live archive. A `--target-time` without a zone is read in the **Barman host's** zone. Then start PostgreSQL on the new host; it replays to 09:39 and promotes.

code

bash · 7 lines
bash
barman list-backups timetable-pg
barman restore \
  --remote-ssh-command 'ssh postgres@timetable-new' \
  --target-time '2026-10-06 09:39:00+02' \
  --target-action promote \
  --get-wal \
  timetable-pg auto /var/lib/postgresql/18/main

go deeper

for a junior

Remember that the command is barman restore, that it prepares a directory rather than starting PostgreSQL, and that it needs a backup ID or auto.

for a middle

Explain which backup can serve a target, what --get-wal changes, and which files Barman writes into the restored directory.

for a senior

Run a remote point-in-time restore end to end, catching the time-zone, end-time and archive_command traps before they cost the recovery.

for a principal

Plan how restores to a new host fit an incident runbook: who owns the target choice, how the copy is validated, and how it rejoins backups.

## `restore`, not `recover` In Barman, **restore** means copying a backup to a destination and preparing it so that PostgreSQL can perform **recovery** (replaying WAL) when it starts. Barman 3.12 renamed `barman recover` to `barman restore` to make that distinction clear; `recover` is kept only as a deprecated alias. This answer assumes Barman 3.20 and a PostgreSQL 18 backup. Scenario: at a regional public-transport operator, a faulty timetable import ran at 09:40 against `timetable-pg`. The goal is a copy of that database on a fresh host, `timetable-new`, as it was at 09:39, so the planners can extract the good data or switch over. ## Choosing the backup A recovery target must lie **after the end** of the chosen backup; Barman rejects a target time earlier than the backup's end time. Two ways to pick: - `barman list-backups timetable-pg` and choose the newest backup whose end time is before 09:39; - pass `auto` as the backup ID with `--target-time` (or `--target-lsn`, optionally with `--target-tli`), and Barman picks the most recent backup available up to that target. With `auto`, only those target types are allowed. `barman show-backup timetable-pg BACKUP_ID` shows a backup's begin and end times and its WAL range. The gap between that end time and 09:39 is the WAL PostgreSQL must replay, so the newest suitable backup is also the fastest one; an older backup works but adds replay time. ## The command, flag by flag | Flag | Effect | |---|---| | `--remote-ssh-command 'ssh postgres@timetable-new'` | restore onto another host over SSH; without it Barman restores locally on the Barman host | | `--target-time '2026-10-06 09:39:00+02'` | stop replay at that instant; also `--target-lsn`, `--target-xid`, `--target-name`, `--target-immediate` | | `--target-action promote` | promote at the target; `pause` and `shutdown` are the alternatives | | `--get-wal` | PostgreSQL fetches WAL from Barman on demand instead of Barman copying it all up front | | `--exclusive` | stop just before the target instead of including it | | `--tablespace NAME:DIR` | relocate a tablespace on the new host | | `--standby-mode` | write `standby.signal` instead, to build a replica | ## What Barman writes into the restored directory - The base backup files, copied with rsync over SSH (or rebuilt with `pg_combinebackup` first if the backup is block-level incremental). - In `postgresql.auto.conf`: `restore_command` and the `recovery_target_*` lines. With `--get-wal` on a remote restore the command is `barman-wal-restore`, from **barman-cli**, which must be installed on the target; locally it is `barman get-wal`. Without `--get-wal`, Barman copies the needed WAL into a `barman_wal` directory in the destination and uses `cp`; with a time, xid or name target that means the **entire WAL archive**. - An empty `recovery.signal` (or `standby.signal` with `--standby-mode`). - Every `archive_command` in the restored configuration is commented out with a `#BARMAN#` prefix and replaced by `archive_command = false`, so the copy cannot push its WAL into the production archive. Barman prints these changes as IMPORTANT for you to review. ## Starting it 1. Check the free space on `timetable-new` for the backup and WAL; a remote restore without `--get-wal` also needs space in the Barman host's temporary directory. 2. Run the `barman restore` command from the Barman host as the `barman` user, with SSH public-key access as `postgres` to the target. 3. Review the configuration changes Barman reports, then start PostgreSQL 18 on `timetable-new` as `postgres`. 4. Watch the log until it reports reaching the recovery target and promotes, then verify the timetable rows from just before 09:40. 5. Only if this copy becomes the new primary, give it a real `archive_command` again, under a new Barman server section or one that expects the new timeline. ## Traps - **Time zones:** a `--target-time` without a zone is read in the Barman host's zone, with a warning. Always write the offset. - **Wrong backup:** a backup that *started* before 09:39 but *ended* after it cannot reach 09:39. - **Slow restore without `--get-wal`:** copying the whole archive for a time target can dominate the restore time. - **Wrong mental model:** `barman restore` does not start PostgreSQL; it only prepares the directory.

  • Why can a barman restore with --target-time take much longer without --get-wal?
    Without `--get-wal`, Barman copies the WAL into the destination before PostgreSQL starts. For time, xid or name targets it cannot know where replay stops, so it copies the entire WAL archive. With `--get-wal`, PostgreSQL fetches only the segments it needs on demand through `barman-wal-restore` or `barman get-wal`.
  • What does barman restore do to archive_command in the restored configuration, and why?
    It comments out every `archive_command` line with a `#BARMAN#` prefix and writes `archive_command = false`. A restored copy that kept the production setting would start archiving into the same Barman server under the same name, mixing a new timeline into the live archive. You re-enable archiving deliberately if the copy becomes a primary.

  • barman recover is the current command and barman restore does not exist
  • Any backup that started before 09:39 can reach a 09:39 target
  • A --target-time without a zone is read as UTC
  • barman restore starts PostgreSQL on the target host for you
  • The restored copy keeps archiving into the production Barman archive

Assumes Barman 3.20 restoring a PostgreSQL 18 backup; barman recover was renamed barman restore in 3.12 and is only a deprecated alias.