diff --git a/src/backup.c b/src/backup.c index 666e8acc..420bcb78 100644 --- a/src/backup.c +++ b/src/backup.c @@ -553,7 +553,7 @@ do_backup_instance(void) pg_ptrack_clear(); /* notify start of backup to PostgreSQL server */ - time2iso(label, lengthof(label), current.start_time, true); + time2iso(label, lengthof(label), current.start_time); strncat(label, " with pg_probackup", lengthof(label) - strlen(" with pg_probackup")); pg_start_backup(label, smooth_checkpoint, ¤t); diff --git a/src/catalog.c b/src/catalog.c index 9b3339dd..a0a8e5dc 100644 --- a/src/catalog.c +++ b/src/catalog.c @@ -409,17 +409,17 @@ pgBackupWriteControl(FILE *out, pgBackup *backup) (uint32) (backup->stop_lsn >> 32), (uint32) backup->stop_lsn); - time2iso(timestamp, lengthof(timestamp), backup->start_time, false); + time2iso(timestamp, lengthof(timestamp), backup->start_time); fprintf(out, "start-time = '%s'\n", timestamp); if (backup->end_time > 0) { - time2iso(timestamp, lengthof(timestamp), backup->end_time, false); + time2iso(timestamp, lengthof(timestamp), backup->end_time); fprintf(out, "end-time = '%s'\n", timestamp); } fprintf(out, "recovery-xid = " XID_FMT "\n", backup->recovery_xid); if (backup->recovery_time > 0) { - time2iso(timestamp, lengthof(timestamp), backup->recovery_time, false); + time2iso(timestamp, lengthof(timestamp), backup->recovery_time); fprintf(out, "recovery-time = '%s'\n", timestamp); } diff --git a/src/delete.c b/src/delete.c index 5b5c79c7..f81fe70d 100644 --- a/src/delete.c +++ b/src/delete.c @@ -257,7 +257,7 @@ pgBackupDeleteFiles(pgBackup *backup) if (backup->status == BACKUP_STATUS_DELETED) return 0; - time2iso(timestamp, lengthof(timestamp), backup->recovery_time, true); + time2iso(timestamp, lengthof(timestamp), backup->recovery_time); elog(INFO, "delete: %s %s", base36enc(backup->start_time), timestamp); diff --git a/src/parsexlog.c b/src/parsexlog.c index a83acfe6..a0079b42 100644 --- a/src/parsexlog.c +++ b/src/parsexlog.c @@ -380,8 +380,7 @@ validate_wal(pgBackup *backup, xlogfpath[0] = '\0'; /* We can restore at least up to the backup end */ - time2iso(last_timestamp, lengthof(last_timestamp), backup->recovery_time, - true); + time2iso(last_timestamp, lengthof(last_timestamp), backup->recovery_time); last_xid = backup->recovery_xid; if ((TransactionIdIsValid(target_xid) && target_xid == last_xid) @@ -431,7 +430,7 @@ validate_wal(pgBackup *backup, if (last_time > 0) time2iso(last_timestamp, lengthof(last_timestamp), - timestamptz_to_time_t(last_time), true); + timestamptz_to_time_t(last_time)); /* There are all needed WAL records */ if (all_wal) @@ -460,8 +459,8 @@ validate_wal(pgBackup *backup, last_timestamp, last_xid); if (target_time > 0) - time2iso(target_timestamp, lengthof(target_timestamp), target_time, - true); + time2iso(target_timestamp, lengthof(target_timestamp), + target_time); if (TransactionIdIsValid(target_xid) && target_time != 0) elog(ERROR, "not enough WAL records to time %s and xid " XID_FMT, target_timestamp, target_xid); diff --git a/src/pg_probackup.h b/src/pg_probackup.h index 0a3be70b..75788cd7 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -521,7 +521,7 @@ extern bool wal_contains_lsn(const char *archivedir, XLogRecPtr target_lsn, /* in util.c */ extern TimeLineID get_current_timeline(bool safe); extern void sanityChecks(void); -extern void time2iso(char *buf, size_t len, time_t time, bool to_local); +extern void time2iso(char *buf, size_t len, time_t time); extern const char *status2str(BackupStatus status); extern void remove_trailing_space(char *buf, int comment_mark); extern void remove_not_digit(char *buf, size_t len, const char *str); diff --git a/src/restore.c b/src/restore.c index 1c295d23..a39b5127 100644 --- a/src/restore.c +++ b/src/restore.c @@ -122,8 +122,7 @@ do_restore_or_validate(time_t target_backup_id, pgRecoveryTarget *rt, current_backup = (pgBackup *) parray_get(backups, i); /* Skip all backups which started after target backup */ - if (target_backup_id != INVALID_BACKUP_ID && - current_backup->start_time > target_backup_id) + if (target_backup_id && current_backup->start_time > target_backup_id) continue; /* @@ -382,7 +381,7 @@ restore_backup(pgBackup *backup) "XLOG_BLCKSZ(%d) is not compatible(%d expected)", backup->wal_block_size, XLOG_BLCKSZ); - time2iso(timestamp, lengthof(timestamp), backup->start_time, true); + time2iso(timestamp, lengthof(timestamp), backup->start_time); elog(LOG, "restoring database from backup %s", timestamp); /* diff --git a/src/show.c b/src/show.c index d783ba06..01a558e0 100644 --- a/src/show.c +++ b/src/show.c @@ -324,8 +324,7 @@ show_instance_plain(parray *backup_list, bool show_name) char data_bytes_str[10] = "----"; if (backup->recovery_time != (time_t) 0) - time2iso(timestamp, lengthof(timestamp), backup->recovery_time, - true); + time2iso(timestamp, lengthof(timestamp), backup->recovery_time); if (backup->end_time != (time_t) 0) snprintf(duration, lengthof(duration), "%.*lfs", 0, difftime(backup->end_time, backup->start_time)); @@ -453,12 +452,12 @@ show_instance_json(parray *backup_list) (uint32) (backup->stop_lsn >> 32), (uint32) backup->stop_lsn); json_add_value(buf, "stop-lsn", lsn, json_level, true); - time2iso(timestamp, lengthof(timestamp), backup->start_time, true); + time2iso(timestamp, lengthof(timestamp), backup->start_time); json_add_value(buf, "start-time", timestamp, json_level, true); if (backup->end_time) { - time2iso(timestamp, lengthof(timestamp), backup->end_time, true); + time2iso(timestamp, lengthof(timestamp), backup->end_time); json_add_value(buf, "end-time", timestamp, json_level, true); } @@ -467,8 +466,7 @@ show_instance_json(parray *backup_list) if (backup->recovery_time > 0) { - time2iso(timestamp, lengthof(timestamp), backup->recovery_time, - true); + time2iso(timestamp, lengthof(timestamp), backup->recovery_time); json_add_value(buf, "recovery-time", timestamp, json_level, true); } diff --git a/src/util.c b/src/util.c index 7893f3da..a43239dc 100644 --- a/src/util.c +++ b/src/util.c @@ -194,35 +194,31 @@ get_data_checksum_version(bool safe) * Convert time_t value to ISO-8601 format string */ void -time2iso(char *buf, size_t len, time_t time, bool to_local) +time2iso(char *buf, size_t len, time_t time) { struct tm *ptm = gmtime(&time); time_t gmt = mktime(ptm); time_t offset; - if (to_local) + ptm = localtime(&time); + offset = time - gmt + (ptm->tm_isdst ? 3600 : 0); + + strftime(buf, len, "%Y-%m-%d %H:%M:%S", ptm); + + if (offset != 0) { - char *ptr = buf; - - ptm = localtime(&time); - offset = time - gmt + (ptm->tm_isdst ? 3600 : 0); - - strftime(ptr, len, "%Y-%m-%d %H:%M:%S", ptm); - - ptr += strlen(ptr); - snprintf(ptr, len - (ptr - buf), "%c%02d", + buf += strlen(buf); + sprintf(buf, "%c%02d", (offset >= 0) ? '+' : '-', abs((int) offset) / SECS_PER_HOUR); if (abs((int) offset) % SECS_PER_HOUR != 0) { - ptr += strlen(ptr); - snprintf(ptr, len - (ptr - buf), ":%02d", + buf += strlen(buf); + sprintf(buf, ":%02d", abs((int) offset % SECS_PER_HOUR) / SECS_PER_MINUTE); } } - else - strftime(buf, len, "%Y-%m-%d %H:%M:%S+00", ptm); } /* copied from timestamp.c */