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 {