Rename backups => snapshot

This commit is contained in:
Tom Wiesing 2022-09-07 11:02:50 +02:00
parent 611cbeebb9
commit d818cb93a5
No known key found for this signature in database
8 changed files with 178 additions and 166 deletions

52
env/backup.go vendored
View file

@ -1,52 +0,0 @@
package env
import (
"fmt"
"os"
"path/filepath"
"sync/atomic"
"time"
)
func (dis Distillery) BackupDir() string {
return filepath.Join(dis.Config.DeployRoot, "backups")
}
func (dis Distillery) InprogressBackupPath() string {
return filepath.Join(dis.BackupDir(), "inprogress")
}
func (dis Distillery) FinalBackupPath() string {
return filepath.Join(dis.BackupDir(), "final")
}
// NewFinalBackupFile returns the path to a new final backup file.
func (dis Distillery) FinalBackupArchive(prefix string) string {
counter := atomic.AddUint64(&globalBackupCounter, 1)
// generate a new name with the current time, a global counter, and the prefix
name := fmt.Sprintf("%s-%d-%d.tar.gz", prefix, time.Now().Unix(), counter)
path := filepath.Join(dis.FinalBackupPath(), name)
return path
}
var globalBackupCounter uint64
// NewInprogressBackupPath returns the path to a new inprogress backup directory.
// The directory is guaranteed to have been freshly created.
func (dis Distillery) NewInprogressBackupPath(prefix string) (string, error) {
counter := atomic.AddUint64(&globalBackupCounter, 1)
// generate a new name with the current time, a global counter, and the prefix
name := fmt.Sprintf("%s-%d-%d", prefix, time.Now().Unix(), counter)
path := filepath.Join(dis.InprogressBackupPath(), name)
// create the directory
if err := os.Mkdir(path, os.ModeDir); err != nil {
return "", err
}
// and it is here!
return path, nil
}