mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-02-03 14:01:57 +02:00
Merge branch 'issue_171'
This commit is contained in:
commit
7b342e3946
@ -1634,13 +1634,14 @@ pg_probackup restore -B <replaceable>backup_dir</replaceable> --instance <replac
|
||||
<para>
|
||||
If you restore <link linkend="pbk-archive-mode">ARCHIVE</link> backups,
|
||||
perform <link linkend="pbk-performing-point-in-time-pitr-recovery">PITR</link>,
|
||||
or specify the <literal>--restore-as-replica</literal> option with the
|
||||
or specify the <literal>--restore-as-replica</literal> flag with the
|
||||
<literal>restore</literal> command to set up a standby server,
|
||||
<application>pg_probackup</application> creates a recovery configuration
|
||||
file once all data files are copied into the target directory. This file
|
||||
includes the minimal settings required for recovery, except for the password in the
|
||||
<ulink url="https://postgrespro.com/docs/postgresql/current/runtime-config-replication.html#GUC-PRIMARY-CONNINFO">primary_conninfo</ulink>
|
||||
parameter; you have to add the password manually, if required.
|
||||
parameter; you have to add the password manually or use
|
||||
the <literal>--primary-conninfo</literal> option, if required.
|
||||
For <productname>PostgreSQL</productname> 11 or lower,
|
||||
recovery settings are written into the <filename>recovery.conf</filename>
|
||||
file. Starting from <productname>PostgreSQL</productname> 12,
|
||||
@ -3605,8 +3606,11 @@ pg_probackup restore -B <replaceable>backup_dir</replaceable> --instance <replac
|
||||
[--help] [-D <replaceable>data_dir</replaceable>] [-i <replaceable>backup_id</replaceable>]
|
||||
[-j <replaceable>num_threads</replaceable>] [--progress]
|
||||
[-T <replaceable>OLDDIR</replaceable>=<replaceable>NEWDIR</replaceable>] [--external-mapping=<replaceable>OLDDIR</replaceable>=<replaceable>NEWDIR</replaceable>] [--skip-external-dirs]
|
||||
[-R | --restore-as-replica] [--no-validate] [--skip-block-validation] [--force]
|
||||
[--restore-command=<replaceable>cmdline</replaceable>] [--no-sync]
|
||||
[-R | --restore-as-replica] [--no-validate] [--skip-block-validation]
|
||||
[--force] [--no-sync]
|
||||
[--restore-command=<replaceable>cmdline</replaceable>]
|
||||
[--restore-command=<replaceable>cmdline</replaceable>]
|
||||
[--primary-conninfo=<replaceable>primary_conninfo</replaceable>]
|
||||
[<replaceable>recovery_target_options</replaceable>] [<replaceable>logging_options</replaceable>] [<replaceable>remote_options</replaceable>]
|
||||
[<replaceable>partial_restore_options</replaceable>] [<replaceable>remote_wal_archive_options</replaceable>]
|
||||
</programlisting>
|
||||
@ -3644,6 +3648,21 @@ pg_probackup restore -B <replaceable>backup_dir</replaceable> --instance <replac
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--primary-conninfo=<replaceable>primary_conninfo</replaceable></option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Sets the
|
||||
<ulink url="https://postgrespro.com/docs/postgresql/current/runtime-config-replication.html#GUC-PRIMARY-CONNINFO">primary_conninfo</ulink>
|
||||
parameter to the specified value.
|
||||
This option will be ignored unless the <option>-R</option> flag if specified.
|
||||
</para>
|
||||
<para>
|
||||
Example: <literal>--primary-conninfo='host=192.168.1.50 port=5432 user=foo password=foopass'</literal>
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>-T <replaceable>OLDDIR</replaceable>=<replaceable>NEWDIR</replaceable></option></term>
|
||||
<term><option>--tablespace-mapping=<replaceable>OLDDIR</replaceable>=<replaceable>NEWDIR</replaceable></option></term>
|
||||
|
@ -90,6 +90,8 @@ static bool target_immediate;
|
||||
static char *target_name = NULL;
|
||||
static char *target_action = NULL;
|
||||
|
||||
static char *primary_conninfo = NULL;
|
||||
|
||||
static pgRecoveryTarget *recovery_target_options = NULL;
|
||||
static pgRestoreParams *restore_params = NULL;
|
||||
|
||||
@ -192,6 +194,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, "primary-conninfo", &primary_conninfo, SOURCE_CMD_STRICT },
|
||||
/* checkdb options */
|
||||
{ 'b', 195, "amcheck", &need_amcheck, SOURCE_CMD_STRICT },
|
||||
{ 'b', 196, "heapallindexed", &heapallindexed, SOURCE_CMD_STRICT },
|
||||
@ -686,6 +689,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->primary_conninfo = primary_conninfo;
|
||||
|
||||
/* handle partial restore parameters */
|
||||
if (datname_exclude_list && datname_include_list)
|
||||
|
@ -423,6 +423,7 @@ typedef struct pgRestoreParams
|
||||
/* options for partial restore */
|
||||
PartialRestoreType partial_restore_type;
|
||||
parray *partial_db_list;
|
||||
const char *primary_conninfo;
|
||||
} pgRestoreParams;
|
||||
|
||||
/* Options needed for set-backup command */
|
||||
|
@ -1059,7 +1059,9 @@ create_recovery_conf(time_t backup_id,
|
||||
fio_fprintf(fp, "standby_mode = 'on'\n");
|
||||
#endif
|
||||
|
||||
if (backup->primary_conninfo)
|
||||
if (params->primary_conninfo)
|
||||
fio_fprintf(fp, "primary_conninfo = '%s'\n", params->primary_conninfo);
|
||||
else if (backup->primary_conninfo)
|
||||
fio_fprintf(fp, "primary_conninfo = '%s'\n", backup->primary_conninfo);
|
||||
}
|
||||
|
||||
|
@ -3376,4 +3376,54 @@ class RestoreTest(ProbackupTest, unittest.TestCase):
|
||||
self.assertEqual('2', timeline_id)
|
||||
|
||||
# Clean after yourself
|
||||
self.del_test_dir(module_name, fname)
|
||||
self.del_test_dir(module_name, fname)
|
||||
|
||||
# @unittest.skip("skip")
|
||||
def test_restore_primary_conninfo(self):
|
||||
"""
|
||||
"""
|
||||
fname = self.id().split('.')[3]
|
||||
node = self.make_simple_node(
|
||||
base_dir=os.path.join(module_name, fname, 'node'),
|
||||
set_replication=True,
|
||||
initdb_params=['--data-checksums'])
|
||||
|
||||
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
||||
self.init_pb(backup_dir)
|
||||
self.add_instance(backup_dir, 'node', node)
|
||||
node.slow_start()
|
||||
|
||||
# Take FULL
|
||||
self.backup_node(backup_dir, 'node', node, options=['--stream'])
|
||||
|
||||
node.pgbench_init(scale=1)
|
||||
|
||||
#primary_conninfo = 'host=192.168.1.50 port=5432 user=foo password=foopass'
|
||||
|
||||
replica = self.make_simple_node(
|
||||
base_dir=os.path.join(module_name, fname, 'replica'))
|
||||
replica.cleanup()
|
||||
str_conninfo='host=192.168.1.50 port=5432 user=foo password=foopass'
|
||||
|
||||
self.restore_node(
|
||||
backup_dir, 'node', replica,
|
||||
options=['-R', '--primary-conninfo={0}'.format(str_conninfo)])
|
||||
|
||||
if self.get_version(node) >= self.version_to_num('12.0'):
|
||||
standby_signal = os.path.join(replica.data_dir, 'standby.signal')
|
||||
self.assertTrue(
|
||||
os.path.isfile(standby_signal),
|
||||
"File '{0}' do not exists".format(standby_signal))
|
||||
|
||||
if self.get_version(node) >= self.version_to_num('12.0'):
|
||||
recovery_conf = os.path.join(replica.data_dir, 'probackup_recovery.conf')
|
||||
else:
|
||||
recovery_conf = os.path.join(replica.data_dir, 'recovery.conf')
|
||||
|
||||
with open(os.path.join(replica.data_dir, recovery_conf), 'r') as f:
|
||||
recovery_conf_content = f.read()
|
||||
|
||||
self.assertIn(str_conninfo, recovery_conf_content)
|
||||
|
||||
# Clean after yourself
|
||||
self.del_test_dir(module_name, fname)
|
||||
|
Loading…
x
Reference in New Issue
Block a user