4.6. Remote Restore #
Remote restore in pg_probackup3 is a feature that allows restoring backups directly to a remote host without the need to manually copy archive files. This approach significantly reduces recovery time and minimizes manual operations during disaster recovery, migration, or automated deployment. It is particularly useful in infrastructures with centralized backup storage where recovery is performed onto isolated remote servers.
The remote restore process includes the following components:
the send-backup command to send data to the specified port of the remote server using multithreading
the receive-backup command to receive, extract, and restore the data
4.6.1. Prerequisites #
The following conditions must be met for successful remote restore:
The pg_probackup3 utility and the
libpgprobackup.solibrary must be installed on both the local and remote hosts.The backup catalog must be accessible on the local host.
On the remote host:
For full restore, the target data directory must be empty.
For incremental restore (
-I/--incremental-mode), the target data directory must exist and contain data. The server using the target directory must be stopped, and, forLSNmode, the directory must not contain abackup_labelfile, which indicates an unfinished backup. If the target directory is empty, the operation automatically switches to full restore.The specified port must be open and available for incoming connections.
Both send-backup and receive-backup must use the same port.
4.6.2. Restoring a Backup to a Remote Host #
To restore an instance to a remote host, follow the steps below.
On the remote host, run the receive-backup command to start listening on a port:
pg_probackup3 receive-backup -D
target_data_dir-pportThe command enters a wait state, listening for an incoming connection.
On the local host, run the send-backup command to send the backup data to the specified port of the remote host:
pg_probackup3 send-backup -B
backup_dir--instance=instance_name-ibackup_id-pport-hhost[--no-merge] [-Iincremental_mode] [remote_wal_archive_options]Using the
--no-mergeflag prevents the backup chain from being merged before the data transfer. Otherwise, the backup chain is merged into a temporary file, which is deleted once the transfer is complete.To perform remote incremental restore, specify the
-I/--incremental-modeoption.Warning
For remote incremental restore, the
-Ioption must be used together with--no-merge. Otherwise, the operation will fail.incremental_modecan take one of the following values:CHECKSUM(recommended): All data files in the target data directory are read. For each page, the header and checksum are validated. Only pages that are invalid, or whose checksum or LSN does not match the corresponding page in the backup, are replaced. This is the simplest and most reliable incremental mode.LSN: Thepg_controlfile in the target data directory is read to obtain the redo LSN and timeline, determining the shiftpoint — the point where the data directory state diverged from the backup chain history. If the shiftpoint lies outside the backup chain history, the restore is aborted. If it lies within, all data files are read, each page header and checksum is validated, and only invalid pages and those with an LSN greater than the shiftpoint are replaced. This mode offers a greater speedup compared toCHECKSUM, but relies on two conditions:Data checksums must be enabled in the data directory (to avoid corruption due to hint bits). This condition is checked at the start of incremental restore, and the operation aborts if checksums are disabled.
The
pg_controlfile must be synchronized with the state of the data directory. This condition cannot be checked automatically, so it is the user's responsibility to ensure thatpg_controlcontains valid information. Therefore,LSNmode is not recommended in any situation wherepg_controlcannot be trusted or may have been tampered with — for example, after runningpg_resetwalor after a restore from backup without WAL replay.
(Optional) The
send-backupcommand does not support recovery target options. Therefore, if you are restoring anARCHIVEbackup and do not want all available WAL files to be replayed on first startup, manually add the following line to thepostgresql.auto.conffile in the targetPGDATAdirectory once thereceive-backupoperation is finished:recovery_target = 'immediate'
4.6.3. Operation Specifics #
If the backup chain contains an ARCHIVE backup, an empty recovery.signal file is created in the target PGDATA directory. It is deleted automatically once recovery is complete.
restore_command is constructed from the archive_command that uses archive-push and is found in postgresql.auto.conf or postgresql.conf. For a remote WAL archive, the connection parameters specified by --archive-host, --archive-port, and --archive-user of send-backup are added to restore_command. If no such archive_command exists, restore_command must be set manually.
If the entire chain consists of STREAM backups, recovery.signal and restore_command are not created.