Add repmgr.conf setting 'barman_config'

Enables provision of a non-default Barman configuration file.
This commit is contained in:
Ian Barwick
2016-08-18 15:06:06 +09:00
parent fe469fe188
commit 5baec14a1e
4 changed files with 42 additions and 8 deletions

View File

@@ -585,6 +585,11 @@ Then we check that `repmgr.conf` includes the following lines:
barman_server=barmansrv barman_server=barmansrv
restore_command=/usr/local/bin/barman-wal-restore.py barmansrv test %f %p restore_command=/usr/local/bin/barman-wal-restore.py barmansrv test %f %p
To use a non-default Barman configuration file on the Barman server,
specify this in `repmgr.conf` with `barman_config`:
barman_config=/path/to/barman.conf
Now we can clone a standby using the Barman server: Now we can clone a standby using the Barman server:
$ repmgr -h node1 -D 9.5/main -f /etc/repmgr.conf standby clone $ repmgr -h node1 -D 9.5/main -f /etc/repmgr.conf standby clone
@@ -595,6 +600,8 @@ Now we can clone a standby using the Barman server:
[2016-06-12 20:08:36] [HINT] for example : pg_ctl -D 9.5/data start [2016-06-12 20:08:36] [HINT] for example : pg_ctl -D 9.5/data start
[2016-06-12 20:08:36] [HINT] After starting the server, you need to register this standby with "repmgr standby register" [2016-06-12 20:08:36] [HINT] After starting the server, you need to register this standby with "repmgr standby register"
Advanced options for cloning a standby Advanced options for cloning a standby
-------------------------------------- --------------------------------------

View File

@@ -216,6 +216,7 @@ parse_config(t_configuration_options *options)
options->use_replication_slots = 0; options->use_replication_slots = 0;
memset(options->conninfo, 0, sizeof(options->conninfo)); memset(options->conninfo, 0, sizeof(options->conninfo));
memset(options->barman_server, 0, sizeof(options->barman_server)); memset(options->barman_server, 0, sizeof(options->barman_server));
memset(options->barman_config, 0, sizeof(options->barman_config));
options->failover = MANUAL_FAILOVER; options->failover = MANUAL_FAILOVER;
options->priority = DEFAULT_PRIORITY; options->priority = DEFAULT_PRIORITY;
memset(options->node_name, 0, sizeof(options->node_name)); memset(options->node_name, 0, sizeof(options->node_name));
@@ -313,6 +314,8 @@ parse_config(t_configuration_options *options)
strncpy(options->conninfo, value, MAXLEN); strncpy(options->conninfo, value, MAXLEN);
else if (strcmp(name, "barman_server") == 0) else if (strcmp(name, "barman_server") == 0)
strncpy(options->barman_server, value, MAXLEN); strncpy(options->barman_server, value, MAXLEN);
else if (strcmp(name, "barman_config") == 0)
strncpy(options->barman_config, value, MAXLEN);
else if (strcmp(name, "rsync_options") == 0) else if (strcmp(name, "rsync_options") == 0)
strncpy(options->rsync_options, value, QUERY_STR_LEN); strncpy(options->rsync_options, value, QUERY_STR_LEN);
else if (strcmp(name, "ssh_options") == 0) else if (strcmp(name, "ssh_options") == 0)

View File

@@ -59,6 +59,7 @@ typedef struct
int upstream_node; int upstream_node;
char conninfo[MAXLEN]; char conninfo[MAXLEN];
char barman_server[MAXLEN]; char barman_server[MAXLEN];
char barman_config[MAXLEN];
int failover; int failover;
int priority; int priority;
char node_name[MAXLEN]; char node_name[MAXLEN];
@@ -92,7 +93,7 @@ typedef struct
* The following will initialize the structure with a minimal set of options; * The following will initialize the structure with a minimal set of options;
* actual defaults are set in parse_config() before parsing the configuration file * actual defaults are set in parse_config() before parsing the configuration file
*/ */
#define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, NO_UPSTREAM_NODE, "", "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", "", "", "", -1, -1, -1, "", "", "", "", "", 0, 0, 0, 0, "", { NULL, NULL }, {NULL, NULL} } #define T_CONFIGURATION_OPTIONS_INITIALIZER { "", -1, NO_UPSTREAM_NODE, "", "", "", MANUAL_FAILOVER, -1, "", "", "", "", "", "", "", "", "", "", -1, -1, -1, "", "", "", "", "", 0, 0, 0, 0, "", { NULL, NULL }, {NULL, NULL} }
typedef struct ItemListCell typedef struct ItemListCell
{ {

View File

@@ -111,6 +111,7 @@ static char *string_skip_prefix(const char *prefix, char *string);
static char *string_remove_trailing_newlines(char *string); static char *string_remove_trailing_newlines(char *string);
static char *make_pg_path(char *file); static char *make_pg_path(char *file);
static char *make_barman_ssh_command(void);
static void do_master_register(void); static void do_master_register(void);
@@ -137,6 +138,7 @@ static void print_error_list(ItemList *error_list, int log_level);
static bool remote_command(const char *host, const char *user, const char *command, PQExpBufferData *outputbuf); static bool remote_command(const char *host, const char *user, const char *command, PQExpBufferData *outputbuf);
static bool local_command(const char *command, PQExpBufferData *outputbuf); static bool local_command(const char *command, PQExpBufferData *outputbuf);
static void format_db_cli_params(const char *conninfo, char *output); static void format_db_cli_params(const char *conninfo, char *output);
static bool copy_file(const char *old_filename, const char *new_filename); static bool copy_file(const char *old_filename, const char *new_filename);
@@ -172,6 +174,7 @@ static char pg_bindir[MAXLEN] = "";
static char repmgr_slot_name[MAXLEN] = ""; static char repmgr_slot_name[MAXLEN] = "";
static char *repmgr_slot_name_ptr = NULL; static char *repmgr_slot_name_ptr = NULL;
static char path_buf[MAXLEN] = ""; static char path_buf[MAXLEN] = "";
static char barman_command_buf[MAXLEN] = "";
/* Collate command line errors and warnings here for friendlier reporting */ /* Collate command line errors and warnings here for friendlier reporting */
ItemList cli_errors = { NULL, NULL }; ItemList cli_errors = { NULL, NULL };
@@ -2054,8 +2057,8 @@ do_standby_clone(void)
* Check that there is at least one valid backup * Check that there is at least one valid backup
*/ */
maxlen_snprintf(command, "ssh %s barman show-backup %s latest > /dev/null", maxlen_snprintf(command, "%s show-backup %s latest > /dev/null",
options.barman_server, make_barman_ssh_command(),
options.cluster_name); options.cluster_name);
command_ok = local_command(command, NULL); command_ok = local_command(command, NULL);
if (command_ok == false) if (command_ok == false)
@@ -2070,8 +2073,8 @@ do_standby_clone(void)
* Locate Barman's backup directory * Locate Barman's backup directory
*/ */
maxlen_snprintf(command, "ssh %s barman show-server %s | grep 'backup_directory'", maxlen_snprintf(command, "%s show-server %s | grep 'backup_directory'",
options.barman_server, make_barman_ssh_command(),
options.cluster_name); options.cluster_name);
initPQExpBuffer(&command_output); initPQExpBuffer(&command_output);
@@ -2126,8 +2129,8 @@ do_standby_clone(void)
char output[MAXLEN]; char output[MAXLEN];
int n; int n;
maxlen_snprintf(command, "ssh %s barman list-files --target=data %s latest", maxlen_snprintf(command, "%s list-files --target=data %s latest",
options.barman_server, make_barman_ssh_command(),
options.cluster_name); options.cluster_name);
fi = popen(command, "r"); fi = popen(command, "r");
@@ -6437,6 +6440,26 @@ make_pg_path(char *file)
} }
static char *
make_barman_ssh_command(void)
{
static char config_opt[MAXLEN] = "";
if(strlen(options.barman_config))
maxlen_snprintf(config_opt,
" --config=%s",
options.barman_config);
maxlen_snprintf(barman_command_buf,
"ssh %s barman%s",
options.barman_server,
config_opt);
return barman_command_buf;
}
static void static void
exit_with_errors(void) exit_with_errors(void)
{ {