Skip to content

Commit c8147f7

Browse files
committed
Add more recovery options for restore/validate:
--immediate - end recovery as soon as a consistent state is reached; --recovery-target-name=target-name - set the named restore point to which recovery will proceed; --recovery-target-action=pause|promote|shutdown - set the action the server should take once the recovery target is reached. Add restore option -R (--write-recovery-conf) - write a minimal recovery.conf in the output directory, to ease setting up a standby server.
1 parent 3b45f96 commit c8147f7

File tree

9 files changed

+314
-69
lines changed

9 files changed

+314
-69
lines changed

src/backup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ do_backup(time_t start_time)
759759
backup_conn = pgut_connect(pgut_dbname);
760760
pgut_atexit_push(backup_disconnect, NULL);
761761

762+
current.primary_conninfo = pgut_get_conninfo_string(backup_conn);
762763
/* Confirm data block size and xlog block size are compatible */
763764
confirm_block_size("block_size", BLCKSZ);
764765
confirm_block_size("wal_block_size", XLOG_BLCKSZ);

src/catalog.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,10 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
437437
/* 'parent_backup' is set if it is incremental backup */
438438
if (backup->parent_backup != 0)
439439
fprintf(out, "parent-backup-id = '%s'\n", base36enc(backup->parent_backup));
440+
441+
/* print connection info except password */
442+
if (backup->primary_conninfo)
443+
fprintf(out, "primary_conninfo = '%s'\n", backup->primary_conninfo);
440444
}
441445

442446
/* create BACKUP_CONTROL_FILE */
@@ -498,6 +502,7 @@ readBackupControlFile(const char *path)
498502
{'s', 0, "compress-alg", &compress_alg, SOURCE_FILE_STRICT},
499503
{'u', 0, "compress-level", &compress_level, SOURCE_FILE_STRICT},
500504
{'b', 0, "from-replica", &from_replica, SOURCE_FILE_STRICT},
505+
{'s', 0, "primary-conninfo", &backup->primary_conninfo, SOURCE_FILE_STRICT},
501506
{0}
502507
};
503508

src/help.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,16 @@ help_pg_probackup(void)
117117
printf(_(" [-D pgdata-dir] [-i backup-id] [--progress]\n"));
118118
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
119119
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n"));
120+
printf(_(" [--immediate] [--recovery-target-name=target-name]\n"));
121+
printf(_(" [--recovery-target-action=pause|promote|shutdown]\n"));
122+
printf(_(" [--write-recovery-conf]\n"));
120123

121124
printf(_("\n %s validate -B backup-dir [--instance=instance_name]\n"), PROGRAM_NAME);
122125
printf(_(" [-i backup-id] [--progress]\n"));
123126
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
124127
printf(_(" [--timeline=timeline]\n"));
128+
printf(_(" [--immediate] [--recovery-target-name=target-name]\n"));
129+
printf(_(" [--recovery-target-action=pause|promote|shutdown]\n"));
125130

126131
printf(_("\n %s show -B backup-dir\n"), PROGRAM_NAME);
127132
printf(_(" [--instance=instance_name [-i backup-id]]\n"));
@@ -259,7 +264,10 @@ help_restore(void)
259264
printf(_("%s restore -B backup-dir --instance=instance_name\n"), PROGRAM_NAME);
260265
printf(_(" [-D pgdata-dir] [-i backup-id] [--progress]\n"));
261266
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
262-
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n\n"));
267+
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n"));
268+
printf(_(" [--immediate] [--recovery-target-name=target-name]\n"));
269+
printf(_(" [--recovery-target-action=pause|promote|shutdown]\n\n"));
270+
printf(_(" [--write-recovery-conf]\n"));
263271

264272
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
265273
printf(_(" --instance=instance_name name of the instance\n"));
@@ -275,6 +283,15 @@ help_restore(void)
275283
printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"));
276284
printf(_(" relocate the tablespace from directory OLDDIR to NEWDIR\n"));
277285

286+
printf(_(" --immediate end recovery as soon as a consistent state is reached\n"));
287+
printf(_(" --recovery-target-name=target-name\n"));
288+
printf(_(" the named restore point to which recovery will proceed\n"));
289+
printf(_(" --recovery-target-action=pause|promote|shutdown\n"));
290+
printf(_(" action the server should take once the recovery target is reached\n"));
291+
292+
printf(_(" -R, --write-recovery-conf write a minimal recovery.conf in the output directory\n"));
293+
printf(_(" to ease setting up a standby server\n"));
294+
278295
printf(_("\n Logging options:\n"));
279296
printf(_(" --log-level-console=log-level-console\n"));
280297
printf(_(" level for console logging (default: info)\n"));
@@ -303,7 +320,9 @@ help_validate(void)
303320
printf(_("%s validate -B backup-dir [--instance=instance_name]\n"), PROGRAM_NAME);
304321
printf(_(" [-i backup-id] [--progress]\n"));
305322
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
306-
printf(_(" [--timeline=timeline]\n\n"));
323+
printf(_(" [--timeline=timeline]\n"));
324+
printf(_(" [--immediate] [--recovery-target-name=target-name]\n"));
325+
printf(_(" [--recovery-target-action=pause|promote|shutdown]\n\n"));
307326

308327
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
309328
printf(_(" --instance=instance_name name of the instance\n"));
@@ -315,6 +334,12 @@ help_validate(void)
315334
printf(_(" --inclusive=boolean whether we stop just after the recovery target\n"));
316335
printf(_(" --timeline=timeline recovering into a particular timeline\n"));
317336

337+
printf(_(" --immediate end recovery as soon as a consistent state is reached\n"));
338+
printf(_(" --recovery-target-name=target-name\n"));
339+
printf(_(" the named restore point to which recovery will proceed\n"));
340+
printf(_(" --recovery-target-action=pause|promote|shutdown\n"));
341+
printf(_(" action the server should take once the recovery target is reached\n"));
342+
318343
printf(_("\n Logging options:\n"));
319344
printf(_(" --log-level-console=log-level-console\n"));
320345
printf(_(" level for console logging (default: info)\n"));

src/pg_probackup.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ static char *target_time;
6262
static char *target_xid;
6363
static char *target_inclusive;
6464
static TimeLineID target_tli;
65+
static bool target_immediate;
66+
static char *target_name = NULL;
67+
static char *target_action = NULL;;
68+
69+
static pgRecoveryTarget *recovery_target_options = NULL;
70+
71+
bool restore_as_replica = false;
6572

6673
/* delete options */
6774
bool delete_wal = false;
@@ -132,6 +139,10 @@ static pgut_option options[] =
132139
{ 's', 22, "inclusive", &target_inclusive, SOURCE_CMDLINE },
133140
{ 'u', 23, "timeline", &target_tli, SOURCE_CMDLINE },
134141
{ 'f', 'T', "tablespace-mapping", opt_tablespace_map, SOURCE_CMDLINE },
142+
{ 'b', 24, "immediate", &target_immediate, SOURCE_CMDLINE },
143+
{ 's', 25, "recovery-target-name", &target_name, SOURCE_CMDLINE },
144+
{ 's', 26, "recovery-target-action", &target_action, SOURCE_CMDLINE },
145+
{ 'b', 'R', "write-recovery-conf", &restore_as_replica, SOURCE_CMDLINE },
135146
/* delete options */
136147
{ 'b', 130, "wal", &delete_wal, SOURCE_CMDLINE },
137148
{ 'b', 131, "expired", &delete_expired, SOURCE_CMDLINE },
@@ -406,8 +417,13 @@ main(int argc, char *argv[])
406417
pgdata_exclude_dir[i] = "pg_log";
407418
}
408419

409-
if (target_time != NULL && target_xid != NULL)
410-
elog(ERROR, "You can't specify recovery-target-time and recovery-target-xid at the same time");
420+
if (backup_subcmd == VALIDATE || backup_subcmd == RESTORE)
421+
{
422+
/* parse all recovery target options into recovery_target_options structure */
423+
recovery_target_options = parseRecoveryTargetOptions(target_time, target_xid,
424+
target_inclusive, target_tli, target_immediate,
425+
target_name, target_action);
426+
}
411427

412428
if (num_threads < 1)
413429
num_threads = 1;
@@ -443,16 +459,14 @@ main(int argc, char *argv[])
443459
}
444460
case RESTORE:
445461
return do_restore_or_validate(current.backup_id,
446-
target_time, target_xid,
447-
target_inclusive, target_tli,
462+
recovery_target_options,
448463
true);
449464
case VALIDATE:
450465
if (current.backup_id == 0 && target_time == 0 && target_xid == 0)
451466
return do_validate_all();
452467
else
453468
return do_restore_or_validate(current.backup_id,
454-
target_time, target_xid,
455-
target_inclusive, target_tli,
469+
recovery_target_options,
456470
false);
457471
case SHOW:
458472
return do_show(current.backup_id);

src/pg_probackup.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,27 @@ typedef struct pgBackup
226226
time_t parent_backup; /* Identifier of the previous backup.
227227
* Which is basic backup for this
228228
* incremental backup. */
229+
char *primary_conninfo; /* Connection parameters of the backup
230+
* in the format suitable for recovery.conf */
229231
} pgBackup;
230232

231233
/* Recovery target for restore and validate subcommands */
232234
typedef struct pgRecoveryTarget
233235
{
234236
bool time_specified;
235237
time_t recovery_target_time;
238+
/* add one more field in order to avoid deparsing recovery_target_time back */
239+
const char *target_time_string;
236240
bool xid_specified;
237241
TransactionId recovery_target_xid;
242+
/* add one more field in order to avoid deparsing recovery_target_xid back */
243+
const char *target_xid_string;
244+
TimeLineID recovery_target_tli;
238245
bool recovery_target_inclusive;
246+
bool inclusive_specified;
247+
bool recovery_target_immediate;
248+
const char *recovery_target_name;
249+
const char *recovery_target_action;
239250
} pgRecoveryTarget;
240251

241252
/* Union to ease operations on relation pages */
@@ -305,6 +316,9 @@ extern bool is_ptrack_support;
305316
extern bool is_checksum_enabled;
306317
extern bool exclusive_backup;
307318

319+
/* restore options */
320+
extern bool restore_as_replica;
321+
308322
/* delete options */
309323
extern bool delete_wal;
310324
extern bool delete_expired;
@@ -349,19 +363,16 @@ extern char *pg_ptrack_get_block(backup_files_args *arguments,
349363
size_t *result_size);
350364
/* in restore.c */
351365
extern int do_restore_or_validate(time_t target_backup_id,
352-
const char *target_time,
353-
const char *target_xid,
354-
const char *target_inclusive,
355-
TimeLineID target_tli,
366+
pgRecoveryTarget *rt,
356367
bool is_restore);
357368
extern bool satisfy_timeline(const parray *timelines, const pgBackup *backup);
358369
extern bool satisfy_recovery_target(const pgBackup *backup,
359370
const pgRecoveryTarget *rt);
360371
extern parray * readTimeLineHistory_probackup(TimeLineID targetTLI);
361372
extern pgRecoveryTarget *parseRecoveryTargetOptions(
362-
const char *target_time,
363-
const char *target_xid,
364-
const char *target_inclusive);
373+
const char *target_time, const char *target_xid,
374+
const char *target_inclusive, TimeLineID target_tli, bool target_immediate,
375+
const char *target_name, const char *target_action);
365376

366377
extern void opt_tablespace_map(pgut_option *opt, const char *arg);
367378

0 commit comments

Comments
 (0)