Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 544de12

Browse files
committed
[Issue #102] now it is possible to set restore_command via set-config
1 parent 56726b2 commit 544de12

File tree

7 files changed

+156
-46
lines changed

7 files changed

+156
-46
lines changed

src/backup.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,8 @@ do_backup(time_t start_time, bool no_validate)
702702
current.compress_level = instance_config.compress_level;
703703

704704
/* Save list of external directories */
705-
if (instance_config.external_dir_str &&
706-
pg_strcasecmp(instance_config.external_dir_str, "none") != 0)
707-
{
705+
if (instance_config.external_dir_str)
708706
current.external_dir_str = instance_config.external_dir_str;
709-
}
710707

711708
elog(INFO, "Backup start, pg_probackup version: %s, instance: %s, backup ID: %s, backup mode: %s, "
712709
"wal mode: %s, remote: %s, compress-algorithm: %s, compress-level: %i",

src/configure.c

Lines changed: 69 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -137,97 +137,102 @@ ConfigOption instance_options[] =
137137
&instance_config.archive.user, SOURCE_CMD, 0,
138138
OPTION_ARCHIVE_GROUP, 0, option_get_value
139139
},
140+
{
141+
's', 211, "restore-command",
142+
&instance_config.restore_command, SOURCE_CMD, SOURCE_DEFAULT,
143+
OPTION_ARCHIVE_GROUP, 0, option_get_value
144+
},
140145
/* Logging options */
141146
{
142-
'f', 211, "log-level-console",
147+
'f', 212, "log-level-console",
143148
assign_log_level_console, SOURCE_CMD, 0,
144149
OPTION_LOG_GROUP, 0, get_log_level_console
145150
},
146151
{
147-
'f', 212, "log-level-file",
152+
'f', 213, "log-level-file",
148153
assign_log_level_file, SOURCE_CMD, 0,
149154
OPTION_LOG_GROUP, 0, get_log_level_file
150155
},
151156
{
152-
's', 213, "log-filename",
157+
's', 214, "log-filename",
153158
&instance_config.logger.log_filename, SOURCE_CMD, 0,
154159
OPTION_LOG_GROUP, 0, option_get_value
155160
},
156161
{
157-
's', 214, "error-log-filename",
162+
's', 215, "error-log-filename",
158163
&instance_config.logger.error_log_filename, SOURCE_CMD, 0,
159164
OPTION_LOG_GROUP, 0, option_get_value
160165
},
161166
{
162-
's', 215, "log-directory",
167+
's', 216, "log-directory",
163168
&instance_config.logger.log_directory, SOURCE_CMD, 0,
164169
OPTION_LOG_GROUP, 0, option_get_value
165170
},
166171
{
167-
'U', 216, "log-rotation-size",
172+
'U', 217, "log-rotation-size",
168173
&instance_config.logger.log_rotation_size, SOURCE_CMD, SOURCE_DEFAULT,
169174
OPTION_LOG_GROUP, OPTION_UNIT_KB, option_get_value
170175
},
171176
{
172-
'U', 217, "log-rotation-age",
177+
'U', 218, "log-rotation-age",
173178
&instance_config.logger.log_rotation_age, SOURCE_CMD, SOURCE_DEFAULT,
174179
OPTION_LOG_GROUP, OPTION_UNIT_MS, option_get_value
175180
},
176181
/* Retention options */
177182
{
178-
'u', 218, "retention-redundancy",
183+
'u', 219, "retention-redundancy",
179184
&instance_config.retention_redundancy, SOURCE_CMD, 0,
180185
OPTION_RETENTION_GROUP, 0, option_get_value
181186
},
182187
{
183-
'u', 219, "retention-window",
188+
'u', 220, "retention-window",
184189
&instance_config.retention_window, SOURCE_CMD, 0,
185190
OPTION_RETENTION_GROUP, 0, option_get_value
186191
},
187192
/* Compression options */
188193
{
189-
'f', 220, "compress-algorithm",
194+
'f', 221, "compress-algorithm",
190195
assign_compress_alg, SOURCE_CMD, 0,
191196
OPTION_COMPRESS_GROUP, 0, get_compress_alg
192197
},
193198
{
194-
'u', 221, "compress-level",
199+
'u', 222, "compress-level",
195200
&instance_config.compress_level, SOURCE_CMD, 0,
196201
OPTION_COMPRESS_GROUP, 0, option_get_value
197202
},
198203
/* Remote backup options */
199204
{
200-
's', 222, "remote-proto",
205+
's', 223, "remote-proto",
201206
&instance_config.remote.proto, SOURCE_CMD, 0,
202207
OPTION_REMOTE_GROUP, 0, option_get_value
203208
},
204209
{
205-
's', 223, "remote-host",
210+
's', 224, "remote-host",
206211
&instance_config.remote.host, SOURCE_CMD, 0,
207212
OPTION_REMOTE_GROUP, 0, option_get_value
208213
},
209214
{
210-
's', 224, "remote-port",
215+
's', 225, "remote-port",
211216
&instance_config.remote.port, SOURCE_CMD, 0,
212217
OPTION_REMOTE_GROUP, 0, option_get_value
213218
},
214219
{
215-
's', 225, "remote-path",
220+
's', 226, "remote-path",
216221
&instance_config.remote.path, SOURCE_CMD, 0,
217222
OPTION_REMOTE_GROUP, 0, option_get_value
218223
},
219224
{
220-
's', 226, "remote-user",
225+
's', 227, "remote-user",
221226
&instance_config.remote.user, SOURCE_CMD, 0,
222227
OPTION_REMOTE_GROUP, 0, option_get_value
223228
},
224229
{
225-
's', 227, "ssh-options",
230+
's', 228, "ssh-options",
226231
&instance_config.remote.ssh_options, SOURCE_CMD, 0,
227232
OPTION_REMOTE_GROUP, 0, option_get_value
228233
},
229234
{
230-
's', 228, "ssh-config",
235+
's', 229, "ssh-config",
231236
&instance_config.remote.ssh_config, SOURCE_CMD, 0,
232237
OPTION_REMOTE_GROUP, 0, option_get_value
233238
},
@@ -450,97 +455,125 @@ readInstanceConfigFile(const char *instance_name)
450455
&instance->archive_timeout, SOURCE_CMD, SOURCE_DEFAULT,
451456
OPTION_ARCHIVE_GROUP, OPTION_UNIT_S, option_get_value
452457
},
458+
{
459+
's', 208, "archive-host",
460+
&instance_config.archive.host, SOURCE_CMD, 0,
461+
OPTION_ARCHIVE_GROUP, 0, option_get_value
462+
},
463+
{
464+
's', 209, "archive-port",
465+
&instance_config.archive.port, SOURCE_CMD, 0,
466+
OPTION_ARCHIVE_GROUP, 0, option_get_value
467+
},
468+
{
469+
's', 210, "archive-user",
470+
&instance_config.archive.user, SOURCE_CMD, 0,
471+
OPTION_ARCHIVE_GROUP, 0, option_get_value
472+
},
473+
{
474+
's', 211, "restore-command",
475+
&instance->restore_command, SOURCE_CMD, 0,
476+
OPTION_ARCHIVE_GROUP, 0, option_get_value
477+
},
478+
479+
/* Instance options */
480+
{
481+
's', 'D', "pgdata",
482+
&instance->pgdata, SOURCE_CMD, 0,
483+
OPTION_INSTANCE_GROUP, 0, option_get_value
484+
},
485+
453486
/* Logging options */
454487
{
455-
's', 208, "log-level-console",
488+
's', 212, "log-level-console",
456489
&log_level_console, SOURCE_CMD, 0,
457490
OPTION_LOG_GROUP, 0, option_get_value
458491
},
459492
{
460-
's', 209, "log-level-file",
493+
's', 213, "log-level-file",
461494
&log_level_file, SOURCE_CMD, 0,
462495
OPTION_LOG_GROUP, 0, option_get_value
463496
},
464497
{
465-
's', 210, "log-filename",
498+
's', 214, "log-filename",
466499
&instance->logger.log_filename, SOURCE_CMD, 0,
467500
OPTION_LOG_GROUP, 0, option_get_value
468501
},
469502
{
470-
's', 211, "error-log-filename",
503+
's', 215, "error-log-filename",
471504
&instance->logger.error_log_filename, SOURCE_CMD, 0,
472505
OPTION_LOG_GROUP, 0, option_get_value
473506
},
474507
{
475-
's', 212, "log-directory",
508+
's', 216, "log-directory",
476509
&instance->logger.log_directory, SOURCE_CMD, 0,
477510
OPTION_LOG_GROUP, 0, option_get_value
478511
},
479512
{
480-
'U', 213, "log-rotation-size",
513+
'U', 217, "log-rotation-size",
481514
&instance->logger.log_rotation_size, SOURCE_CMD, SOURCE_DEFAULT,
482515
OPTION_LOG_GROUP, OPTION_UNIT_KB, option_get_value
483516
},
484517
{
485-
'U', 214, "log-rotation-age",
518+
'U', 218, "log-rotation-age",
486519
&instance->logger.log_rotation_age, SOURCE_CMD, SOURCE_DEFAULT,
487520
OPTION_LOG_GROUP, OPTION_UNIT_MS, option_get_value
488521
},
489522
/* Retention options */
490523
{
491-
'u', 215, "retention-redundancy",
524+
'u', 219, "retention-redundancy",
492525
&instance->retention_redundancy, SOURCE_CMD, 0,
493526
OPTION_RETENTION_GROUP, 0, option_get_value
494527
},
495528
{
496-
'u', 216, "retention-window",
529+
'u', 220, "retention-window",
497530
&instance->retention_window, SOURCE_CMD, 0,
498531
OPTION_RETENTION_GROUP, 0, option_get_value
499532
},
500533
/* Compression options */
501534
{
502-
's', 217, "compress-algorithm",
535+
's', 221, "compress-algorithm",
503536
&compress_alg, SOURCE_CMD, 0,
504537
OPTION_LOG_GROUP, 0, option_get_value
505538
},
506539
{
507-
'u', 218, "compress-level",
540+
'u', 222, "compress-level",
508541
&instance->compress_level, SOURCE_CMD, 0,
509542
OPTION_COMPRESS_GROUP, 0, option_get_value
510543
},
511544
/* Remote backup options */
512545
{
513-
's', 219, "remote-proto",
546+
's', 223, "remote-proto",
514547
&instance->remote.proto, SOURCE_CMD, 0,
515548
OPTION_REMOTE_GROUP, 0, option_get_value
516549
},
517550
{
518-
's', 220, "remote-host",
551+
's', 224, "remote-host",
519552
&instance->remote.host, SOURCE_CMD, 0,
520553
OPTION_REMOTE_GROUP, 0, option_get_value
521554
},
522555
{
523-
's', 221, "remote-port",
556+
's', 225, "remote-port",
524557
&instance->remote.port, SOURCE_CMD, 0,
525558
OPTION_REMOTE_GROUP, 0, option_get_value
526559
},
527560
{
528-
's', 222, "remote-path",
561+
's', 226, "remote-path",
529562
&instance->remote.path, SOURCE_CMD, 0,
530563
OPTION_REMOTE_GROUP, 0, option_get_value
531564
},
532565
{
533-
's', 223, "remote-user",
566+
's', 227, "remote-user",
534567
&instance->remote.user, SOURCE_CMD, 0,
535568
OPTION_REMOTE_GROUP, 0, option_get_value
536569
},
537570
{
538-
's', 224, "ssh-options",
571+
's', 228, "ssh-options",
539572
&instance->remote.ssh_options, SOURCE_CMD, 0,
540573
OPTION_REMOTE_GROUP, 0, option_get_value
541574
},
542575
{
543-
's', 225, "ssh-config",
576+
's', 229, "ssh-config",
544577
&instance->remote.ssh_config, SOURCE_CMD, 0,
545578
OPTION_REMOTE_GROUP, 0, option_get_value
546579
},

src/pg_probackup.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ static char *target_stop;
8787
static bool target_immediate;
8888
static char *target_name = NULL;
8989
static char *target_action = NULL;
90-
static char *restore_command = NULL;
9190

9291
static pgRecoveryTarget *recovery_target_options = NULL;
9392
static pgRestoreParams *restore_params = NULL;
@@ -183,7 +182,6 @@ static ConfigOption cmd_options[] =
183182
{ 'b', 156, "skip-external-dirs", &skip_external_dirs, SOURCE_CMD_STRICT },
184183
{ 'f', 158, "db-include", opt_datname_include_list, SOURCE_CMD_STRICT },
185184
{ 'f', 159, "db-exclude", opt_datname_exclude_list, SOURCE_CMD_STRICT },
186-
{ 's', 160, "restore-command", &restore_command, SOURCE_CMD_STRICT },
187185
/* checkdb options */
188186
{ 'b', 195, "amcheck", &need_amcheck, SOURCE_CMD_STRICT },
189187
{ 'b', 196, "heapallindexed", &heapallindexed, SOURCE_CMD_STRICT },
@@ -643,7 +641,6 @@ main(int argc, char *argv[])
643641
restore_params->skip_external_dirs = skip_external_dirs;
644642
restore_params->partial_db_list = NULL;
645643
restore_params->partial_restore_type = NONE;
646-
restore_params->restore_command = restore_command;
647644

648645
/* handle partial restore parameters */
649646
if (datname_exclude_list && datname_include_list)

src/pg_probackup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ typedef struct InstanceConfig
252252
/* Wait timeout for WAL segment archiving */
253253
uint32 archive_timeout;
254254

255+
/* cmdline to be used as restore_command */
256+
char *restore_command;
257+
255258
/* Logger parameters */
256259
LoggerConfig logger;
257260

src/restore.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,15 +857,15 @@ create_recovery_conf(time_t backup_id,
857857
fio_fprintf(fp, "# recovery.conf generated by pg_probackup %s\n",
858858
PROGRAM_VERSION);
859859

860+
/* construct restore_command */
860861
if (need_restore_conf)
861862
{
862863

863864
char restore_command_guc[16384];
864865

865866
/* If restore_command is provided, use it */
866-
if (params->restore_command)
867-
sprintf(restore_command_guc, "%s", params->restore_command);
868-
/* construct restore_command */
867+
if (instance_config.restore_command)
868+
sprintf(restore_command_guc, "%s", instance_config.restore_command);
869869
else
870870
{
871871
/* default cmdline, ok for local restore */

src/utils/configuration.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ assign_option(ConfigOption *opt, const char *optarg, OptionSource src)
250250
case 's':
251251
if (orig_source != SOURCE_DEFAULT)
252252
free(*(char **) opt->var);
253+
254+
/* 'none' and 'off' are always disable the string parameter */
255+
if ((pg_strcasecmp(optarg, "none") == 0) ||
256+
(pg_strcasecmp(optarg, "off") == 0))
257+
{
258+
opt->var = NULL;
259+
return;
260+
}
261+
253262
*(char **) opt->var = pgut_strdup(optarg);
254263
if (strcmp(optarg,"") != 0)
255264
return;
@@ -656,6 +665,10 @@ option_get_value(ConfigOption *opt)
656665
case 's':
657666
if (*((char **) opt->var) == NULL)
658667
return NULL;
668+
/* 'none' and 'off' are always disable the string parameter */
669+
if ((pg_strcasecmp(*((char **) opt->var), "none") == 0) ||
670+
(pg_strcasecmp(*((char **) opt->var), "off") == 0))
671+
return NULL;
659672
return pstrdup(*((char **) opt->var));
660673
case 't':
661674
{

0 commit comments

Comments
 (0)