summaryrefslogtreecommitdiff
path: root/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'config.go')
-rw-r--r--config.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/config.go b/config.go
index 99ce67f..6185010 100644
--- a/config.go
+++ b/config.go
@@ -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")