mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 06:46:34 +00:00
Rename package 'server' to 'repo'
This commit is contained in:
parent
1d37fe3f97
commit
8be9e95d20
@ -15,7 +15,7 @@ import (
|
|||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/pack"
|
"github.com/restic/restic/pack"
|
||||||
"github.com/restic/restic/pipe"
|
"github.com/restic/restic/pipe"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
|
|
||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
)
|
)
|
||||||
@ -30,7 +30,7 @@ var archiverAllowAllFiles = func(string, os.FileInfo) bool { return true }
|
|||||||
|
|
||||||
// Archiver is used to backup a set of directories.
|
// Archiver is used to backup a set of directories.
|
||||||
type Archiver struct {
|
type Archiver struct {
|
||||||
s *server.Server
|
s *repo.Server
|
||||||
|
|
||||||
blobToken chan struct{}
|
blobToken chan struct{}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ type Archiver struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewArchiver returns a new archiver.
|
// NewArchiver returns a new archiver.
|
||||||
func NewArchiver(s *server.Server) *Archiver {
|
func NewArchiver(s *repo.Server) *Archiver {
|
||||||
arch := &Archiver{
|
arch := &Archiver{
|
||||||
s: s,
|
s: s,
|
||||||
blobToken: make(chan struct{}, maxConcurrentBlobs),
|
blobToken: make(chan struct{}, maxConcurrentBlobs),
|
||||||
|
6
cache.go
6
cache.go
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cache is used to locally cache items from a server.
|
// Cache is used to locally cache items from a server.
|
||||||
@ -18,7 +18,7 @@ type Cache struct {
|
|||||||
base string
|
base string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCache(s *server.Server) (*Cache, error) {
|
func NewCache(s *repo.Server) (*Cache, error) {
|
||||||
cacheDir, err := getCacheDir()
|
cacheDir, err := getCacheDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -106,7 +106,7 @@ func (c *Cache) purge(t backend.Type, subtype string, id backend.ID) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clear removes information from the cache that isn't present in the server any more.
|
// Clear removes information from the cache that isn't present in the server any more.
|
||||||
func (c *Cache) Clear(s *server.Server) error {
|
func (c *Cache) Clear(s *repo.Server) error {
|
||||||
list, err := c.list(backend.Snapshot)
|
list, err := c.list(backend.Snapshot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/pack"
|
"github.com/restic/restic/pack"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CmdCat struct{}
|
type CmdCat struct{}
|
||||||
@ -107,7 +107,7 @@ func (cmd CmdCat) Execute(args []string) error {
|
|||||||
|
|
||||||
dec := json.NewDecoder(rd)
|
dec := json.NewDecoder(rd)
|
||||||
|
|
||||||
var key server.Key
|
var key repo.Key
|
||||||
err = dec.Decode(&key)
|
err = dec.Decode(&key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/restic/restic"
|
"github.com/restic/restic"
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type findResult struct {
|
type findResult struct {
|
||||||
@ -59,7 +59,7 @@ func parseTime(str string) (time.Time, error) {
|
|||||||
return time.Time{}, fmt.Errorf("unable to parse time: %q", str)
|
return time.Time{}, fmt.Errorf("unable to parse time: %q", str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CmdFind) findInTree(s *server.Server, id backend.ID, path string) ([]findResult, error) {
|
func (c CmdFind) findInTree(s *repo.Server, id backend.ID, path string) ([]findResult, error) {
|
||||||
debug.Log("restic.find", "checking tree %v\n", id)
|
debug.Log("restic.find", "checking tree %v\n", id)
|
||||||
tree, err := restic.LoadTree(s, id)
|
tree, err := restic.LoadTree(s, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -105,7 +105,7 @@ func (c CmdFind) findInTree(s *server.Server, id backend.ID, path string) ([]fin
|
|||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CmdFind) findInSnapshot(s *server.Server, name string) error {
|
func (c CmdFind) findInSnapshot(s *repo.Server, name string) error {
|
||||||
debug.Log("restic.find", "searching in snapshot %s\n for entries within [%s %s]", name, c.oldest, c.newest)
|
debug.Log("restic.find", "searching in snapshot %s\n for entries within [%s %s]", name, c.oldest, c.newest)
|
||||||
|
|
||||||
id, err := backend.ParseID(name)
|
id, err := backend.ParseID(name)
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/restic/restic/crypto"
|
"github.com/restic/restic/crypto"
|
||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/pack"
|
"github.com/restic/restic/pack"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CmdFsck struct {
|
type CmdFsck struct {
|
||||||
@ -34,7 +34,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func fsckFile(opts CmdFsck, s *server.Server, IDs []backend.ID) (uint64, error) {
|
func fsckFile(opts CmdFsck, s *repo.Server, IDs []backend.ID) (uint64, error) {
|
||||||
debug.Log("restic.fsckFile", "checking file %v", IDs)
|
debug.Log("restic.fsckFile", "checking file %v", IDs)
|
||||||
var bytes uint64
|
var bytes uint64
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ func fsckFile(opts CmdFsck, s *server.Server, IDs []backend.ID) (uint64, error)
|
|||||||
return bytes, nil
|
return bytes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fsckTree(opts CmdFsck, s *server.Server, id backend.ID) error {
|
func fsckTree(opts CmdFsck, s *repo.Server, id backend.ID) error {
|
||||||
debug.Log("restic.fsckTree", "checking tree %v", id.Str())
|
debug.Log("restic.fsckTree", "checking tree %v", id.Str())
|
||||||
|
|
||||||
tree, err := restic.LoadTree(s, id)
|
tree, err := restic.LoadTree(s, id)
|
||||||
@ -157,7 +157,7 @@ func fsckTree(opts CmdFsck, s *server.Server, id backend.ID) error {
|
|||||||
return firstErr
|
return firstErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func fsckSnapshot(opts CmdFsck, s *server.Server, id backend.ID) error {
|
func fsckSnapshot(opts CmdFsck, s *repo.Server, id backend.ID) error {
|
||||||
debug.Log("restic.fsck", "checking snapshot %v\n", id)
|
debug.Log("restic.fsck", "checking snapshot %v\n", id)
|
||||||
|
|
||||||
sn, err := restic.LoadSnapshot(s, id)
|
sn, err := restic.LoadSnapshot(s, id)
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CmdKey struct{}
|
type CmdKey struct{}
|
||||||
@ -21,7 +21,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func listKeys(s *server.Server) error {
|
func listKeys(s *repo.Server) error {
|
||||||
tab := NewTable()
|
tab := NewTable()
|
||||||
tab.Header = fmt.Sprintf(" %-10s %-10s %-10s %s", "ID", "User", "Host", "Created")
|
tab.Header = fmt.Sprintf(" %-10s %-10s %-10s %s", "ID", "User", "Host", "Created")
|
||||||
tab.RowFormat = "%s%-10s %-10s %-10s %s"
|
tab.RowFormat = "%s%-10s %-10s %-10s %s"
|
||||||
@ -35,7 +35,7 @@ func listKeys(s *server.Server) error {
|
|||||||
defer close(done)
|
defer close(done)
|
||||||
|
|
||||||
for name := range s.List(backend.Key, done) {
|
for name := range s.List(backend.Key, done) {
|
||||||
k, err := server.LoadKey(s, name)
|
k, err := repo.LoadKey(s, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "LoadKey() failed: %v\n", err)
|
fmt.Fprintf(os.Stderr, "LoadKey() failed: %v\n", err)
|
||||||
continue
|
continue
|
||||||
@ -56,7 +56,7 @@ func listKeys(s *server.Server) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func addKey(s *server.Server) error {
|
func addKey(s *repo.Server) error {
|
||||||
pw := readPassword("RESTIC_NEWPASSWORD", "enter password for new key: ")
|
pw := readPassword("RESTIC_NEWPASSWORD", "enter password for new key: ")
|
||||||
pw2 := readPassword("RESTIC_NEWPASSWORD", "enter password again: ")
|
pw2 := readPassword("RESTIC_NEWPASSWORD", "enter password again: ")
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ func addKey(s *server.Server) error {
|
|||||||
return errors.New("passwords do not match")
|
return errors.New("passwords do not match")
|
||||||
}
|
}
|
||||||
|
|
||||||
id, err := server.AddKey(s, pw, s.Key())
|
id, err := repo.AddKey(s, pw, s.Key())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating new key failed: %v\n", err)
|
return fmt.Errorf("creating new key failed: %v\n", err)
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ func addKey(s *server.Server) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteKey(s *server.Server, name string) error {
|
func deleteKey(s *repo.Server, name string) error {
|
||||||
if name == s.KeyName() {
|
if name == s.KeyName() {
|
||||||
return errors.New("refusing to remove key currently used to access repository")
|
return errors.New("refusing to remove key currently used to access repository")
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ func deleteKey(s *server.Server, name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func changePassword(s *server.Server) error {
|
func changePassword(s *repo.Server) error {
|
||||||
pw := readPassword("RESTIC_NEWPASSWORD", "enter password for new key: ")
|
pw := readPassword("RESTIC_NEWPASSWORD", "enter password for new key: ")
|
||||||
pw2 := readPassword("RESTIC_NEWPASSWORD", "enter password again: ")
|
pw2 := readPassword("RESTIC_NEWPASSWORD", "enter password again: ")
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ func changePassword(s *server.Server) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add new key
|
// add new key
|
||||||
id, err := server.AddKey(s, pw, s.Key())
|
id, err := repo.AddKey(s, pw, s.Key())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating new key failed: %v\n", err)
|
return fmt.Errorf("creating new key failed: %v\n", err)
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/restic/restic"
|
"github.com/restic/restic"
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CmdLs struct{}
|
type CmdLs struct{}
|
||||||
@ -38,7 +38,7 @@ func printNode(prefix string, n *restic.Node) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func printTree(prefix string, s *server.Server, id backend.ID) error {
|
func printTree(prefix string, s *repo.Server, id backend.ID) error {
|
||||||
tree, err := restic.LoadTree(s, id)
|
tree, err := restic.LoadTree(s, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/restic/restic/backend/local"
|
"github.com/restic/restic/backend/local"
|
||||||
"github.com/restic/restic/backend/sftp"
|
"github.com/restic/restic/backend/sftp"
|
||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "compiled manually"
|
var version = "compiled manually"
|
||||||
@ -72,7 +72,7 @@ func (cmd CmdInit) Execute(args []string) error {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
s := server.NewServer(be)
|
s := repo.NewServer(be)
|
||||||
err = s.Init(pw)
|
err = s.Init(pw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "creating key in backend at %s failed: %v\n", opts.Repo, err)
|
fmt.Fprintf(os.Stderr, "creating key in backend at %s failed: %v\n", opts.Repo, err)
|
||||||
@ -133,7 +133,7 @@ func create(u string) (backend.Backend, error) {
|
|||||||
return sftp.Create(url.Path[1:], "ssh", args...)
|
return sftp.Create(url.Path[1:], "ssh", args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OpenRepo() (*server.Server, error) {
|
func OpenRepo() (*repo.Server, error) {
|
||||||
if opts.Repo == "" {
|
if opts.Repo == "" {
|
||||||
return nil, errors.New("Please specify repository location (-r)")
|
return nil, errors.New("Please specify repository location (-r)")
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ func OpenRepo() (*server.Server, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
s := server.NewServer(be)
|
s := repo.NewServer(be)
|
||||||
|
|
||||||
err = s.SearchKey(readPassword("RESTIC_PASSWORD", "enter password for repository: "))
|
err = s.SearchKey(readPassword("RESTIC_PASSWORD", "enter password for repository: "))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
8
node.go
8
node.go
@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/pack"
|
"github.com/restic/restic/pack"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Node is a file, directory or other item in a backup.
|
// Node is a file, directory or other item in a backup.
|
||||||
@ -43,7 +43,7 @@ type Node struct {
|
|||||||
|
|
||||||
path string
|
path string
|
||||||
err error
|
err error
|
||||||
blobs server.Blobs
|
blobs repo.Blobs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (node Node) String() string {
|
func (node Node) String() string {
|
||||||
@ -103,7 +103,7 @@ func nodeTypeFromFileInfo(fi os.FileInfo) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateAt creates the node at the given path and restores all the meta data.
|
// CreateAt creates the node at the given path and restores all the meta data.
|
||||||
func (node *Node) CreateAt(path string, s *server.Server) error {
|
func (node *Node) CreateAt(path string, s *repo.Server) error {
|
||||||
switch node.Type {
|
switch node.Type {
|
||||||
case "dir":
|
case "dir":
|
||||||
if err := node.createDirAt(path); err != nil {
|
if err := node.createDirAt(path); err != nil {
|
||||||
@ -176,7 +176,7 @@ func (node Node) createDirAt(path string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (node Node) createFileAt(path string, s *server.Server) error {
|
func (node Node) createFileAt(path string, s *repo.Server) error {
|
||||||
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600)
|
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0600)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package server
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
2
repo/doc.go
Normal file
2
repo/doc.go
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Package repo implements a restic repository on top of a backend.
|
||||||
|
package repo
|
@ -1,4 +1,4 @@
|
|||||||
package server
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
@ -1,4 +1,4 @@
|
|||||||
package server_test
|
package repo_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/pack"
|
"github.com/restic/restic/pack"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
. "github.com/restic/restic/test"
|
. "github.com/restic/restic/test"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ func TestIndexSerialize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
tests := []testEntry{}
|
tests := []testEntry{}
|
||||||
|
|
||||||
idx := server.NewIndex()
|
idx := repo.NewIndex()
|
||||||
|
|
||||||
// create 50 packs with 20 blobs each
|
// create 50 packs with 20 blobs each
|
||||||
for i := 0; i < 50; i++ {
|
for i := 0; i < 50; i++ {
|
||||||
@ -58,7 +58,7 @@ func TestIndexSerialize(t *testing.T) {
|
|||||||
err := idx.Encode(wr)
|
err := idx.Encode(wr)
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
idx2, err := server.DecodeIndex(wr)
|
idx2, err := repo.DecodeIndex(wr)
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
Assert(t, idx2 != nil,
|
Assert(t, idx2 != nil,
|
||||||
"nil returned for decoded index")
|
"nil returned for decoded index")
|
||||||
@ -113,7 +113,7 @@ func TestIndexSerialize(t *testing.T) {
|
|||||||
err = idx2.Encode(wr3)
|
err = idx2.Encode(wr3)
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
idx3, err := server.DecodeIndex(wr3)
|
idx3, err := repo.DecodeIndex(wr3)
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
Assert(t, idx3 != nil,
|
Assert(t, idx3 != nil,
|
||||||
"nil returned for decoded index")
|
"nil returned for decoded index")
|
||||||
@ -138,7 +138,7 @@ func TestIndexSerialize(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexSize(t *testing.T) {
|
func TestIndexSize(t *testing.T) {
|
||||||
idx := server.NewIndex()
|
idx := repo.NewIndex()
|
||||||
|
|
||||||
packs := 200
|
packs := 200
|
||||||
blobs := 100
|
blobs := 100
|
||||||
@ -210,7 +210,7 @@ var exampleTests = []struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIndexUnserialize(t *testing.T) {
|
func TestIndexUnserialize(t *testing.T) {
|
||||||
idx, err := server.DecodeIndex(bytes.NewReader(docExample))
|
idx, err := repo.DecodeIndex(bytes.NewReader(docExample))
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
for _, test := range exampleTests {
|
for _, test := range exampleTests {
|
@ -1,4 +1,4 @@
|
|||||||
package server
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
@ -1,4 +1,4 @@
|
|||||||
package server
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
@ -1,4 +1,4 @@
|
|||||||
package server
|
package repo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -1,4 +1,4 @@
|
|||||||
package server_test
|
package repo_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
@ -7,14 +7,14 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
|
|
||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Restorer is used to restore a snapshot to a directory.
|
// Restorer is used to restore a snapshot to a directory.
|
||||||
type Restorer struct {
|
type Restorer struct {
|
||||||
s *server.Server
|
s *repo.Server
|
||||||
sn *Snapshot
|
sn *Snapshot
|
||||||
|
|
||||||
Error func(dir string, node *Node, err error) error
|
Error func(dir string, node *Node, err error) error
|
||||||
@ -24,7 +24,7 @@ type Restorer struct {
|
|||||||
var restorerAbortOnAllErrors = func(str string, node *Node, err error) error { return err }
|
var restorerAbortOnAllErrors = func(str string, node *Node, err error) error { return err }
|
||||||
|
|
||||||
// NewRestorer creates a restorer preloaded with the content from the snapshot id.
|
// NewRestorer creates a restorer preloaded with the content from the snapshot id.
|
||||||
func NewRestorer(s *server.Server, id backend.ID) (*Restorer, error) {
|
func NewRestorer(s *repo.Server, id backend.ID) (*Restorer, error) {
|
||||||
r := &Restorer{s: s, Error: restorerAbortOnAllErrors}
|
r := &Restorer{s: s, Error: restorerAbortOnAllErrors}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
// Package server implements a restic repository on top of a backend.
|
|
||||||
package server
|
|
@ -9,7 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Snapshot struct {
|
type Snapshot struct {
|
||||||
@ -50,7 +50,7 @@ func NewSnapshot(paths []string) (*Snapshot, error) {
|
|||||||
return sn, nil
|
return sn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadSnapshot(s *server.Server, id backend.ID) (*Snapshot, error) {
|
func LoadSnapshot(s *repo.Server, id backend.ID) (*Snapshot, error) {
|
||||||
sn := &Snapshot{id: id}
|
sn := &Snapshot{id: id}
|
||||||
err := s.LoadJSONUnpacked(backend.Snapshot, id, sn)
|
err := s.LoadJSONUnpacked(backend.Snapshot, id, sn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -10,14 +10,14 @@ import (
|
|||||||
"github.com/restic/restic"
|
"github.com/restic/restic"
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/backend/local"
|
"github.com/restic/restic/backend/local"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var TestPassword = flag.String("test.password", "", `use this password for repositories created during tests (default: "geheim")`)
|
var TestPassword = flag.String("test.password", "", `use this password for repositories created during tests (default: "geheim")`)
|
||||||
var TestCleanup = flag.Bool("test.cleanup", true, "clean up after running tests (remove local backend directory with all content)")
|
var TestCleanup = flag.Bool("test.cleanup", true, "clean up after running tests (remove local backend directory with all content)")
|
||||||
var TestTempDir = flag.String("test.tempdir", "", "use this directory for temporary storage (default: system temp dir)")
|
var TestTempDir = flag.String("test.tempdir", "", "use this directory for temporary storage (default: system temp dir)")
|
||||||
|
|
||||||
func SetupBackend(t testing.TB) *server.Server {
|
func SetupBackend(t testing.TB) *repo.Server {
|
||||||
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
|
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
@ -29,12 +29,12 @@ func SetupBackend(t testing.TB) *server.Server {
|
|||||||
err = os.Setenv("RESTIC_CACHE", filepath.Join(tempdir, "cache"))
|
err = os.Setenv("RESTIC_CACHE", filepath.Join(tempdir, "cache"))
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
s := server.NewServer(b)
|
s := repo.NewServer(b)
|
||||||
OK(t, s.Init(*TestPassword))
|
OK(t, s.Init(*TestPassword))
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func TeardownBackend(t testing.TB, s *server.Server) {
|
func TeardownBackend(t testing.TB, s *repo.Server) {
|
||||||
if !*TestCleanup {
|
if !*TestCleanup {
|
||||||
l := s.Backend().(*local.Local)
|
l := s.Backend().(*local.Local)
|
||||||
t.Logf("leaving local backend at %s\n", l.Location())
|
t.Logf("leaving local backend at %s\n", l.Location())
|
||||||
@ -44,7 +44,7 @@ func TeardownBackend(t testing.TB, s *server.Server) {
|
|||||||
OK(t, s.Delete())
|
OK(t, s.Delete())
|
||||||
}
|
}
|
||||||
|
|
||||||
func SnapshotDir(t testing.TB, server *server.Server, path string, parent backend.ID) *restic.Snapshot {
|
func SnapshotDir(t testing.TB, server *repo.Server, path string, parent backend.ID) *restic.Snapshot {
|
||||||
arch := restic.NewArchiver(server)
|
arch := restic.NewArchiver(server)
|
||||||
sn, _, err := arch.Snapshot(nil, []string{path}, parent)
|
sn, _, err := arch.Snapshot(nil, []string{path}, parent)
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
4
tree.go
4
tree.go
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/pack"
|
"github.com/restic/restic/pack"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Tree struct {
|
type Tree struct {
|
||||||
@ -30,7 +30,7 @@ func (t Tree) String() string {
|
|||||||
return fmt.Sprintf("Tree<%d nodes>", len(t.Nodes))
|
return fmt.Sprintf("Tree<%d nodes>", len(t.Nodes))
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadTree(s *server.Server, id backend.ID) (*Tree, error) {
|
func LoadTree(s *repo.Server, id backend.ID) (*Tree, error) {
|
||||||
tree := &Tree{}
|
tree := &Tree{}
|
||||||
err := s.LoadJSONPack(pack.Tree, id, tree)
|
err := s.LoadJSONPack(pack.Tree, id, tree)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
6
walk.go
6
walk.go
@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/debug"
|
"github.com/restic/restic/debug"
|
||||||
"github.com/restic/restic/server"
|
"github.com/restic/restic/repo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WalkTreeJob struct {
|
type WalkTreeJob struct {
|
||||||
@ -16,7 +16,7 @@ type WalkTreeJob struct {
|
|||||||
Tree *Tree
|
Tree *Tree
|
||||||
}
|
}
|
||||||
|
|
||||||
func walkTree(s *server.Server, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
|
func walkTree(s *repo.Server, path string, treeID backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
|
||||||
debug.Log("walkTree", "start on %q (%v)", path, treeID.Str())
|
debug.Log("walkTree", "start on %q (%v)", path, treeID.Str())
|
||||||
|
|
||||||
t, err := LoadTree(s, treeID)
|
t, err := LoadTree(s, treeID)
|
||||||
@ -41,7 +41,7 @@ func walkTree(s *server.Server, path string, treeID backend.ID, done chan struct
|
|||||||
// WalkTree walks the tree specified by id recursively and sends a job for each
|
// WalkTree walks the tree specified by id recursively and sends a job for each
|
||||||
// file and directory it finds. When the channel done is closed, processing
|
// file and directory it finds. When the channel done is closed, processing
|
||||||
// stops.
|
// stops.
|
||||||
func WalkTree(server *server.Server, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
|
func WalkTree(server *repo.Server, id backend.ID, done chan struct{}, jobCh chan<- WalkTreeJob) {
|
||||||
debug.Log("WalkTree", "start on %v", id.Str())
|
debug.Log("WalkTree", "start on %v", id.Str())
|
||||||
walkTree(server, "", id, done, jobCh)
|
walkTree(server, "", id, done, jobCh)
|
||||||
close(jobCh)
|
close(jobCh)
|
||||||
|
Loading…
Reference in New Issue
Block a user