Prevent a test SSH connection being made when not needed

When using the default pg_basebackup method to clone a standby
together with the `--ignore-external-config-files` option, there's
no need to test for a working SSH connection - which may not
be desirable in many use-cases anyway.

Per issue #64 in GitHub.
This commit is contained in:
Ian Barwick
2015-04-10 15:05:19 +09:00
parent 734ae1825e
commit 9e5e843a4f

View File

@@ -925,7 +925,7 @@ do_standby_clone(void)
int i; int i;
bool pg_start_backup_executed = false; bool pg_start_backup_executed = false;
bool target_directory_provided = false; bool target_directory_provided = false;
bool config_file_copy_required = false; bool external_config_file_copy_required = false;
char master_data_directory[MAXFILENAME]; char master_data_directory[MAXFILENAME];
char local_data_directory[MAXFILENAME]; char local_data_directory[MAXFILENAME];
@@ -1101,7 +1101,7 @@ do_standby_clone(void)
if(strcmp(PQgetvalue(res, i, 2), "f") == 0) if(strcmp(PQgetvalue(res, i, 2), "f") == 0)
{ {
config_file_outside_pgdata = true; config_file_outside_pgdata = true;
config_file_copy_required = true; external_config_file_copy_required = true;
strncpy(master_config_file, PQgetvalue(res, i, 1), MAXFILENAME); strncpy(master_config_file, PQgetvalue(res, i, 1), MAXFILENAME);
} }
} }
@@ -1110,7 +1110,7 @@ do_standby_clone(void)
if(strcmp(PQgetvalue(res, i, 2), "f") == 0) if(strcmp(PQgetvalue(res, i, 2), "f") == 0)
{ {
hba_file_outside_pgdata = true; hba_file_outside_pgdata = true;
config_file_copy_required = true; external_config_file_copy_required = true;
strncpy(master_hba_file, PQgetvalue(res, i, 1), MAXFILENAME); strncpy(master_hba_file, PQgetvalue(res, i, 1), MAXFILENAME);
} }
} }
@@ -1119,13 +1119,14 @@ do_standby_clone(void)
if(strcmp(PQgetvalue(res, i, 2), "f") == 0) if(strcmp(PQgetvalue(res, i, 2), "f") == 0)
{ {
ident_file_outside_pgdata = true; ident_file_outside_pgdata = true;
config_file_copy_required = true; external_config_file_copy_required = true;
strncpy(master_ident_file, PQgetvalue(res, i, 1), MAXFILENAME); strncpy(master_ident_file, PQgetvalue(res, i, 1), MAXFILENAME);
} }
} }
else else
log_warning(_("unknown parameter: %s\n"), PQgetvalue(res, i, 0)); log_warning(_("unknown parameter: %s\n"), PQgetvalue(res, i, 0));
} }
PQclear(res); PQclear(res);
/* /*
@@ -1316,12 +1317,6 @@ do_standby_clone(void)
} }
PQclear(res); PQclear(res);
/*
* With rsync we'll need to explicitly copy configuration files in any
* case
*/
config_file_copy_required = true;
} }
else else
{ {
@@ -1335,18 +1330,18 @@ do_standby_clone(void)
} }
/* /*
* If configuration files were not in the data directory, we need to copy * If configuration files were not inside the data directory, we;ll need to
* them via SSH * copy them via SSH (unless `--ignore-external-config-files` was provided)
* *
* TODO: add option to place these files in the same location on the * TODO: add option to place these files in the same location on the
* standby server as on the primary? * standby server as on the primary?
*/ */
if(config_file_copy_required == true) if(external_config_file_copy_required && !runtime_options.ignore_external_config_files)
{ {
log_notice(_("copying configuration files from master\n")); log_notice(_("copying configuration files from master\n"));
r = test_ssh_connection(runtime_options.host, runtime_options.remote_user); r = test_ssh_connection(runtime_options.host, runtime_options.remote_user);
if (r != 0 && !(runtime_options.ignore_external_config_files && config_file_outside_pgdata)) if (r != 0)
{ {
log_err(_("aborting, remote host %s is not reachable.\n"), log_err(_("aborting, remote host %s is not reachable.\n"),
runtime_options.host); runtime_options.host);
@@ -1354,62 +1349,42 @@ do_standby_clone(void)
goto stop_backup; goto stop_backup;
} }
if(strlen(master_config_file)) if(config_file_outside_pgdata)
{
if(runtime_options.ignore_external_config_files && config_file_outside_pgdata)
{
log_notice(_("standby clone: not copying master config file '%s'\n"), master_config_file);
}
else
{ {
log_info(_("standby clone: master config file '%s'\n"), master_config_file); log_info(_("standby clone: master config file '%s'\n"), master_config_file);
r = copy_remote_files(runtime_options.host, runtime_options.remote_user, r = copy_remote_files(runtime_options.host, runtime_options.remote_user,
master_config_file, local_config_file, false, server_version_num); master_config_file, local_config_file, false, server_version_num);
if (r != 0) if (r != 0)
{ {
log_warning(_("standby clone: failed copying master config file '%s'\n"), log_err(_("standby clone: failed copying master config file '%s'\n"),
master_config_file); master_config_file);
retval = ERR_BAD_SSH; retval = ERR_BAD_SSH;
goto stop_backup; goto stop_backup;
} }
} }
}
if(strlen(master_hba_file)) if(hba_file_outside_pgdata)
{
if(runtime_options.ignore_external_config_files && hba_file_outside_pgdata)
{
log_notice(_("standby clone: not copying master config file '%s'\n"), master_hba_file);
}
else
{ {
log_info(_("standby clone: master hba file '%s'\n"), master_hba_file); log_info(_("standby clone: master hba file '%s'\n"), master_hba_file);
r = copy_remote_files(runtime_options.host, runtime_options.remote_user, r = copy_remote_files(runtime_options.host, runtime_options.remote_user,
master_hba_file, local_hba_file, false, server_version_num); master_hba_file, local_hba_file, false, server_version_num);
if (r != 0) if (r != 0)
{ {
log_warning(_("standby clone: failed copying master hba file '%s'\n"), log_err(_("standby clone: failed copying master hba file '%s'\n"),
master_hba_file); master_hba_file);
retval = ERR_BAD_SSH; retval = ERR_BAD_SSH;
goto stop_backup; goto stop_backup;
} }
} }
}
if(strlen(master_ident_file)) if(ident_file_outside_pgdata)
{
if(runtime_options.ignore_external_config_files && ident_file_outside_pgdata)
{
log_notice(_("standby clone: not copying master config file '%s'\n"), master_ident_file);
}
else
{ {
log_info(_("standby clone: master ident file '%s'\n"), master_ident_file); log_info(_("standby clone: master ident file '%s'\n"), master_ident_file);
r = copy_remote_files(runtime_options.host, runtime_options.remote_user, r = copy_remote_files(runtime_options.host, runtime_options.remote_user,
master_ident_file, local_ident_file, false, server_version_num); master_ident_file, local_ident_file, false, server_version_num);
if (r != 0) if (r != 0)
{ {
log_warning(_("standby clone: failed copying master ident file '%s'\n"), log_err(_("standby clone: failed copying master ident file '%s'\n"),
master_ident_file); master_ident_file);
retval = ERR_BAD_SSH; retval = ERR_BAD_SSH;
goto stop_backup; goto stop_backup;
@@ -1450,7 +1425,6 @@ do_standby_clone(void)
goto stop_backup; goto stop_backup;
} }
} }
}
stop_backup: stop_backup:
@@ -2440,7 +2414,7 @@ copy_remote_files(char *host, char *remote_user, char *remote_path,
*/ */
if (is_directory) if (is_directory)
{ {
/* Files we don't want */ /* Files which we don't want */
appendPQExpBuffer(&rsync_flags, "%s", appendPQExpBuffer(&rsync_flags, "%s",
" --exclude=postmaster.pid --exclude=postmaster.opts --exclude=global/pg_control"); " --exclude=postmaster.pid --exclude=postmaster.opts --exclude=global/pg_control");
@@ -2454,11 +2428,11 @@ copy_remote_files(char *host, char *remote_user, char *remote_path,
" --exclude=postgresql.auto.conf.tmp"); " --exclude=postgresql.auto.conf.tmp");
} }
/* Temporary files we don't want, if they exist */ /* Temporary files which we don't want, if they exist */
appendPQExpBuffer(&rsync_flags, " --exclude=%s*", appendPQExpBuffer(&rsync_flags, " --exclude=%s*",
PG_TEMP_FILE_PREFIX); PG_TEMP_FILE_PREFIX);
/* Directories we don't want */ /* Directories which we don't want */
appendPQExpBuffer(&rsync_flags, "%s", appendPQExpBuffer(&rsync_flags, "%s",
" --exclude=pg_xlog/* --exclude=pg_log/* --exclude=pg_stat_tmp/*"); " --exclude=pg_xlog/* --exclude=pg_log/* --exclude=pg_stat_tmp/*");