mirror of
https://github.com/EnterpriseDB/repmgr.git
synced 2026-03-22 22:56:29 +00:00
Parse pg_basebackup option --waldir/--xlogdir
This commit is contained in:
32
configfile.c
32
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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user