diff options
| author | Jeff Carr <[email protected]> | 2024-10-27 06:05:49 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-10-27 06:05:49 -0500 |
| commit | 3a9e77a4fb25bea7de28a29300c5ab032e6d4765 (patch) | |
| tree | 835922ad0e61f474b896525838d0036cbd4c47ee /config.go | |
| parent | dc2dba26556d507bc929056755395cc51fcc7d9e (diff) | |
backup the cluster config files
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -8,6 +8,7 @@ import ( "fmt" "os" "path/filepath" + "time" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/encoding/prototext" @@ -19,6 +20,12 @@ import ( func (c *Cluster) ConfigSave() error { var d *Droplets d = new(Droplets) + + // try to backup the current cluster config files + if err := backupConfigFiles(); err != nil { + return err + } + d.Droplets = c.Droplets if err := ConfigWriteJSON(d, "newdroplets.json"); err != nil { fmt.Println("droplets.json write failed") @@ -71,6 +78,16 @@ func (c *Cluster) ConfigSave() error { return nil } +func backupConfigFiles() error { + // make a new dir to backup the files + now := time.Now() + timestamp := now.Format("2006.01.02.150405") + srcDir := filepath.Join(os.Getenv("VIRTIGO_HOME")) + destDir := filepath.Join(os.Getenv("VIRTIGO_HOME"), timestamp) + + return backupFiles(srcDir, destDir) +} + func (c *Cluster) ConfigLoadOld() error { if c == nil { return errors.New("It's not safe to run ConfigLoad() on a nil cluster") @@ -108,7 +125,6 @@ func (c *Cluster) ConfigLoadOld() error { return nil } - func (c *Cluster) ConfigLoad() error { if c == nil { return errors.New("It's not safe to run ConfigLoad() on a nil cluster") |
