diff options
author | Steve Manuel <nilslice@gmail.com> | 2017-01-23 11:47:17 -0800 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2017-01-23 11:47:17 -0800 |
commit | b750e1e9f7fa16126e3e1a26ed43e1a43e78ce04 (patch) | |
tree | f76f624b3633e5a03e336ada0a37cb0ff3afa210 /system/db/backup.go | |
parent | 964479e5ce756aa48755dc3de35b4d82326f149f (diff) |
adding untracked files for recent basic auth and backup features
Diffstat (limited to 'system/db/backup.go')
-rw-r--r-- | system/db/backup.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/system/db/backup.go b/system/db/backup.go new file mode 100644 index 0000000..735abe4 --- /dev/null +++ b/system/db/backup.go @@ -0,0 +1,26 @@ +package db + +import ( + "fmt" + "net/http" + "time" + + "github.com/boltdb/bolt" +) + +// Backup writes a snapshot of the system.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="system-%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 +} |