Skip to content

Commit 188bb11

Browse files
committed
Revert "Issue #31: Use UTC time to make backup ID"
This reverts commit 4877f6b.
1 parent 4877f6b commit 188bb11

File tree

8 files changed

+26
-34
lines changed

8 files changed

+26
-34
lines changed

src/backup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ do_backup_instance(void)
553553
pg_ptrack_clear();
554554

555555
/* notify start of backup to PostgreSQL server */
556-
time2iso(label, lengthof(label), current.start_time, true);
556+
time2iso(label, lengthof(label), current.start_time);
557557
strncat(label, " with pg_probackup", lengthof(label) -
558558
strlen(" with pg_probackup"));
559559
pg_start_backup(label, smooth_checkpoint, &current);

src/catalog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,17 +409,17 @@ pgBackupWriteControl(FILE *out, pgBackup *backup)
409409
(uint32) (backup->stop_lsn >> 32),
410410
(uint32) backup->stop_lsn);
411411

412-
time2iso(timestamp, lengthof(timestamp), backup->start_time, false);
412+
time2iso(timestamp, lengthof(timestamp), backup->start_time);
413413
fprintf(out, "start-time = '%s'\n", timestamp);
414414
if (backup->end_time > 0)
415415
{
416-
time2iso(timestamp, lengthof(timestamp), backup->end_time, false);
416+
time2iso(timestamp, lengthof(timestamp), backup->end_time);
417417
fprintf(out, "end-time = '%s'\n", timestamp);
418418
}
419419
fprintf(out, "recovery-xid = " XID_FMT "\n", backup->recovery_xid);
420420
if (backup->recovery_time > 0)
421421
{
422-
time2iso(timestamp, lengthof(timestamp), backup->recovery_time, false);
422+
time2iso(timestamp, lengthof(timestamp), backup->recovery_time);
423423
fprintf(out, "recovery-time = '%s'\n", timestamp);
424424
}
425425

src/delete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pgBackupDeleteFiles(pgBackup *backup)
257257
if (backup->status == BACKUP_STATUS_DELETED)
258258
return 0;
259259

260-
time2iso(timestamp, lengthof(timestamp), backup->recovery_time, true);
260+
time2iso(timestamp, lengthof(timestamp), backup->recovery_time);
261261

262262
elog(INFO, "delete: %s %s", base36enc(backup->start_time), timestamp);
263263

src/parsexlog.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ validate_wal(pgBackup *backup,
380380
xlogfpath[0] = '\0';
381381

382382
/* We can restore at least up to the backup end */
383-
time2iso(last_timestamp, lengthof(last_timestamp), backup->recovery_time,
384-
true);
383+
time2iso(last_timestamp, lengthof(last_timestamp), backup->recovery_time);
385384
last_xid = backup->recovery_xid;
386385

387386
if ((TransactionIdIsValid(target_xid) && target_xid == last_xid)
@@ -431,7 +430,7 @@ validate_wal(pgBackup *backup,
431430

432431
if (last_time > 0)
433432
time2iso(last_timestamp, lengthof(last_timestamp),
434-
timestamptz_to_time_t(last_time), true);
433+
timestamptz_to_time_t(last_time));
435434

436435
/* There are all needed WAL records */
437436
if (all_wal)
@@ -460,8 +459,8 @@ validate_wal(pgBackup *backup,
460459
last_timestamp, last_xid);
461460

462461
if (target_time > 0)
463-
time2iso(target_timestamp, lengthof(target_timestamp), target_time,
464-
true);
462+
time2iso(target_timestamp, lengthof(target_timestamp),
463+
target_time);
465464
if (TransactionIdIsValid(target_xid) && target_time != 0)
466465
elog(ERROR, "not enough WAL records to time %s and xid " XID_FMT,
467466
target_timestamp, target_xid);

src/pg_probackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ extern bool wal_contains_lsn(const char *archivedir, XLogRecPtr target_lsn,
521521
/* in util.c */
522522
extern TimeLineID get_current_timeline(bool safe);
523523
extern void sanityChecks(void);
524-
extern void time2iso(char *buf, size_t len, time_t time, bool to_local);
524+
extern void time2iso(char *buf, size_t len, time_t time);
525525
extern const char *status2str(BackupStatus status);
526526
extern void remove_trailing_space(char *buf, int comment_mark);
527527
extern void remove_not_digit(char *buf, size_t len, const char *str);

src/restore.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt,
122122
current_backup = (pgBackup *) parray_get(backups, i);
123123

124124
/* Skip all backups which started after target backup */
125-
if (target_backup_id != INVALID_BACKUP_ID &&
126-
current_backup->start_time > target_backup_id)
125+
if (target_backup_id && current_backup->start_time > target_backup_id)
127126
continue;
128127

129128
/*
@@ -382,7 +381,7 @@ restore_backup(pgBackup *backup)
382381
"XLOG_BLCKSZ(%d) is not compatible(%d expected)",
383382
backup->wal_block_size, XLOG_BLCKSZ);
384383

385-
time2iso(timestamp, lengthof(timestamp), backup->start_time, true);
384+
time2iso(timestamp, lengthof(timestamp), backup->start_time);
386385
elog(LOG, "restoring database from backup %s", timestamp);
387386

388387
/*

src/show.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,7 @@ show_instance_plain(parray *backup_list, bool show_name)
324324
char data_bytes_str[10] = "----";
325325

326326
if (backup->recovery_time != (time_t) 0)
327-
time2iso(timestamp, lengthof(timestamp), backup->recovery_time,
328-
true);
327+
time2iso(timestamp, lengthof(timestamp), backup->recovery_time);
329328
if (backup->end_time != (time_t) 0)
330329
snprintf(duration, lengthof(duration), "%.*lfs", 0,
331330
difftime(backup->end_time, backup->start_time));
@@ -453,12 +452,12 @@ show_instance_json(parray *backup_list)
453452
(uint32) (backup->stop_lsn >> 32), (uint32) backup->stop_lsn);
454453
json_add_value(buf, "stop-lsn", lsn, json_level, true);
455454

456-
time2iso(timestamp, lengthof(timestamp), backup->start_time, true);
455+
time2iso(timestamp, lengthof(timestamp), backup->start_time);
457456
json_add_value(buf, "start-time", timestamp, json_level, true);
458457

459458
if (backup->end_time)
460459
{
461-
time2iso(timestamp, lengthof(timestamp), backup->end_time, true);
460+
time2iso(timestamp, lengthof(timestamp), backup->end_time);
462461
json_add_value(buf, "end-time", timestamp, json_level, true);
463462
}
464463

@@ -467,8 +466,7 @@ show_instance_json(parray *backup_list)
467466

468467
if (backup->recovery_time > 0)
469468
{
470-
time2iso(timestamp, lengthof(timestamp), backup->recovery_time,
471-
true);
469+
time2iso(timestamp, lengthof(timestamp), backup->recovery_time);
472470
json_add_value(buf, "recovery-time", timestamp, json_level, true);
473471
}
474472

src/util.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,35 +194,31 @@ get_data_checksum_version(bool safe)
194194
* Convert time_t value to ISO-8601 format string
195195
*/
196196
void
197-
time2iso(char *buf, size_t len, time_t time, bool to_local)
197+
time2iso(char *buf, size_t len, time_t time)
198198
{
199199
struct tm *ptm = gmtime(&time);
200200
time_t gmt = mktime(ptm);
201201
time_t offset;
202202

203-
if (to_local)
204-
{
205-
char *ptr = buf;
206-
207-
ptm = localtime(&time);
208-
offset = time - gmt + (ptm->tm_isdst ? 3600 : 0);
203+
ptm = localtime(&time);
204+
offset = time - gmt + (ptm->tm_isdst ? 3600 : 0);
209205

210-
strftime(ptr, len, "%Y-%m-%d %H:%M:%S", ptm);
206+
strftime(buf, len, "%Y-%m-%d %H:%M:%S", ptm);
211207

212-
ptr += strlen(ptr);
213-
snprintf(ptr, len - (ptr - buf), "%c%02d",
208+
if (offset != 0)
209+
{
210+
buf += strlen(buf);
211+
sprintf(buf, "%c%02d",
214212
(offset >= 0) ? '+' : '-',
215213
abs((int) offset) / SECS_PER_HOUR);
216214

217215
if (abs((int) offset) % SECS_PER_HOUR != 0)
218216
{
219-
ptr += strlen(ptr);
220-
snprintf(ptr, len - (ptr - buf), ":%02d",
217+
buf += strlen(buf);
218+
sprintf(buf, ":%02d",
221219
abs((int) offset % SECS_PER_HOUR) / SECS_PER_MINUTE);
222220
}
223221
}
224-
else
225-
strftime(buf, len, "%Y-%m-%d %H:%M:%S+00", ptm);
226222
}
227223

228224
/* copied from timestamp.c */

0 commit comments

Comments
 (0)