Added backup machinery

This commit is contained in:
2018-11-19 03:28:44 +00:00
committed by cdramey
parent 90e419f5a4
commit 206eb2f149
4 changed files with 56 additions and 11 deletions

View File

@ -4,6 +4,7 @@ import (
bolt "go.etcd.io/bbolt"
"net/url"
"time"
"os"
)
type BoltStorage struct {
@ -26,3 +27,17 @@ func New(u *url.URL) (*BoltStorage, error) {
}
return &BoltStorage{DB: db}, nil
}
func (stor *BoltStorage) Backup(bpath string) error {
tx, err := stor.DB.Begin(false)
if err != nil {
return err
}
defer tx.Rollback()
err = tx.CopyFile(bpath, os.FileMode(0600))
if err != nil {
return err
}
return nil
}

View File

@ -13,6 +13,7 @@ type Storage interface {
// GetQURL(uint64) (*qurl.QURL, error)
GetQURLByURL(string) (*qurl.QURL, error)
SetQURLSequence(uint64) error
Backup(string) error
Shutdown()
}