Skip to content

Commit e1ed647

Browse files
committed
[Issue #149] Allow to set primary_slot_name during restore, option "-S,--slot" can now be used with "restore" command
1 parent 4000349 commit e1ed647

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/pg_probackup.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,12 +653,16 @@ main(int argc, char *argv[])
653653
if (force)
654654
no_validate = true;
655655

656+
if (replication_slot != NULL)
657+
restore_as_replica = true;
658+
656659
/* keep all params in one structure */
657660
restore_params = pgut_new(pgRestoreParams);
658661
restore_params->is_restore = (backup_subcmd == RESTORE_CMD);
659662
restore_params->force = force;
660663
restore_params->no_validate = no_validate;
661664
restore_params->restore_as_replica = restore_as_replica;
665+
restore_params->primary_slot_name = replication_slot;
662666
restore_params->skip_block_validation = skip_block_validation;
663667
restore_params->skip_external_dirs = skip_external_dirs;
664668
restore_params->partial_db_list = NULL;

src/pg_probackup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ typedef struct pgRestoreParams
392392
bool skip_external_dirs;
393393
bool skip_block_validation; //Start using it
394394
const char *restore_command;
395+
const char *primary_slot_name;
395396

396397
/* options for partial restore */
397398
PartialRestoreType partial_restore_type;

src/restore.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ create_recovery_conf(time_t backup_id,
937937
/* construct restore_command */
938938
if (pitr_requested)
939939
{
940+
fio_fprintf(fp, "\n## recovery settings\n");
940941
/* If restore_command is provided, use it. Otherwise construct it from scratch. */
941942
if (restore_command_provided)
942943
sprintf(restore_command_guc, "%s", instance_config.restore_command);
@@ -1012,21 +1013,25 @@ create_recovery_conf(time_t backup_id,
10121013
fio_fprintf(fp, "recovery_target_action = '%s'\n", "pause");
10131014
}
10141015

1016+
if (pitr_requested)
1017+
{
1018+
elog(LOG, "Setting restore_command to '%s'", restore_command_guc);
1019+
fio_fprintf(fp, "restore_command = '%s'\n", restore_command_guc);
1020+
}
1021+
10151022
if (params->restore_as_replica)
10161023
{
1024+
fio_fprintf(fp, "\n## standby settings\n");
10171025
/* standby_mode was removed in PG12 */
10181026
#if PG_VERSION_NUM < 120000
10191027
fio_fprintf(fp, "standby_mode = 'on'\n");
10201028
#endif
10211029

10221030
if (backup->primary_conninfo)
10231031
fio_fprintf(fp, "primary_conninfo = '%s'\n", backup->primary_conninfo);
1024-
}
10251032

1026-
if (pitr_requested)
1027-
{
1028-
elog(LOG, "Setting restore_command to '%s'", restore_command_guc);
1029-
fio_fprintf(fp, "restore_command = '%s'\n", restore_command_guc);
1033+
if (params->primary_slot_name != NULL)
1034+
fio_fprintf(fp, "primary_slot_name = '%s'\n", params->primary_slot_name);
10301035
}
10311036

10321037
if (fio_fflush(fp) != 0 ||

0 commit comments

Comments
 (0)