fix: better backup file names #260
@ -7,7 +7,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -120,6 +119,10 @@ This single file can be used to restore your app. See "abra app restore" for mor
|
|||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if len(backupConfigs) == 0 {
|
||||||
|
logrus.Fatalf("no backup configs discovered for %s?", app.Name)
|
||||||
|
}
|
||||||
|
|
||||||
for serviceName, backupConfig := range backupConfigs {
|
for serviceName, backupConfig := range backupConfigs {
|
||||||
logrus.Infof("running backup for the %s service", serviceName)
|
logrus.Infof("running backup for the %s service", serviceName)
|
||||||
|
|
||||||
@ -133,6 +136,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.
|
// runBackup does the actual backup logic.
|
||||||
func runBackup(app config.App, serviceName string, bkConfig backupConfig) error {
|
func runBackup(app config.App, serviceName string, bkConfig backupConfig) error {
|
||||||
if len(bkConfig.backupPaths) == 0 {
|
if len(bkConfig.backupPaths) == 0 {
|
||||||
@ -182,9 +191,8 @@ func runBackup(app config.App, serviceName string, bkConfig backupConfig) error
|
|||||||
|
|
||||||
var tempBackupPaths []string
|
var tempBackupPaths []string
|
||||||
for _, remoteBackupPath := range bkConfig.backupPaths {
|
for _, remoteBackupPath := range bkConfig.backupPaths {
|
||||||
timestamp := strconv.Itoa(time.Now().Nanosecond())
|
|
||||||
sanitisedPath := strings.ReplaceAll(remoteBackupPath, "/", "_")
|
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.Debugf("temporarily backing up %s:%s to %s", fullServiceName, remoteBackupPath, localBackupPath)
|
||||||
|
|
||||||
logrus.Infof("backing up %s:%s", fullServiceName, remoteBackupPath)
|
logrus.Infof("backing up %s:%s", fullServiceName, remoteBackupPath)
|
||||||
@ -290,8 +298,7 @@ func mergeArchives(tarPaths []string, serviceName string) error {
|
|||||||
var out io.Writer
|
var out io.Writer
|
||||||
var cout *pgzip.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)
|
fout, err := os.Create(localBackupPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user