From e16ca45fa7827c3d5dbc60d06055aba5df6e9c32 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sun, 22 Jan 2023 18:50:27 +0100 Subject: [PATCH] fix!: better backup file names Closes https://git.coopcloud.tech/coop-cloud/organising/issues/366 --- cli/app/backup.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cli/app/backup.go b/cli/app/backup.go index 55877b8c..662b80a7 100644 --- a/cli/app/backup.go +++ b/cli/app/backup.go @@ -7,7 +7,6 @@ import ( "io" "os" "path/filepath" - "strconv" "strings" "time" @@ -133,6 +132,12 @@ This single file can be used to restore your app. See "abra app restore" for mor }, } +// TimeStamp generates a file name friendly timestamp. +func TimeStamp() string { + ts := time.Now().UTC().Format(time.RFC3339) + return strings.Replace(ts, ":", "-", -1) +} + // runBackup does the actual backup logic. func runBackup(app config.App, serviceName string, bkConfig backupConfig) error { if len(bkConfig.backupPaths) == 0 { @@ -182,9 +187,8 @@ func runBackup(app config.App, serviceName string, bkConfig backupConfig) error var tempBackupPaths []string for _, remoteBackupPath := range bkConfig.backupPaths { - timestamp := strconv.Itoa(time.Now().Nanosecond()) sanitisedPath := strings.ReplaceAll(remoteBackupPath, "/", "_") - localBackupPath := filepath.Join(config.BACKUP_DIR, fmt.Sprintf("%s%s_%s.tar.gz", fullServiceName, sanitisedPath, timestamp)) + localBackupPath := filepath.Join(config.BACKUP_DIR, fmt.Sprintf("%s%s_%s.tar.gz", fullServiceName, sanitisedPath, TimeStamp())) logrus.Debugf("temporarily backing up %s:%s to %s", fullServiceName, remoteBackupPath, localBackupPath) logrus.Infof("backing up %s:%s", fullServiceName, remoteBackupPath) @@ -290,8 +294,7 @@ func mergeArchives(tarPaths []string, serviceName string) error { var out io.Writer var cout *pgzip.Writer - timestamp := strconv.Itoa(time.Now().Nanosecond()) - localBackupPath := filepath.Join(config.BACKUP_DIR, fmt.Sprintf("%s_%s.tar.gz", serviceName, timestamp)) + localBackupPath := filepath.Join(config.BACKUP_DIR, fmt.Sprintf("%s_%s.tar.gz", serviceName, TimeStamp())) fout, err := os.Create(localBackupPath) if err != nil {