From b750e1e9f7fa16126e3e1a26ed43e1a43e78ce04 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 23 Jan 2017 11:47:17 -0800 Subject: adding untracked files for recent basic auth and backup features --- system/api/analytics/backup.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 system/api/analytics/backup.go (limited to 'system/api/analytics/backup.go') diff --git a/system/api/analytics/backup.go b/system/api/analytics/backup.go new file mode 100644 index 0000000..07b1a46 --- /dev/null +++ b/system/api/analytics/backup.go @@ -0,0 +1,26 @@ +package analytics + +import ( + "fmt" + "net/http" + "time" + + "github.com/boltdb/bolt" +) + +// Backup writes a snapshot of the analytics.db database to an HTTP response +func Backup(res http.ResponseWriter) error { + err := store.View(func(tx *bolt.Tx) error { + ts := time.Now().Unix() + disposition := `attachment; filename="analytics-%d.db.bak"` + + res.Header().Set("Content-Type", "application/octet-stream") + res.Header().Set("Content-Disposition", fmt.Sprintf(disposition, ts)) + res.Header().Set("Content-Length", fmt.Sprintf("%d", int(tx.Size()))) + + _, err := tx.WriteTo(res) + return err + }) + + return err +} -- cgit v1.2.3