From b3b9281253563cf4bc80a495c8401e7c15a5c958 Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 6 Oct 2020 18:00:11 +0900 Subject: [PATCH] Parse pg_basebackup option --waldir/--xlogdir --- configfile.c | 32 +++++++++++++++++++++++++------- configfile.h | 3 ++- repmgr-action-standby.c | 4 ++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/configfile.c b/configfile.c index 62439a57..08cb2e0b 100644 --- a/configfile.c +++ b/configfile.c @@ -2056,17 +2056,12 @@ bool parse_pg_basebackup_options(const char *pg_basebackup_options, t_basebackup_options *backup_options, int server_version_num, ItemList *error_list) { bool backup_options_ok = true; - int c = 0, argc_item = 0; - char **argv_array = NULL; - int optindex = 0; - struct option *long_options = NULL; - /* * We're only interested in these options. */ @@ -2075,7 +2070,8 @@ parse_pg_basebackup_options(const char *pg_basebackup_options, t_basebackup_opti { {"slot", required_argument, NULL, 'S'}, {"wal-method", required_argument, NULL, 'X'}, - {"no-slot", no_argument, NULL, 1}, + {"waldir", required_argument, NULL, 1}, + {"no-slot", no_argument, NULL, 2}, {NULL, 0, NULL, 0} }; @@ -2086,6 +2082,7 @@ parse_pg_basebackup_options(const char *pg_basebackup_options, t_basebackup_opti { {"slot", required_argument, NULL, 'S'}, {"xlog-method", required_argument, NULL, 'X'}, + {"xlogdir", required_argument, NULL, 1}, {NULL, 0, NULL, 0} }; @@ -2119,10 +2116,13 @@ parse_pg_basebackup_options(const char *pg_basebackup_options, t_basebackup_opti strncpy(backup_options->wal_method, optarg, MAXLEN); break; case 1: + strncpy(backup_options->waldir, optarg, MAXPGPATH); + break; + case 2: backup_options->no_slot = true; break; case '?': - if (server_version_num >= 100000 && optopt == 1) + if (server_version_num >= 100000 && optopt == 2) { if (error_list != NULL) { @@ -2143,6 +2143,24 @@ parse_pg_basebackup_options(const char *pg_basebackup_options, t_basebackup_opti backup_options_ok = false; } + /* + * If --waldir/--xlogdir provided, check it's an absolute path. + */ + if (backup_options->waldir[0] != '\0') + { + canonicalize_path(backup_options->waldir); + if (!is_absolute_path(backup_options->waldir)) + { + if (error_list != NULL) + { + item_list_append_format(error_list, + "--%s must be provided with an absolute path", + server_version_num >= 100000 ? "waldir" : "xlogdir"); + } + backup_options_ok = false; + } + } + free_parsed_argv(&argv_array); return backup_options_ok; diff --git a/configfile.h b/configfile.h index da2ae106..5769fb63 100644 --- a/configfile.h +++ b/configfile.h @@ -262,10 +262,11 @@ typedef struct { char slot[MAXLEN]; char wal_method[MAXLEN]; + char waldir[MAXPGPATH]; bool no_slot; /* from PostgreSQL 10 */ } t_basebackup_options; -#define T_BASEBACKUP_OPTIONS_INITIALIZER { "", "", false } +#define T_BASEBACKUP_OPTIONS_INITIALIZER { "", "", "", false } typedef enum diff --git a/repmgr-action-standby.c b/repmgr-action-standby.c index 2828145f..19bef47e 100644 --- a/repmgr-action-standby.c +++ b/repmgr-action-standby.c @@ -7203,6 +7203,10 @@ run_file_backup(t_node_info *local_node_record) if (vers[i] < 0 && source_server_version_num >= abs(vers[i])) continue; + /* + * If --waldir/--xlogdir specified in "pg_basebackup_options", + * create a symlink rather than make a directory. + */ maxlen_snprintf(filename, "%s/%s", local_data_directory, dirs[i]); if (mkdir(filename, S_IRWXU) != 0 && errno != EEXIST) {