Skip to content

Commit 5c3acb6

Browse files
committed
Merge branch 'pgpro_1053_697'
2 parents e154698 + b1f9043 commit 5c3acb6

File tree

17 files changed

+1038
-309
lines changed

17 files changed

+1038
-309
lines changed

src/backup.c

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

814+
current.primary_conninfo = pgut_get_conninfo_string(backup_conn);
814815
/* Confirm data block size and xlog block size are compatible */
815816
confirm_block_size("block_size", BLCKSZ);
816817
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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ 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(_(" [--restore-as-replica]\n"));
120123

121124
printf(_("\n %s validate -B backup-dir [--instance=instance_name]\n"), PROGRAM_NAME);
122125
printf(_(" [-i backup-id] [--progress]\n"));
@@ -259,7 +262,10 @@ help_restore(void)
259262
printf(_("%s restore -B backup-dir --instance=instance_name\n"), PROGRAM_NAME);
260263
printf(_(" [-D pgdata-dir] [-i backup-id] [--progress]\n"));
261264
printf(_(" [--time=time|--xid=xid [--inclusive=boolean]]\n"));
262-
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n\n"));
265+
printf(_(" [--timeline=timeline] [-T OLDDIR=NEWDIR]\n"));
266+
printf(_(" [--immediate] [--recovery-target-name=target-name]\n"));
267+
printf(_(" [--recovery-target-action=pause|promote|shutdown]\n"));
268+
printf(_(" [--restore-as-replica]\n\n"));
263269

264270
printf(_(" -B, --backup-path=backup-path location of the backup storage area\n"));
265271
printf(_(" --instance=instance_name name of the instance\n"));
@@ -275,6 +281,16 @@ help_restore(void)
275281
printf(_(" -T, --tablespace-mapping=OLDDIR=NEWDIR\n"));
276282
printf(_(" relocate the tablespace from directory OLDDIR to NEWDIR\n"));
277283

284+
printf(_(" --immediate end recovery as soon as a consistent state is reached\n"));
285+
printf(_(" --recovery-target-name=target-name\n"));
286+
printf(_(" the named restore point to which recovery will proceed\n"));
287+
printf(_(" --recovery-target-action=pause|promote|shutdown\n"));
288+
printf(_(" action the server should take once the recovery target is reached\n"));
289+
printf(_(" (default: pause)\n"));
290+
291+
printf(_(" -R, --restore-as-replica write a minimal recovery.conf in the output directory\n"));
292+
printf(_(" to ease setting up a standby server\n"));
293+
278294
printf(_("\n Logging options:\n"));
279295
printf(_(" --log-level-console=log-level-console\n"));
280296
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', "restore-as-replica", &restore_as_replica, SOURCE_CMDLINE },
135146
/* delete options */
136147
{ 'b', 130, "wal", &delete_wal, SOURCE_CMDLINE },
137148
{ 'b', 131, "expired", &delete_expired, SOURCE_CMDLINE },
@@ -411,8 +422,13 @@ main(int argc, char *argv[])
411422
pgdata_exclude_dir[i] = "pg_log";
412423
}
413424

414-
if (target_time != NULL && target_xid != NULL)
415-
elog(ERROR, "You can't specify recovery-target-time and recovery-target-xid at the same time");
425+
if (backup_subcmd == VALIDATE || backup_subcmd == RESTORE)
426+
{
427+
/* parse all recovery target options into recovery_target_options structure */
428+
recovery_target_options = parseRecoveryTargetOptions(target_time, target_xid,
429+
target_inclusive, target_tli, target_immediate,
430+
target_name, target_action);
431+
}
416432

417433
if (num_threads < 1)
418434
num_threads = 1;
@@ -448,16 +464,14 @@ main(int argc, char *argv[])
448464
}
449465
case RESTORE:
450466
return do_restore_or_validate(current.backup_id,
451-
target_time, target_xid,
452-
target_inclusive, target_tli,
467+
recovery_target_options,
453468
true);
454469
case VALIDATE:
455470
if (current.backup_id == 0 && target_time == 0 && target_xid == 0)
456471
return do_validate_all();
457472
else
458473
return do_restore_or_validate(current.backup_id,
459-
target_time, target_xid,
460-
target_inclusive, target_tli,
474+
recovery_target_options,
461475
false);
462476
case SHOW:
463477
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 */
@@ -311,6 +322,9 @@ extern bool is_ptrack_support;
311322
extern bool is_checksum_enabled;
312323
extern bool exclusive_backup;
313324

325+
/* restore options */
326+
extern bool restore_as_replica;
327+
314328
/* delete options */
315329
extern bool delete_wal;
316330
extern bool delete_expired;
@@ -355,19 +369,16 @@ extern char *pg_ptrack_get_block(backup_files_args *arguments,
355369
size_t *result_size);
356370
/* in restore.c */
357371
extern int do_restore_or_validate(time_t target_backup_id,
358-
const char *target_time,
359-
const char *target_xid,
360-
const char *target_inclusive,
361-
TimeLineID target_tli,
372+
pgRecoveryTarget *rt,
362373
bool is_restore);
363374
extern bool satisfy_timeline(const parray *timelines, const pgBackup *backup);
364375
extern bool satisfy_recovery_target(const pgBackup *backup,
365376
const pgRecoveryTarget *rt);
366377
extern parray * readTimeLineHistory_probackup(TimeLineID targetTLI);
367378
extern pgRecoveryTarget *parseRecoveryTargetOptions(
368-
const char *target_time,
369-
const char *target_xid,
370-
const char *target_inclusive);
379+
const char *target_time, const char *target_xid,
380+
const char *target_inclusive, TimeLineID target_tli, bool target_immediate,
381+
const char *target_name, const char *target_action);
371382

372383
extern void opt_tablespace_map(pgut_option *opt, const char *arg);
373384

0 commit comments

Comments
 (0)