mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2026-06-21 01:34:15 +02:00
[Issue #102] New options for 'restore' command used for setting 'restore_command' GUC in recovery.conf: '--archive-host', '--archive-post', 'archive-user' and '--restore-command'
This commit is contained in:
+46
-5
@@ -68,6 +68,7 @@ Current version - 2.1.5
|
||||
* [Compression Options](#compression-options)
|
||||
* [Archiving Options](#archiving-options)
|
||||
* [Remote Mode Options](#remote-mode-options)
|
||||
* [Remote WAL Archive Options](#remote-wal-archive-options)
|
||||
* [Replica Options](#replica-options)
|
||||
|
||||
7. [Authors](#authors)
|
||||
@@ -546,6 +547,8 @@ Once the restore command is complete, start the database service.
|
||||
|
||||
If you are restoring an STREAM backup, the restore is complete at once, with the cluster returned to a self-consistent state at the point when the backup was taken. For ARCHIVE backups, PostgreSQL replays all available archived WAL segments, so the cluster is restored to the latest state possible. You can change this behavior by using the [recovery target options](#recovery-target-options) with the `restore` command. Note that using the [recovery target options](#recovery-target-options) when restoring STREAM backup is possible if the WAL archive is available at least starting from the time the STREAM backup was taken.
|
||||
|
||||
To restore cluster on remote host see the section [Using pg_probackup in the Remote Mode](#using-pg-probackup-in-the-remote-mode).
|
||||
|
||||
>NOTE: By default, the [restore](#restore) command validates the specified backup before restoring the cluster. If you run regular backup validations and would like to save time when restoring the cluster, you can specify the `--no-validate` flag to skip validation and speed up the recovery.
|
||||
|
||||
#### Partial Restore
|
||||
@@ -624,6 +627,24 @@ For example, to restore latest backup on remote system using remote mode through
|
||||
|
||||
pg_probackup restore -B backup_dir --instance instance_name --remote-user=postgres --remote-host=192.168.0.2 --remote-port=2302
|
||||
|
||||
Restoring of ARCHIVE backup or performing PITR in remote mode require additional information: destination address, port and username for establishing ssh connection **from** a host with database **to** a host with backup catalog. This information will be used by `restore_command` to copy via ssh WAL segments from archive to PostgreSQL 'pg_wal' directory.
|
||||
|
||||
To solve this problem you can use [Remote Wal Archive Options](#remote-wal-archive-options).
|
||||
|
||||
For example, to restore latest backup on remote system using remote mode through SSH connection to user `postgres` on host with address `192.168.0.2` via port `2302` and user `backup` on backup catalog host with address `192.168.0.3` via port `2303`, run:
|
||||
|
||||
pg_probackup restore -B backup_dir --instance instance_name --remote-user=postgres --remote-host=192.168.0.2 --remote-port=2302 --archive-host=192.168.0.3 --archive-port=2303 --archive-user=backup
|
||||
|
||||
Provided arguments will be used to construct 'restore_command' in recovery.conf:
|
||||
```
|
||||
# recovery.conf generated by pg_probackup 2.1.5
|
||||
restore_command = 'pg_probackup archive-get -B backup_dir --instance instance_name --wal-file-path=%p --wal-file-name=%f --remote-host=192.168.0.3 --remote-port=2303 --remote-user=backup'
|
||||
```
|
||||
|
||||
Alternatively you can use `--restore-command` option to provide an entire 'restore_command':
|
||||
|
||||
pg_probackup restore -B backup_dir --instance instance_name --remote-user=postgres --remote-host=192.168.0.2 --remote-port=2302 --restore-command='pg_probackup archive-get -B backup_dir --instance instance_name --wal-file-path=%p --wal-file-name=%f --remote-host=192.168.0.3 --remote-port=2303 --remote-user=backup'
|
||||
|
||||
>NOTE: The remote backup mode is currently unavailable for Windows systems.
|
||||
|
||||
### Running pg_probackup on Parallel Threads
|
||||
@@ -1054,7 +1075,7 @@ The sample output is as follows:
|
||||
Most fields are consistent with plain format, with some exceptions:
|
||||
|
||||
- size is in bytes.
|
||||
- 'closest-backup-id' attribute contain ID of valid backup closest to the timeline, located on some of the previous timelines. This backup is the closest starting point to reach the timeline from other timelines by PITR. If such backup do not exists, then string is empty.
|
||||
- 'closest-backup-id' attribute contain ID of valid backup closest to the timeline, located on some of the previous timelines. This backup is the closest starting point to reach the timeline from other timelines by PITR. Closest backup always has a valid status, either OK or DONE. If such backup do not exists, then string is empty.
|
||||
- DEGRADED timelines contain 'lost-segments' array with information about intervals of missing segments. In OK timelines 'lost-segments' array is empty.
|
||||
- 'N backups' attribute is replaced with 'backups' array containing backups belonging to the timeline. If timeline has no backups, then 'backups' array is empty.
|
||||
|
||||
@@ -1214,7 +1235,8 @@ Deletes all backups and WAL files associated with the specified instance.
|
||||
[--compress-algorithm=compression_algorithm] [--compress-level=compression_level]
|
||||
[-d dbname] [-h host] [-p port] [-U username]
|
||||
[--archive-timeout=timeout] [--external-dirs=external_directory_path]
|
||||
[remote_options] [logging_options]
|
||||
[--restore-command=cmdline]
|
||||
[remote_options] [remote_archive_options] [logging_options]
|
||||
|
||||
Adds the specified connection, compression, retention, logging and external directory settings into the pg_probackup.conf configuration file, or modifies the previously defined values.
|
||||
|
||||
@@ -1308,8 +1330,9 @@ For details on usage, see the section [Creating a Backup](#creating-a-backup).
|
||||
[-j num_threads] [--progress]
|
||||
[-T OLDDIR=NEWDIR] [--external-mapping=OLDDIR=NEWDIR] [--skip-external-dirs]
|
||||
[-R | --restore-as-replica] [--no-validate] [--skip-block-validation]
|
||||
[--restore-command=cmdline]
|
||||
[recovery_options] [logging_options] [remote_options]
|
||||
[partial_restore_options]
|
||||
[partial_restore_options] [remote_archive_options]
|
||||
|
||||
Restores the PostgreSQL instance from a backup copy located in the *backup_dir* backup catalog. If you specify a [recovery target option](#recovery-target-options), pg_probackup will find the closest backup and restores it to the specified recovery target. Otherwise, the most recent backup is used.
|
||||
|
||||
@@ -1333,7 +1356,10 @@ Disables block-level checksum verification to speed up validation. During automa
|
||||
--no-validate
|
||||
Skips backup validation. You can use this flag if you validate backups regularly and would like to save time when running restore operations.
|
||||
|
||||
Additionally [Recovery Target Options](#recovery-target-options), [Remote Mode Options](#remote-mode-options), [Logging Options](#logging-options), [Partial Restore](#partial-restore) and [Common Options](#common-options) can be used.
|
||||
--restore-command=cmdline
|
||||
Set the [restore_command](https://www.postgresql.org/docs/current/archive-recovery-settings.html#RESTORE-COMMAND) parameter to specified command. Example: `--restore-command='cp /mnt/server/archivedir/%f "%p"'`
|
||||
|
||||
Additionally [Recovery Target Options](#recovery-target-options), [Remote Mode Options](#remote-mode-options), [Remote WAL Archive Options](#remote-wal-archive-options), [Logging Options](#logging-options), [Partial Restore](#partial-restore) and [Common Options](#common-options) can be used.
|
||||
|
||||
For details on usage, see the section [Restoring a Cluster](#restoring-a-cluster).
|
||||
|
||||
@@ -1656,9 +1682,24 @@ Specifies pg_probackup installation directory on the remote system.
|
||||
--ssh-options=ssh_options
|
||||
Specifies a string of SSH command-line options. For example, the following options can used to set keep-alive for ssh connections opened by pg_probackup: `--ssh-options='-o ServerAliveCountMax=5 -o ServerAliveInterval=60'`. Full list of possible options can be found on [ssh_config manual page](https://man.openbsd.org/ssh_config.5).
|
||||
|
||||
#### Remote WAL Archive Options
|
||||
|
||||
This section describes the options used to provide the arguments for [Remote Mode Options](#remote-mode-options) in [archive-get](#archive-get) used in [restore_command](https://www.postgresql.org/docs/current/archive-recovery-settings.html#RESTORE-COMMAND) command when restoring ARCHIVE backup or performing PITR.
|
||||
|
||||
--archive-host=destination
|
||||
Provides the argument for `--remote-host` option in `archive-get` command.
|
||||
|
||||
--archive-port=port
|
||||
Default: 22
|
||||
Provides the argument for `--remote-port` option in `archive-get` command.
|
||||
|
||||
--archive-user=username
|
||||
Default: PostgreSQL user
|
||||
Provides the argument for `--remote-user` option in `archive-get` command. If you omit this option, the the user running PostgreSQL cluster is used.
|
||||
|
||||
#### Partial Restore Options
|
||||
|
||||
This section describes the options related to partial restore of cluster from backup. These options can be used with [restore](#restore) command.
|
||||
This section describes the options related to partial restore of a cluster from backup. These options can be used with [restore](#restore) command.
|
||||
|
||||
--db-exclude=dbname
|
||||
Specifies database name to exclude from restore. All other databases in the cluster will be restored as usual, including `template0` and `template1`. This option can be specified multiple times for multiple databases.
|
||||
|
||||
+33
-18
@@ -122,97 +122,112 @@ ConfigOption instance_options[] =
|
||||
&instance_config.archive_timeout, SOURCE_CMD, SOURCE_DEFAULT,
|
||||
OPTION_ARCHIVE_GROUP, OPTION_UNIT_S, option_get_value
|
||||
},
|
||||
{
|
||||
's', 208, "archive-host",
|
||||
&instance_config.archive.host, SOURCE_CMD, 0,
|
||||
OPTION_ARCHIVE_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
's', 209, "archive-port",
|
||||
&instance_config.archive.port, SOURCE_CMD, 0,
|
||||
OPTION_ARCHIVE_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
's', 210, "archive-user",
|
||||
&instance_config.archive.user, SOURCE_CMD, 0,
|
||||
OPTION_ARCHIVE_GROUP, 0, option_get_value
|
||||
},
|
||||
/* Logging options */
|
||||
{
|
||||
'f', 208, "log-level-console",
|
||||
'f', 211, "log-level-console",
|
||||
assign_log_level_console, SOURCE_CMD, 0,
|
||||
OPTION_LOG_GROUP, 0, get_log_level_console
|
||||
},
|
||||
{
|
||||
'f', 209, "log-level-file",
|
||||
'f', 212, "log-level-file",
|
||||
assign_log_level_file, SOURCE_CMD, 0,
|
||||
OPTION_LOG_GROUP, 0, get_log_level_file
|
||||
},
|
||||
{
|
||||
's', 210, "log-filename",
|
||||
's', 213, "log-filename",
|
||||
&instance_config.logger.log_filename, SOURCE_CMD, 0,
|
||||
OPTION_LOG_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
's', 211, "error-log-filename",
|
||||
's', 214, "error-log-filename",
|
||||
&instance_config.logger.error_log_filename, SOURCE_CMD, 0,
|
||||
OPTION_LOG_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
's', 212, "log-directory",
|
||||
's', 215, "log-directory",
|
||||
&instance_config.logger.log_directory, SOURCE_CMD, 0,
|
||||
OPTION_LOG_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
'U', 213, "log-rotation-size",
|
||||
'U', 216, "log-rotation-size",
|
||||
&instance_config.logger.log_rotation_size, SOURCE_CMD, SOURCE_DEFAULT,
|
||||
OPTION_LOG_GROUP, OPTION_UNIT_KB, option_get_value
|
||||
},
|
||||
{
|
||||
'U', 214, "log-rotation-age",
|
||||
'U', 217, "log-rotation-age",
|
||||
&instance_config.logger.log_rotation_age, SOURCE_CMD, SOURCE_DEFAULT,
|
||||
OPTION_LOG_GROUP, OPTION_UNIT_MS, option_get_value
|
||||
},
|
||||
/* Retention options */
|
||||
{
|
||||
'u', 215, "retention-redundancy",
|
||||
'u', 218, "retention-redundancy",
|
||||
&instance_config.retention_redundancy, SOURCE_CMD, 0,
|
||||
OPTION_RETENTION_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
'u', 216, "retention-window",
|
||||
'u', 219, "retention-window",
|
||||
&instance_config.retention_window, SOURCE_CMD, 0,
|
||||
OPTION_RETENTION_GROUP, 0, option_get_value
|
||||
},
|
||||
/* Compression options */
|
||||
{
|
||||
'f', 217, "compress-algorithm",
|
||||
'f', 220, "compress-algorithm",
|
||||
assign_compress_alg, SOURCE_CMD, 0,
|
||||
OPTION_COMPRESS_GROUP, 0, get_compress_alg
|
||||
},
|
||||
{
|
||||
'u', 218, "compress-level",
|
||||
'u', 221, "compress-level",
|
||||
&instance_config.compress_level, SOURCE_CMD, 0,
|
||||
OPTION_COMPRESS_GROUP, 0, option_get_value
|
||||
},
|
||||
/* Remote backup options */
|
||||
{
|
||||
's', 219, "remote-proto",
|
||||
's', 222, "remote-proto",
|
||||
&instance_config.remote.proto, SOURCE_CMD, 0,
|
||||
OPTION_REMOTE_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
's', 220, "remote-host",
|
||||
's', 223, "remote-host",
|
||||
&instance_config.remote.host, SOURCE_CMD, 0,
|
||||
OPTION_REMOTE_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
's', 221, "remote-port",
|
||||
's', 224, "remote-port",
|
||||
&instance_config.remote.port, SOURCE_CMD, 0,
|
||||
OPTION_REMOTE_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
's', 222, "remote-path",
|
||||
's', 225, "remote-path",
|
||||
&instance_config.remote.path, SOURCE_CMD, 0,
|
||||
OPTION_REMOTE_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
's', 223, "remote-user",
|
||||
's', 226, "remote-user",
|
||||
&instance_config.remote.user, SOURCE_CMD, 0,
|
||||
OPTION_REMOTE_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
's', 224, "ssh-options",
|
||||
's', 227, "ssh-options",
|
||||
&instance_config.remote.ssh_options, SOURCE_CMD, 0,
|
||||
OPTION_REMOTE_GROUP, 0, option_get_value
|
||||
},
|
||||
{
|
||||
's', 225, "ssh-config",
|
||||
's', 228, "ssh-config",
|
||||
&instance_config.remote.ssh_config, SOURCE_CMD, 0,
|
||||
OPTION_REMOTE_GROUP, 0, option_get_value
|
||||
},
|
||||
|
||||
+27
-7
@@ -97,6 +97,8 @@ help_pg_probackup(void)
|
||||
printf(_(" [--remote-proto] [--remote-host]\n"));
|
||||
printf(_(" [--remote-port] [--remote-path] [--remote-user]\n"));
|
||||
printf(_(" [--ssh-options]\n"));
|
||||
printf(_(" [--restore-command=cmdline] [--archive-host=destination]\n"));
|
||||
printf(_(" [--archive-port=port] [--archive-user=username]\n"));
|
||||
printf(_(" [--help]\n"));
|
||||
|
||||
printf(_("\n %s show-config -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
|
||||
@@ -142,11 +144,13 @@ help_pg_probackup(void)
|
||||
printf(_(" [--no-validate] [--skip-block-validation]\n"));
|
||||
printf(_(" [-T OLDDIR=NEWDIR] [--progress]\n"));
|
||||
printf(_(" [--external-mapping=OLDDIR=NEWDIR]\n"));
|
||||
printf(_(" [--skip-external-dirs]\n"));
|
||||
printf(_(" [--skip-external-dirs] [--restore-command=cmdline]\n"));
|
||||
printf(_(" [--db-include | --db-exclude]\n"));
|
||||
printf(_(" [--remote-proto] [--remote-host]\n"));
|
||||
printf(_(" [--remote-port] [--remote-path] [--remote-user]\n"));
|
||||
printf(_(" [--ssh-options]\n"));
|
||||
printf(_(" [--archive-host=hostname]\n"));
|
||||
printf(_(" [--archive-port=port] [--archive-user=username]\n"));
|
||||
printf(_(" [--help]\n"));
|
||||
|
||||
printf(_("\n %s validate -B backup-path [--instance=instance_name]\n"), PROGRAM_NAME);
|
||||
@@ -331,7 +335,7 @@ help_backup(void)
|
||||
printf(_("\n Remote options:\n"));
|
||||
printf(_(" --remote-proto=protocol remote protocol to use\n"));
|
||||
printf(_(" available options: 'ssh', 'none' (default: ssh)\n"));
|
||||
printf(_(" --remote-host=hostname remote host address or hostname\n"));
|
||||
printf(_(" --remote-host=destination remote host address or hostname\n"));
|
||||
printf(_(" --remote-port=port remote host port (default: 22)\n"));
|
||||
printf(_(" --remote-path=path path to directory with pg_probackup binary on remote host\n"));
|
||||
printf(_(" (default: current binary path)\n"));
|
||||
@@ -363,10 +367,13 @@ help_restore(void)
|
||||
printf(_(" [-T OLDDIR=NEWDIR] [--progress]\n"));
|
||||
printf(_(" [--external-mapping=OLDDIR=NEWDIR]\n"));
|
||||
printf(_(" [--skip-external-dirs]\n"));
|
||||
printf(_(" [--restore-command=cmdline]\n"));
|
||||
printf(_(" [--db-include dbname | --db-exclude dbname]\n"));
|
||||
printf(_(" [--remote-proto] [--remote-host]\n"));
|
||||
printf(_(" [--remote-port] [--remote-path] [--remote-user]\n"));
|
||||
printf(_(" [--ssh-options]\n\n"));
|
||||
printf(_(" [--ssh-options]\n"));
|
||||
printf(_(" [--archive-host=hostname] [--archive-port=port]\n"));
|
||||
printf(_(" [--archive-user=username]\n\n"));
|
||||
|
||||
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
|
||||
printf(_(" --instance=instance_name name of the instance\n"));
|
||||
@@ -401,6 +408,7 @@ help_restore(void)
|
||||
printf(_(" --external-mapping=OLDDIR=NEWDIR\n"));
|
||||
printf(_(" relocate the external directory from OLDDIR to NEWDIR\n"));
|
||||
printf(_(" --skip-external-dirs do not restore all external directories\n"));
|
||||
printf(_(" --restore-command=cmdline command to use as 'restore_command' in recovery.conf\n"));
|
||||
|
||||
printf(_("\n Partial restore options:\n"));
|
||||
printf(_(" --db-include dbname restore only specified databases\n"));
|
||||
@@ -430,13 +438,18 @@ help_restore(void)
|
||||
printf(_("\n Remote options:\n"));
|
||||
printf(_(" --remote-proto=protocol remote protocol to use\n"));
|
||||
printf(_(" available options: 'ssh', 'none' (default: ssh)\n"));
|
||||
printf(_(" --remote-host=hostname remote host address or hostname\n"));
|
||||
printf(_(" --remote-host=destination remote host address or hostname\n"));
|
||||
printf(_(" --remote-port=port remote host port (default: 22)\n"));
|
||||
printf(_(" --remote-path=path path to directory with pg_probackup binary on remote host\n"));
|
||||
printf(_(" (default: current binary path)\n"));
|
||||
printf(_(" --remote-user=username user name for ssh connection (default: current user)\n"));
|
||||
printf(_(" --ssh-options=ssh_options additional ssh options (default: none)\n"));
|
||||
printf(_(" (example: --ssh-options='-c cipher_spec -F configfile')\n\n"));
|
||||
printf(_(" (example: --ssh-options='-c cipher_spec -F configfile')\n"));
|
||||
|
||||
printf(_("\n Remote WAL archive options:\n"));
|
||||
printf(_(" --archive-host=destination address or hostname for ssh connection to archive host\n"));
|
||||
printf(_(" --archive-port=port port for ssh connection to archive host (default: 22)\n"));
|
||||
printf(_(" --archive-user=username user name for ssh connection to archive host (default: PostgreSQL user)\n\n"));
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -652,6 +665,7 @@ help_set_config(void)
|
||||
printf(_("\n%s set-config -B backup-path --instance=instance_name\n"), PROGRAM_NAME);
|
||||
printf(_(" [-D pgdata-path]\n"));
|
||||
printf(_(" [-E external-directories-paths]\n"));
|
||||
printf(_(" [--restore-command=cmdline]\n"));
|
||||
printf(_(" [--log-level-console=log-level-console]\n"));
|
||||
printf(_(" [--log-level-file=log-level-file]\n"));
|
||||
printf(_(" [--log-filename=log-filename]\n"));
|
||||
@@ -675,6 +689,7 @@ help_set_config(void)
|
||||
printf(_(" -E --external-dirs=external-directories-paths\n"));
|
||||
printf(_(" backup some directories not from pgdata \n"));
|
||||
printf(_(" (example: --external-dirs=/tmp/dir1:/tmp/dir2)\n"));
|
||||
printf(_(" --restore-command=cmdline command to use as 'restore_command' in recovery.conf\n"));
|
||||
|
||||
printf(_("\n Logging options:\n"));
|
||||
printf(_(" --log-level-console=log-level-console\n"));
|
||||
@@ -722,7 +737,7 @@ help_set_config(void)
|
||||
printf(_("\n Remote options:\n"));
|
||||
printf(_(" --remote-proto=protocol remote protocol to use\n"));
|
||||
printf(_(" available options: 'ssh', 'none' (default: ssh)\n"));
|
||||
printf(_(" --remote-host=hostname remote host address or hostname\n"));
|
||||
printf(_(" --remote-host=destination remote host address or hostname\n"));
|
||||
printf(_(" --remote-port=port remote host port (default: 22)\n"));
|
||||
printf(_(" --remote-path=path path to directory with pg_probackup binary on remote host\n"));
|
||||
printf(_(" (default: current binary path)\n"));
|
||||
@@ -730,6 +745,11 @@ help_set_config(void)
|
||||
printf(_(" --ssh-options=ssh_options additional ssh options (default: none)\n"));
|
||||
printf(_(" (example: --ssh-options='-c cipher_spec -F configfile')\n"));
|
||||
|
||||
printf(_("\n Remote WAL archive options:\n"));
|
||||
printf(_(" --archive-host=destination address or hostname for ssh connection to archive host\n"));
|
||||
printf(_(" --archive-port=port port for ssh connection to archive host (default: 22)\n"));
|
||||
printf(_(" --archive-user=username user name for ssh connection to archive host (default: PostgreSQL user)\n"));
|
||||
|
||||
printf(_("\n Replica options:\n"));
|
||||
printf(_(" --master-user=user_name user name to connect to master (deprecated)\n"));
|
||||
printf(_(" --master-db=db_name database to connect to master (deprecated)\n"));
|
||||
@@ -769,7 +789,7 @@ help_add_instance(void)
|
||||
printf(_("\n Remote options:\n"));
|
||||
printf(_(" --remote-proto=protocol remote protocol to use\n"));
|
||||
printf(_(" available options: 'ssh', 'none' (default: ssh)\n"));
|
||||
printf(_(" --remote-host=hostname remote host address or hostname\n"));
|
||||
printf(_(" --remote-host=destination remote host address or hostname\n"));
|
||||
printf(_(" --remote-port=port remote host port (default: 22)\n"));
|
||||
printf(_(" --remote-path=path path to directory with pg_probackup binary on remote host\n"));
|
||||
printf(_(" (default: current binary path)\n"));
|
||||
|
||||
+4
-1
@@ -87,6 +87,7 @@ static char *target_stop;
|
||||
static bool target_immediate;
|
||||
static char *target_name = NULL;
|
||||
static char *target_action = NULL;
|
||||
static char *restore_command = NULL;
|
||||
|
||||
static pgRecoveryTarget *recovery_target_options = NULL;
|
||||
static pgRestoreParams *restore_params = NULL;
|
||||
@@ -182,6 +183,7 @@ static ConfigOption cmd_options[] =
|
||||
{ 'b', 156, "skip-external-dirs", &skip_external_dirs, SOURCE_CMD_STRICT },
|
||||
{ 'f', 158, "db-include", opt_datname_include_list, SOURCE_CMD_STRICT },
|
||||
{ 'f', 159, "db-exclude", opt_datname_exclude_list, SOURCE_CMD_STRICT },
|
||||
{ 's', 160, "restore-command", &restore_command, SOURCE_CMD_STRICT },
|
||||
/* checkdb options */
|
||||
{ 'b', 195, "amcheck", &need_amcheck, SOURCE_CMD_STRICT },
|
||||
{ 'b', 196, "heapallindexed", &heapallindexed, SOURCE_CMD_STRICT },
|
||||
@@ -204,7 +206,7 @@ static ConfigOption cmd_options[] =
|
||||
{ 'b', 152, "overwrite", &file_overwrite, SOURCE_CMD_STRICT },
|
||||
/* show options */
|
||||
{ 'f', 153, "format", opt_show_format, SOURCE_CMD_STRICT },
|
||||
{ 'b', 160, "archive", &show_archive, SOURCE_CMD_STRICT },
|
||||
{ 'b', 161, "archive", &show_archive, SOURCE_CMD_STRICT },
|
||||
|
||||
/* options for backward compatibility */
|
||||
{ 's', 136, "time", &target_time, SOURCE_CMD_STRICT },
|
||||
@@ -641,6 +643,7 @@ main(int argc, char *argv[])
|
||||
restore_params->skip_external_dirs = skip_external_dirs;
|
||||
restore_params->partial_db_list = NULL;
|
||||
restore_params->partial_restore_type = NONE;
|
||||
restore_params->restore_command = restore_command;
|
||||
|
||||
/* handle partial restore parameters */
|
||||
if (datname_exclude_list && datname_include_list)
|
||||
|
||||
@@ -220,6 +220,14 @@ typedef struct ConnectionArgs
|
||||
PGcancel *cancel_conn;
|
||||
} ConnectionArgs;
|
||||
|
||||
/* Store values for --remote-* option for 'restore_command' constructor */
|
||||
typedef struct ArchiveOptions
|
||||
{
|
||||
const char *host;
|
||||
const char *port;
|
||||
const char *user;
|
||||
} ArchiveOptions;
|
||||
|
||||
/*
|
||||
* An instance configuration. It can be stored in a configuration file or passed
|
||||
* from command line.
|
||||
@@ -256,6 +264,9 @@ typedef struct InstanceConfig
|
||||
|
||||
CompressAlg compress_alg;
|
||||
int compress_level;
|
||||
|
||||
/* Archive description */
|
||||
ArchiveOptions archive;
|
||||
} InstanceConfig;
|
||||
|
||||
extern ConfigOption instance_options[];
|
||||
@@ -357,6 +368,7 @@ typedef struct pgRestoreParams
|
||||
bool restore_as_replica;
|
||||
bool skip_external_dirs;
|
||||
bool skip_block_validation;
|
||||
const char *restore_command;
|
||||
|
||||
/* options for partial restore */
|
||||
PartialRestoreType partial_restore_type;
|
||||
|
||||
+35
-2
@@ -860,11 +860,44 @@ create_recovery_conf(time_t backup_id,
|
||||
if (need_restore_conf)
|
||||
{
|
||||
|
||||
fio_fprintf(fp, "restore_command = '%s archive-get -B %s --instance %s "
|
||||
"--wal-file-path %%p --wal-file-name %%f'\n",
|
||||
char restore_command_guc[16384];
|
||||
|
||||
/* If restore_command is provided, use it */
|
||||
if (params->restore_command)
|
||||
sprintf(restore_command_guc, "%s", params->restore_command);
|
||||
/* construct restore_command */
|
||||
else
|
||||
{
|
||||
/* default cmdline, ok for local restore */
|
||||
sprintf(restore_command_guc, "%s archive-get -B %s --instance %s "
|
||||
"--wal-file-path=%%p --wal-file-name=%%f",
|
||||
PROGRAM_FULL_PATH ? PROGRAM_FULL_PATH : PROGRAM_NAME,
|
||||
backup_path, instance_name);
|
||||
|
||||
/* append --remote-* parameters provided via --archive-* settings */
|
||||
if (instance_config.archive.host)
|
||||
{
|
||||
strcat(restore_command_guc, " --remote-host=");
|
||||
strcat(restore_command_guc, instance_config.archive.host);
|
||||
}
|
||||
|
||||
if (instance_config.archive.port)
|
||||
{
|
||||
strcat(restore_command_guc, " --remote-port=");
|
||||
strcat(restore_command_guc, instance_config.archive.port);
|
||||
}
|
||||
|
||||
if (instance_config.archive.user)
|
||||
{
|
||||
strcat(restore_command_guc, " --remote-user=");
|
||||
strcat(restore_command_guc, instance_config.archive.user);
|
||||
}
|
||||
}
|
||||
|
||||
elog(LOG, "Setting restore_command to '%s'", restore_command_guc);
|
||||
fio_fprintf(fp, "restore_command = '%s'\n",
|
||||
restore_command_guc);
|
||||
|
||||
/*
|
||||
* We've already checked that only one of the four following mutually
|
||||
* exclusive options is specified, so the order of calls is insignificant.
|
||||
|
||||
@@ -1541,6 +1541,79 @@ class ArchiveTest(ProbackupTest, unittest.TestCase):
|
||||
|
||||
self.del_test_dir(module_name, fname)
|
||||
|
||||
# @unittest.expectedFailure
|
||||
# @unittest.skip("skip")
|
||||
def test_archive_options(self):
|
||||
"""
|
||||
check that '--archive-host', '--archive-user', '--archiver-port'
|
||||
and '--restore-command' are working as expected.
|
||||
"""
|
||||
fname = self.id().split('.')[3]
|
||||
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
||||
node = self.make_simple_node(
|
||||
base_dir=os.path.join(module_name, fname, 'node'),
|
||||
set_replication=True,
|
||||
initdb_params=['--data-checksums'])
|
||||
|
||||
self.init_pb(backup_dir)
|
||||
self.add_instance(backup_dir, 'node', node)
|
||||
self.set_archiving(backup_dir, 'node', node, compress=True)
|
||||
|
||||
node.slow_start()
|
||||
|
||||
# FULL
|
||||
self.backup_node(backup_dir, 'node', node)
|
||||
node.pgbench_init(scale=1)
|
||||
|
||||
node.cleanup()
|
||||
|
||||
wal_dir = os.path.join(backup_dir, 'wal', 'node')
|
||||
self.restore_node(
|
||||
backup_dir, 'node', node,
|
||||
options=[
|
||||
'--restore-command="cp {0}/%f %p"'.format(wal_dir),
|
||||
'--archive-host=localhost',
|
||||
'--archive-port=22',
|
||||
'--archive-user={0}'.format(self.user)
|
||||
])
|
||||
|
||||
recovery_conf = os.path.join(node.data_dir, 'recovery.conf')
|
||||
with open(recovery_conf, 'r') as f:
|
||||
recovery_content = f.read()
|
||||
|
||||
self.assertIn(
|
||||
'restore_command = \'"cp {0}/%f %p"\''.format(wal_dir),
|
||||
recovery_content)
|
||||
|
||||
node.cleanup()
|
||||
|
||||
self.restore_node(
|
||||
backup_dir, 'node', node,
|
||||
options=[
|
||||
'--recovery-target-action=promote',
|
||||
'--archive-host=localhost',
|
||||
'--archive-port=22',
|
||||
'--archive-user={0}'.format(self.user)
|
||||
])
|
||||
|
||||
with open(recovery_conf, 'r') as f:
|
||||
recovery_content = f.read()
|
||||
|
||||
self.assertIn(
|
||||
"restore_command = '{0} archive-get -B {1} --instance {2} "
|
||||
"--wal-file-path=%p --wal-file-name=%f --remote-host=localhost "
|
||||
"--remote-port=22 --remote-user={3}'".format(
|
||||
self.probackup_path, backup_dir, 'node', self.user),
|
||||
recovery_content)
|
||||
|
||||
node.slow_start()
|
||||
|
||||
node.safe_psql(
|
||||
'postgres',
|
||||
'select 1')
|
||||
|
||||
self.del_test_dir(module_name, fname)
|
||||
|
||||
# important - switchpoint may be NullOffset LSN and not actually existing in archive to boot.
|
||||
# so write validation code accordingly
|
||||
|
||||
|
||||
Reference in New Issue
Block a user