From b9910c6e529067e49da7831be0c9defe9ff6af80 Mon Sep 17 00:00:00 2001 From: Luke Morris Date: Sat, 16 Dec 2017 13:32:21 -0800 Subject: [PATCH] Output backups to backup/ directory --- bolt/client.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bolt/client.go b/bolt/client.go index 4fc5d64928..2cee7b29a2 100644 --- a/bolt/client.go +++ b/bolt/client.go @@ -2,6 +2,7 @@ package bolt import ( "context" + "fmt" "io" "log" "os" @@ -162,8 +163,12 @@ func (c *Client) Backup(ctx context.Context, build chronograf.BuildInfo) error { } defer from.Close() - toName := c.Path + "." + lastBuild.Version + ".backup" - to, err := os.OpenFile(toName, os.O_RDWR|os.O_CREATE, 0666) + backupDir := path.Join(path.Dir(c.Path), "backup") + _ = os.Mkdir(backupDir, 0700) + + toName := fmt.Sprintf("%s.%s", c.Path, lastBuild.Version) + toPath := path.Join(backupDir, toName) + to, err := os.OpenFile(toPath, os.O_RDWR|os.O_CREATE, 0600) if err != nil { log.Fatal(err) } @@ -178,7 +183,7 @@ func (c *Client) Backup(ctx context.Context, build chronograf.BuildInfo) error { log.Fatal(err) } - log.Printf("Successfully created backup of bolt database") + log.Printf("Successfully created %s", toPath) return nil }