Added backup machinery
This commit is contained in:
@ -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
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ type Storage interface {
|
||||
// GetQURL(uint64) (*qurl.QURL, error)
|
||||
GetQURLByURL(string) (*qurl.QURL, error)
|
||||
SetQURLSequence(uint64) error
|
||||
Backup(string) error
|
||||
Shutdown()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user