Implement initial 'wdcli backup_instance' command
This commit performs an initial implementation of the 'backup_instance' command.
This commit is contained in:
parent
a64c02cd78
commit
2a14d93d3c
17 changed files with 437 additions and 135 deletions
52
env/backup.go
vendored
Normal file
52
env/backup.go
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue