Skip to content

Commit 20d8820

Browse files
committed
[Issue #129] Generate recovery.conf if --recovery-target='immediate' is provided
1 parent 6596926 commit 20d8820

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

src/restore.c

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
193193
{
194194
parray *timelines;
195195

196-
elog(LOG, "target timeline ID = %u", rt->target_tli);
196+
// elog(LOG, "target timeline ID = %u", rt->target_tli);
197197
/* Read timeline history files from archives */
198198
timelines = read_timeline_history(arclog_path, rt->target_tli);
199199

@@ -835,11 +835,18 @@ create_recovery_conf(time_t backup_id,
835835
FILE *fp;
836836
bool need_restore_conf;
837837
bool target_latest;
838+
bool target_immediate;
838839

840+
/* restore-target='latest' support */
839841
target_latest = rt->target_stop != NULL &&
840842
strcmp(rt->target_stop, "latest") == 0;
841-
need_restore_conf = !backup->stream ||
842-
(rt->time_string || rt->xid_string || rt->lsn_string) || target_latest;
843+
844+
target_immediate = rt->target_stop != NULL &&
845+
strcmp(rt->target_stop, "immediate") == 0;
846+
847+
need_restore_conf = !backup->stream || rt->time_string ||
848+
rt->xid_string || rt->lsn_string || rt->target_name ||
849+
target_immediate || target_latest;
843850

844851
/* No need to generate recovery.conf at all. */
845852
if (!(need_restore_conf || params->restore_as_replica))
@@ -914,7 +921,7 @@ create_recovery_conf(time_t backup_id,
914921
if (rt->lsn_string)
915922
fio_fprintf(fp, "recovery_target_lsn = '%s'\n", rt->lsn_string);
916923

917-
if (rt->target_stop && !target_latest)
924+
if (rt->target_stop && target_immediate)
918925
fio_fprintf(fp, "recovery_target = '%s'\n", rt->target_stop);
919926

920927
if (rt->inclusive_specified)
@@ -1120,7 +1127,7 @@ parseRecoveryTargetOptions(const char *target_time,
11201127
if (parse_time(target_time, &dummy_time, false))
11211128
rt->target_time = dummy_time;
11221129
else
1123-
elog(ERROR, "Invalid value for '--recovery-target-time' option %s",
1130+
elog(ERROR, "Invalid value for '--recovery-target-time' option '%s'",
11241131
target_time);
11251132
}
11261133

@@ -1138,7 +1145,7 @@ parseRecoveryTargetOptions(const char *target_time,
11381145
#endif
11391146
rt->target_xid = dummy_xid;
11401147
else
1141-
elog(ERROR, "Invalid value for '--recovery-target-xid' option %s",
1148+
elog(ERROR, "Invalid value for '--recovery-target-xid' option '%s'",
11421149
target_xid);
11431150
}
11441151

@@ -1151,7 +1158,7 @@ parseRecoveryTargetOptions(const char *target_time,
11511158
if (parse_lsn(target_lsn, &dummy_lsn))
11521159
rt->target_lsn = dummy_lsn;
11531160
else
1154-
elog(ERROR, "Invalid value of '--recovery-target-lsn' option %s",
1161+
elog(ERROR, "Invalid value of '--recovery-target-lsn' option '%s'",
11551162
target_lsn);
11561163
}
11571164

@@ -1161,7 +1168,7 @@ parseRecoveryTargetOptions(const char *target_time,
11611168
if (parse_bool(target_inclusive, &dummy_bool))
11621169
rt->target_inclusive = dummy_bool;
11631170
else
1164-
elog(ERROR, "Invalid value for '--recovery-target-inclusive' option %s",
1171+
elog(ERROR, "Invalid value for '--recovery-target-inclusive' option '%s'",
11651172
target_inclusive);
11661173
}
11671174

@@ -1170,7 +1177,7 @@ parseRecoveryTargetOptions(const char *target_time,
11701177
{
11711178
if ((strcmp(target_stop, "immediate") != 0)
11721179
&& (strcmp(target_stop, "latest") != 0))
1173-
elog(ERROR, "Invalid value for '--recovery-target' option %s",
1180+
elog(ERROR, "Invalid value for '--recovery-target' option '%s'",
11741181
target_stop);
11751182

11761183
recovery_target_specified++;
@@ -1188,7 +1195,7 @@ parseRecoveryTargetOptions(const char *target_time,
11881195
if ((strcmp(target_action, "pause") != 0)
11891196
&& (strcmp(target_action, "promote") != 0)
11901197
&& (strcmp(target_action, "shutdown") != 0))
1191-
elog(ERROR, "Invalid value for '--recovery-target-action' option %s",
1198+
elog(ERROR, "Invalid value for '--recovery-target-action' option '%s'",
11921199
target_action);
11931200

11941201
rt->target_action = target_action;
@@ -1201,15 +1208,27 @@ parseRecoveryTargetOptions(const char *target_time,
12011208

12021209
/* More than one mutually exclusive option was defined. */
12031210
if (recovery_target_specified > 1)
1204-
elog(ERROR, "At most one of --recovery-target, --recovery-target-name, --recovery-target-time, --recovery-target-xid, or --recovery-target-lsn can be specified");
1211+
elog(ERROR, "At most one of '--recovery-target', '--recovery-target-name', "
1212+
"'--recovery-target-time', '--recovery-target-xid' or "
1213+
"'--recovery-target-lsn' options can be specified");
12051214

12061215
/*
12071216
* If none of the options is defined, '--recovery-target-inclusive' option
12081217
* is meaningless.
12091218
*/
12101219
if (!(rt->xid_string || rt->time_string || rt->lsn_string) &&
12111220
rt->target_inclusive)
1212-
elog(ERROR, "--recovery-target-inclusive option applies when either --recovery-target-time, --recovery-target-xid or --recovery-target-lsn is specified");
1221+
elog(ERROR, "The '--recovery-target-inclusive' option can be applied only when "
1222+
"either of '--recovery-target-time', '--recovery-target-xid' or "
1223+
"'--recovery-target-lsn' options is specified");
1224+
1225+
/* If none of the options is defined, '--recovery-target-action' is meaningless */
1226+
if (rt->target_action && recovery_target_specified == 0)
1227+
elog(ERROR, "The '--recovery-target-action' option can be applied only when "
1228+
"either of '--recovery-target', '--recovery-target-time', '--recovery-target-xid', "
1229+
"'--recovery-target-lsn' or '--recovery-target-name' options is specified");
1230+
1231+
/* TODO: sanity for recovery-target-timeline */
12131232

12141233
return rt;
12151234
}

0 commit comments

Comments
 (0)