mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-24 23:56:29 +00:00
copy_remote_files() now only needs to copy individual files
In which case rsync should be an atomic operation
This commit is contained in:
62
repmgr.c
62
repmgr.c
@@ -56,7 +56,7 @@
|
|||||||
static bool create_recovery_file(const char *data_dir);
|
static bool create_recovery_file(const char *data_dir);
|
||||||
static int test_ssh_connection(char *host, char *remote_user);
|
static int test_ssh_connection(char *host, char *remote_user);
|
||||||
static int copy_remote_files(char *host, char *remote_user, char *remote_path,
|
static int copy_remote_files(char *host, char *remote_user, char *remote_path,
|
||||||
char *local_path, bool is_directory);
|
char *local_path);
|
||||||
static int run_basebackup(void);
|
static int run_basebackup(void);
|
||||||
static bool check_parameters_for_action(const int action);
|
static bool check_parameters_for_action(const int action);
|
||||||
static bool create_schema(PGconn *conn);
|
static bool create_schema(PGconn *conn);
|
||||||
@@ -113,7 +113,6 @@ main(int argc, char **argv)
|
|||||||
{"keep-history", required_argument, NULL, 'k'},
|
{"keep-history", required_argument, NULL, 'k'},
|
||||||
{"force", no_argument, NULL, 'F'},
|
{"force", no_argument, NULL, 'F'},
|
||||||
{"wait", no_argument, NULL, 'W'},
|
{"wait", no_argument, NULL, 'W'},
|
||||||
{"ignore-rsync-warning", no_argument, NULL, 'I'},
|
|
||||||
{"min-recovery-apply-delay", required_argument, NULL, 'r'},
|
{"min-recovery-apply-delay", required_argument, NULL, 'r'},
|
||||||
{"verbose", no_argument, NULL, 'v'},
|
{"verbose", no_argument, NULL, 'v'},
|
||||||
{"initdb-no-pwprompt", no_argument, NULL, 1},
|
{"initdb-no-pwprompt", no_argument, NULL, 1},
|
||||||
@@ -1109,8 +1108,7 @@ do_standby_clone(void)
|
|||||||
{
|
{
|
||||||
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,
|
master_config_file, local_config_file);
|
||||||
false);
|
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
{
|
{
|
||||||
log_warning(_("standby clone: failed copying master config file '%s'\n"),
|
log_warning(_("standby clone: failed copying master config file '%s'\n"),
|
||||||
@@ -1123,8 +1121,7 @@ do_standby_clone(void)
|
|||||||
{
|
{
|
||||||
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,
|
master_hba_file, local_hba_file);
|
||||||
false);
|
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
{
|
{
|
||||||
log_warning(_("standby clone: failed copying master hba file '%s'\n"),
|
log_warning(_("standby clone: failed copying master hba file '%s'\n"),
|
||||||
@@ -1137,8 +1134,7 @@ do_standby_clone(void)
|
|||||||
{
|
{
|
||||||
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,
|
master_ident_file, local_ident_file);
|
||||||
false);
|
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
{
|
{
|
||||||
log_warning(_("standby clone: failed copying master ident file '%s'\n"),
|
log_warning(_("standby clone: failed copying master ident file '%s'\n"),
|
||||||
@@ -1155,7 +1151,7 @@ do_standby_clone(void)
|
|||||||
|
|
||||||
stop_backup:
|
stop_backup:
|
||||||
|
|
||||||
/* If the rsync failed then exit */
|
/* If the backup failed then exit */
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
{
|
{
|
||||||
log_err(_("Unable to take a base backup of the primary server\n"));
|
log_err(_("Unable to take a base backup of the primary server\n"));
|
||||||
@@ -1630,8 +1626,7 @@ do_witness_create(void)
|
|||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
|
||||||
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, runtime_options.dest_dir,
|
master_hba_file, runtime_options.dest_dir);
|
||||||
false);
|
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
{
|
{
|
||||||
log_err(_("Can't rsync the pg_hba.conf file from master\n"));
|
log_err(_("Can't rsync the pg_hba.conf file from master\n"));
|
||||||
@@ -1749,7 +1744,6 @@ help(const char *progname)
|
|||||||
" (default: postgres)\n"));
|
" (default: postgres)\n"));
|
||||||
printf(_(" -w, --wal-keep-segments=VALUE minimum value for the GUC\n" \
|
printf(_(" -w, --wal-keep-segments=VALUE minimum value for the GUC\n" \
|
||||||
" wal_keep_segments (default: 5000)\n"));
|
" wal_keep_segments (default: 5000)\n"));
|
||||||
printf(_(" -I, --ignore-rsync-warning ignore rsync partial transfer warning\n"));
|
|
||||||
printf(_(" -k, --keep-history=VALUE keeps indicated number of days of\n" \
|
printf(_(" -k, --keep-history=VALUE keeps indicated number of days of\n" \
|
||||||
" history\n"));
|
" history\n"));
|
||||||
printf(_(" -F, --force force potentially dangerous operations\n" \
|
printf(_(" -F, --force force potentially dangerous operations\n" \
|
||||||
@@ -1868,7 +1862,7 @@ test_ssh_connection(char *host, char *remote_user)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
copy_remote_files(char *host, char *remote_user, char *remote_path,
|
copy_remote_files(char *host, char *remote_user, char *remote_path,
|
||||||
char *local_path, bool is_directory)
|
char *local_path)
|
||||||
{
|
{
|
||||||
char script[MAXLEN];
|
char script[MAXLEN];
|
||||||
char rsync_flags[MAXLEN];
|
char rsync_flags[MAXLEN];
|
||||||
@@ -1894,50 +1888,16 @@ copy_remote_files(char *host, char *remote_user, char *remote_path,
|
|||||||
maxlen_snprintf(host_string, "%s@%s", remote_user, host);
|
maxlen_snprintf(host_string, "%s@%s", remote_user, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_directory)
|
|
||||||
{
|
maxlen_snprintf(script, "rsync %s %s:%s %s",
|
||||||
strcat(rsync_flags,
|
rsync_flags, host_string, remote_path, local_path);
|
||||||
" --exclude=pg_xlog/* --exclude=pg_log/* --exclude=pg_control --exclude=*.pid");
|
|
||||||
maxlen_snprintf(script, "rsync %s %s:%s/* %s",
|
|
||||||
rsync_flags, host_string, remote_path, local_path);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
maxlen_snprintf(script, "rsync %s %s:%s %s",
|
|
||||||
rsync_flags, host_string, remote_path, local_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_info(_("rsync command line: '%s'\n"), script);
|
log_info(_("rsync command line: '%s'\n"), script);
|
||||||
|
|
||||||
r = system(script);
|
r = system(script);
|
||||||
|
|
||||||
/*
|
|
||||||
* If we are transfering a directory (data directory, tablespace
|
|
||||||
* directories) then we can ignore some rsync warnings. If we get some of
|
|
||||||
* those errors, we treat them as 0 only if passed the
|
|
||||||
* --ignore-rsync-warning command-line option.
|
|
||||||
*
|
|
||||||
* List of ignorable rsync errors: 24 Partial transfer due to vanished
|
|
||||||
* source files
|
|
||||||
*/
|
|
||||||
if ((WEXITSTATUS(r) == 24) && is_directory)
|
|
||||||
{
|
|
||||||
if (runtime_options.ignore_rsync_warn)
|
|
||||||
{
|
|
||||||
r = 0;
|
|
||||||
log_info(_("rsync partial transfer warning ignored\n"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
log_warning(_("rsync completed with return code 24: "
|
|
||||||
"\"Partial transfer due to vanished source files\".\n"
|
|
||||||
"This can happen because of normal operation "
|
|
||||||
"on the master server, but it may indicate an "
|
|
||||||
"unexpected change during cloning. If you are certain "
|
|
||||||
"no changes were made to the master, try cloning "
|
|
||||||
"again using \"repmgr --force --ignore-rsync-warning\"."));
|
|
||||||
}
|
|
||||||
if (r != 0)
|
if (r != 0)
|
||||||
log_err(_("Can't rsync from remote file or directory (%s:%s)\n"),
|
log_err(_("Can't rsync from remote file (%s:%s)\n"),
|
||||||
host_string, remote_path);
|
host_string, remote_path);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
Reference in New Issue
Block a user