From 821e6740c5e7dbb3d4dd1c38dba08d9b6fbecf8c Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Wed, 3 May 2017 11:08:17 +0900 Subject: [PATCH] "standby clone": fixes for Barman mode --- repmgr-action-standby.c | 46 ++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index bacec00a..e2417c0a 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -73,9 +73,9 @@ static struct BackupLabel backup_label; /* used by barman mode */ static char local_repmgr_tmp_directory[MAXPGPATH]; +static char datadir_list_filename[MAXLEN]; static char barman_command_buf[MAXLEN] = ""; - static void check_barman_config(void); static void check_source_server(void); static void check_source_server_via_barman(void); @@ -152,14 +152,6 @@ do_standby_clone(void) exit(ERR_BAD_CONFIG); } - /* Sanity-check barman connection and installation */ - if (mode == barman) - { - /* this will exit with ERR_BARMAN if problems found */ - check_barman_config(); - } - - /* * target directory (-D/--pgdata) provided - use that as new data directory * (useful when executing backup on local machine only or creating the backup @@ -170,6 +162,14 @@ do_standby_clone(void) strncpy(local_data_directory, runtime_options.data_dir, MAXPGPATH); } + /* Sanity-check barman connection and installation */ + if (mode == barman) + { + /* this will exit with ERR_BARMAN if problems found */ + check_barman_config(); + } + + /* * Initialise list of conninfo parameters which will later be used * to create the `primary_conninfo` string in recovery.conf . @@ -405,7 +405,7 @@ do_standby_clone(void) * add a hint about using the -F/--force. */ - log_hint(_("After starting the server, you need to register this standby with \"repmgr standby register\"")); + log_hint(_("after starting the server, you need to register this standby with \"repmgr standby register\"")); /* Log the event */ @@ -447,7 +447,8 @@ do_standby_clone(void) if (PQstatus(primary_conn) == CONNECTION_OK) PQfinish(primary_conn); - PQfinish(source_conn); + if (PQstatus(source_conn) == CONNECTION_OK) + PQfinish(source_conn); exit(r); } @@ -455,8 +456,6 @@ do_standby_clone(void) void check_barman_config(void) { - char datadir_list_filename[MAXLEN]; - char command[MAXLEN]; bool command_ok; @@ -481,15 +480,6 @@ check_barman_config(void) exit(ERR_BARMAN); } - /* - * Create the local repmgr subdirectory - */ - - maxlen_snprintf(local_repmgr_tmp_directory, - "%s/repmgr", local_data_directory); - - maxlen_snprintf(datadir_list_filename, - "%s/data.txt", local_repmgr_tmp_directory); if (!create_pg_dir(local_data_directory, runtime_options.force)) { @@ -499,6 +489,17 @@ check_barman_config(void) exit(ERR_BAD_CONFIG); } + + /* + * Create the local repmgr subdirectory + */ + + maxlen_snprintf(local_repmgr_tmp_directory, + "%s/repmgr", local_data_directory); + + maxlen_snprintf(datadir_list_filename, + "%s/data.txt", local_repmgr_tmp_directory); + if (!create_pg_dir(local_repmgr_tmp_directory, runtime_options.force)) { log_error(_("unable to create directory \"%s\""), @@ -1213,7 +1214,6 @@ run_file_backup(void) PQExpBufferData tablespace_map; bool tablespace_map_rewrite = false; - char datadir_list_filename[MAXLEN]; if (mode == barman)