Skip to content

Commit c46dfab

Browse files
committed
respect local timezone when show backup time in list, fix #1185
Signed-off-by: Slach <[email protected]>
1 parent d5fa1f2 commit c46dfab

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# v2.6.29
2+
BUG FIXES
3+
- respect local timezone when show backup time in list, fix [1185](https://github.com/Altinity/clickhouse-backup/issues/1185)
4+
15
# v2.6.28
26
BUG FIXES
37
- time layout for watch backup name shall respect TZ environment variable, fix [1184](https://github.com/Altinity/clickhouse-backup/issues/1184)

pkg/backup/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type LocalBackup struct {
5353

5454
// NewBackupName - return default backup name
5555
func NewBackupName() string {
56-
return time.Now().UTC().Format(TimeFormatForBackup)
56+
return time.Now().Format(TimeFormatForBackup)
5757
}
5858

5959
// CreateBackup - create new backup of all tables matched by tablePattern
@@ -996,7 +996,7 @@ func (b *Backuper) createBackupMetadata(ctx context.Context, backupMetaFile, bac
996996
Disks: diskMap,
997997
DiskTypes: diskTypes,
998998
ClickhouseBackupVersion: version,
999-
CreationDate: time.Now().UTC(),
999+
CreationDate: time.Now(),
10001000
Tags: tags,
10011001
ClickHouseVersion: b.ch.GetVersionDescribe(ctx),
10021002
DataSize: backupDataSize,

pkg/backup/list.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"sort"
2020
"strings"
2121
"text/tabwriter"
22+
"time"
2223
)
2324

2425
// List - list backups to stdout from command line
@@ -51,7 +52,7 @@ func printBackupsRemote(w io.Writer, backupList []storage.Backup, format string)
5152
for _, backup := range backupList {
5253
size := fmt.Sprintf("all:%s,data:%s,arch:%s,obj:%s,meta:%s,rbac:%s,conf:%s", utils.FormatBytes(backup.GetFullSize()), utils.FormatBytes(backup.DataSize), utils.FormatBytes(backup.CompressedSize), utils.FormatBytes(backup.ObjectDiskSize), utils.FormatBytes(backup.MetadataSize), utils.FormatBytes(backup.RBACSize), utils.FormatBytes(backup.ConfigSize))
5354
description := backup.DataFormat
54-
uploadDate := backup.UploadDate.Format("02/01/2006 15:04:05")
55+
uploadDate := backup.UploadDate.In(time.Local).Format("2006-02-01 15:04:05")
5556
if backup.Tags != "" {
5657
description += ", " + backup.Tags
5758
}
@@ -99,7 +100,7 @@ func printBackupsLocal(ctx context.Context, w io.Writer, backupList []LocalBacku
99100
}
100101
description += backup.Tags
101102
}
102-
creationDate := backup.CreationDate.Format("02/01/2006 15:04:05")
103+
creationDate := backup.CreationDate.In(time.Local).Format("2006-02-01 15:04:05")
103104
required := ""
104105
if backup.RequiredBackup != "" {
105106
required = "+" + backup.RequiredBackup

pkg/pidlock/pidlock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func CheckAndCreatePidFile(backupName string, command string) error {
3434
}
3535

3636
// Write new PID file
37-
pid := fmt.Sprintf("%d|%s|%s", os.Getpid(), command, time.Now().UTC().Format(time.RFC3339))
37+
pid := fmt.Sprintf("%d|%s|%s", os.Getpid(), command, time.Now().Format(time.RFC3339))
3838
return os.WriteFile(pidPath, []byte(pid), 0644)
3939
}
4040

pkg/server/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ func (api *APIServer) httpListHandler(w http.ResponseWriter, r *http.Request) {
855855
}
856856
backupsJSON = append(backupsJSON, backupJSON{
857857
Name: item.BackupName,
858-
Created: item.CreationDate.Format(common.TimeFormat),
858+
Created: item.CreationDate.In(time.Local).Format(common.TimeFormat),
859859
Size: item.GetFullSize(),
860860
DataSize: item.DataSize,
861861
ObjectDiskSize: item.ObjectDiskSize,
@@ -892,7 +892,7 @@ func (api *APIServer) httpListHandler(w http.ResponseWriter, r *http.Request) {
892892
fullSize := item.GetFullSize()
893893
backupsJSON = append(backupsJSON, backupJSON{
894894
Name: item.BackupName,
895-
Created: item.CreationDate.Format(common.TimeFormat),
895+
Created: item.CreationDate.In(time.Local).Format(common.TimeFormat),
896896
Size: fullSize,
897897
DataSize: item.DataSize,
898898
ObjectDiskSize: item.ObjectDiskSize,

0 commit comments

Comments
 (0)