restic/src/restic/backend/s3/s3.go

338 lines
7.5 KiB
Go
Raw Normal View History

2015-05-10 17:20:58 +02:00
package s3
import (
s3: Use low-level API with a Range header for Load benchmark old ns/op new ns/op delta BenchmarkBackendMinio/LoadFile-4 9213315 11001787 +19.41% BenchmarkBackendMinio/LoadPartialFile-4 4176619 3479707 -16.69% BenchmarkBackendMinio/LoadPartialFileOffset-4 4391521 3139214 -28.52% BenchmarkBackendS3/LoadFile-4 2886070905 2505907501 -13.17% BenchmarkBackendS3/LoadPartialFile-4 762702722 735694398 -3.54% BenchmarkBackendS3/LoadPartialFileOffset-4 789724328 1108989142 +40.43% benchmark old MB/s new MB/s speedup BenchmarkBackendMinio/LoadFile-4 1821.21 1525.15 0.84x BenchmarkBackendMinio/LoadPartialFile-4 1004.49 1205.67 1.20x BenchmarkBackendMinio/LoadPartialFileOffset-4 955.34 1336.45 1.40x BenchmarkBackendS3/LoadFile-4 5.81 6.70 1.15x BenchmarkBackendS3/LoadPartialFile-4 5.50 5.70 1.04x BenchmarkBackendS3/LoadPartialFileOffset-4 5.31 3.78 0.71x benchmark old allocs new allocs delta BenchmarkBackendMinio/LoadFile-4 406 204 -49.75% BenchmarkBackendMinio/LoadPartialFile-4 225 206 -8.44% BenchmarkBackendMinio/LoadPartialFileOffset-4 227 207 -8.81% BenchmarkBackendS3/LoadFile-4 600 388 -35.33% BenchmarkBackendS3/LoadPartialFile-4 416 302 -27.40% BenchmarkBackendS3/LoadPartialFileOffset-4 417 303 -27.34% benchmark old bytes new bytes delta BenchmarkBackendMinio/LoadFile-4 29475 13904 -52.83% BenchmarkBackendMinio/LoadPartialFile-4 4218838 13958 -99.67% BenchmarkBackendMinio/LoadPartialFileOffset-4 4219175 14332 -99.66% BenchmarkBackendS3/LoadFile-4 114152 97424 -14.65% BenchmarkBackendS3/LoadPartialFile-4 4265416 56212 -98.68% BenchmarkBackendS3/LoadPartialFileOffset-4 4266520 56308 -98.68%
2017-05-13 21:18:14 +02:00
"fmt"
2015-05-10 17:20:58 +02:00
"io"
2017-05-13 23:55:22 +02:00
"os"
"path"
2016-08-31 22:39:36 +02:00
"restic"
2015-05-10 17:20:58 +02:00
"strings"
"sync"
2015-05-10 17:20:58 +02:00
2017-01-22 22:01:12 +01:00
"restic/backend"
2016-09-01 22:17:37 +02:00
"restic/errors"
"github.com/minio/minio-go"
2015-05-10 17:20:58 +02:00
"restic/debug"
2015-05-10 17:20:58 +02:00
)
const connLimit = 10
2015-05-10 17:20:58 +02:00
2016-01-26 22:19:10 +01:00
// s3 is a backend which stores the data on an S3 endpoint.
type s3 struct {
client *minio.Client
connChan chan struct{}
bucketname string
prefix string
cacheMutex sync.RWMutex
cacheObjSize map[string]int64
2017-04-11 22:04:18 +02:00
backend.Layout
}
// Open opens the S3 backend at bucket and region. The bucket is created if it
// does not exist yet.
2016-08-31 22:39:36 +02:00
func Open(cfg Config) (restic.Backend, error) {
2016-09-27 22:35:08 +02:00
debug.Log("open, config %#v", cfg)
2015-05-10 17:20:58 +02:00
client, err := minio.New(cfg.Endpoint, cfg.KeyID, cfg.Secret, !cfg.UseHTTP)
if err != nil {
2016-08-29 21:54:50 +02:00
return nil, errors.Wrap(err, "minio.New")
}
be := &s3{
client: client,
bucketname: cfg.Bucket,
prefix: cfg.Prefix,
cacheObjSize: make(map[string]int64),
2017-04-17 19:18:47 +02:00
Layout: &backend.S3Layout{Path: cfg.Prefix, Join: path.Join},
}
2017-02-10 19:24:54 +01:00
2017-05-01 19:30:52 +02:00
client.SetCustomTransport(backend.Transport())
2017-02-10 19:24:54 +01:00
be.createConnections()
found, err := client.BucketExists(cfg.Bucket)
2016-08-21 16:14:58 +02:00
if err != nil {
debug.Log("BucketExists(%v) returned err %v", cfg.Bucket, err)
2016-08-29 21:54:50 +02:00
return nil, errors.Wrap(err, "client.BucketExists")
2016-08-21 16:14:58 +02:00
}
if !found {
// create new bucket with default ACL in default region
err = client.MakeBucket(cfg.Bucket, "")
if err != nil {
2016-08-29 21:54:50 +02:00
return nil, errors.Wrap(err, "client.MakeBucket")
}
}
return be, nil
}
2016-01-26 22:19:10 +01:00
func (be *s3) createConnections() {
be.connChan = make(chan struct{}, connLimit)
for i := 0; i < connLimit; i++ {
be.connChan <- struct{}{}
}
2015-05-10 17:20:58 +02:00
}
// Location returns this backend's location (the bucket name).
2016-01-26 22:19:10 +01:00
func (be *s3) Location() string {
return be.bucketname
2015-05-10 17:20:58 +02:00
}
type Sizer interface {
Size() int64
}
2017-05-13 23:55:22 +02:00
type Lenner interface {
Len() int
}
// getRemainingSize returns number of bytes remaining. If it is not possible to
// determine the size, panic() is called.
func getRemainingSize(rd io.Reader) (size int64, err error) {
if r, ok := rd.(Lenner); ok {
size = int64(r.Len())
} else if r, ok := rd.(Sizer); ok {
size = r.Size()
} else if f, ok := rd.(*os.File); ok {
fi, err := f.Stat()
if err != nil {
return 0, err
}
pos, err := f.Seek(0, io.SeekCurrent)
if err != nil {
return 0, err
}
size = fi.Size() - pos
} else {
panic(fmt.Sprintf("Save() got passed a reader without a method to determine the data size, type is %T", rd))
}
return size, nil
}
// preventCloser wraps an io.Reader to run a function instead of the original Close() function.
type preventCloser struct {
io.Reader
f func()
}
func (wr preventCloser) Close() error {
wr.f()
return nil
}
2016-01-24 01:15:35 +01:00
// Save stores data in the backend at the handle.
2017-01-22 22:01:12 +01:00
func (be *s3) Save(h restic.Handle, rd io.Reader) (err error) {
2016-01-24 01:15:35 +01:00
if err := h.Valid(); err != nil {
return err
}
2017-04-11 22:04:18 +02:00
objName := be.Filename(h)
2017-05-13 23:55:22 +02:00
size, err := getRemainingSize(rd)
if err != nil {
return err
}
2017-04-17 19:18:47 +02:00
debug.Log("Save %v at %v", h, objName)
// Check key does not already exist
_, err = be.client.StatObject(be.bucketname, objName)
if err == nil {
2016-09-27 22:35:08 +02:00
debug.Log("%v already exists", h)
return errors.New("key already exists")
}
2016-01-24 01:15:35 +01:00
<-be.connChan
// wrap the reader so that net/http client cannot close the reader, return
// the token instead.
rd = preventCloser{
Reader: rd,
f: func() {
debug.Log("Close()")
},
}
debug.Log("PutObject(%v, %v)", be.bucketname, objName)
coreClient := minio.Core{be.client}
info, err := coreClient.PutObject(be.bucketname, objName, size, rd, nil, nil, nil)
// return token
be.connChan <- struct{}{}
debug.Log("%v -> %v bytes, err %#v", objName, info.Size, err)
2016-01-24 01:15:35 +01:00
2016-08-29 21:54:50 +02:00
return errors.Wrap(err, "client.PutObject")
2016-01-24 01:15:35 +01:00
}
// wrapReader wraps an io.ReadCloser to run an additional function on Close.
type wrapReader struct {
io.ReadCloser
f func()
}
func (wr wrapReader) Close() error {
err := wr.ReadCloser.Close()
wr.f()
return err
}
2017-01-23 18:11:10 +01:00
// Load returns a reader that yields the contents of the file at h at the
2017-01-22 22:01:12 +01:00
// given offset. If length is nonzero, only a portion of the file is
// returned. rd must be closed after use.
2017-01-23 18:11:10 +01:00
func (be *s3) Load(h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
2017-04-17 19:18:47 +02:00
debug.Log("Load %v, length %v, offset %v from %v", h, length, offset, be.Filename(h))
2017-01-22 22:01:12 +01:00
if err := h.Valid(); err != nil {
return nil, err
}
if offset < 0 {
return nil, errors.New("offset is negative")
}
if length < 0 {
return nil, errors.Errorf("invalid length %d", length)
}
2017-04-11 22:04:18 +02:00
objName := be.Filename(h)
2017-01-22 22:01:12 +01:00
// get token for connection
2017-01-22 22:01:12 +01:00
<-be.connChan
s3: Use low-level API with a Range header for Load benchmark old ns/op new ns/op delta BenchmarkBackendMinio/LoadFile-4 9213315 11001787 +19.41% BenchmarkBackendMinio/LoadPartialFile-4 4176619 3479707 -16.69% BenchmarkBackendMinio/LoadPartialFileOffset-4 4391521 3139214 -28.52% BenchmarkBackendS3/LoadFile-4 2886070905 2505907501 -13.17% BenchmarkBackendS3/LoadPartialFile-4 762702722 735694398 -3.54% BenchmarkBackendS3/LoadPartialFileOffset-4 789724328 1108989142 +40.43% benchmark old MB/s new MB/s speedup BenchmarkBackendMinio/LoadFile-4 1821.21 1525.15 0.84x BenchmarkBackendMinio/LoadPartialFile-4 1004.49 1205.67 1.20x BenchmarkBackendMinio/LoadPartialFileOffset-4 955.34 1336.45 1.40x BenchmarkBackendS3/LoadFile-4 5.81 6.70 1.15x BenchmarkBackendS3/LoadPartialFile-4 5.50 5.70 1.04x BenchmarkBackendS3/LoadPartialFileOffset-4 5.31 3.78 0.71x benchmark old allocs new allocs delta BenchmarkBackendMinio/LoadFile-4 406 204 -49.75% BenchmarkBackendMinio/LoadPartialFile-4 225 206 -8.44% BenchmarkBackendMinio/LoadPartialFileOffset-4 227 207 -8.81% BenchmarkBackendS3/LoadFile-4 600 388 -35.33% BenchmarkBackendS3/LoadPartialFile-4 416 302 -27.40% BenchmarkBackendS3/LoadPartialFileOffset-4 417 303 -27.34% benchmark old bytes new bytes delta BenchmarkBackendMinio/LoadFile-4 29475 13904 -52.83% BenchmarkBackendMinio/LoadPartialFile-4 4218838 13958 -99.67% BenchmarkBackendMinio/LoadPartialFileOffset-4 4219175 14332 -99.66% BenchmarkBackendS3/LoadFile-4 114152 97424 -14.65% BenchmarkBackendS3/LoadPartialFile-4 4265416 56212 -98.68% BenchmarkBackendS3/LoadPartialFileOffset-4 4266520 56308 -98.68%
2017-05-13 21:18:14 +02:00
byteRange := fmt.Sprintf("bytes=%d-", offset)
if length > 0 {
byteRange = fmt.Sprintf("bytes=%d-%d", offset, offset+int64(length)-1)
2017-01-22 22:01:12 +01:00
}
s3: Use low-level API with a Range header for Load benchmark old ns/op new ns/op delta BenchmarkBackendMinio/LoadFile-4 9213315 11001787 +19.41% BenchmarkBackendMinio/LoadPartialFile-4 4176619 3479707 -16.69% BenchmarkBackendMinio/LoadPartialFileOffset-4 4391521 3139214 -28.52% BenchmarkBackendS3/LoadFile-4 2886070905 2505907501 -13.17% BenchmarkBackendS3/LoadPartialFile-4 762702722 735694398 -3.54% BenchmarkBackendS3/LoadPartialFileOffset-4 789724328 1108989142 +40.43% benchmark old MB/s new MB/s speedup BenchmarkBackendMinio/LoadFile-4 1821.21 1525.15 0.84x BenchmarkBackendMinio/LoadPartialFile-4 1004.49 1205.67 1.20x BenchmarkBackendMinio/LoadPartialFileOffset-4 955.34 1336.45 1.40x BenchmarkBackendS3/LoadFile-4 5.81 6.70 1.15x BenchmarkBackendS3/LoadPartialFile-4 5.50 5.70 1.04x BenchmarkBackendS3/LoadPartialFileOffset-4 5.31 3.78 0.71x benchmark old allocs new allocs delta BenchmarkBackendMinio/LoadFile-4 406 204 -49.75% BenchmarkBackendMinio/LoadPartialFile-4 225 206 -8.44% BenchmarkBackendMinio/LoadPartialFileOffset-4 227 207 -8.81% BenchmarkBackendS3/LoadFile-4 600 388 -35.33% BenchmarkBackendS3/LoadPartialFile-4 416 302 -27.40% BenchmarkBackendS3/LoadPartialFileOffset-4 417 303 -27.34% benchmark old bytes new bytes delta BenchmarkBackendMinio/LoadFile-4 29475 13904 -52.83% BenchmarkBackendMinio/LoadPartialFile-4 4218838 13958 -99.67% BenchmarkBackendMinio/LoadPartialFileOffset-4 4219175 14332 -99.66% BenchmarkBackendS3/LoadFile-4 114152 97424 -14.65% BenchmarkBackendS3/LoadPartialFile-4 4265416 56212 -98.68% BenchmarkBackendS3/LoadPartialFileOffset-4 4266520 56308 -98.68%
2017-05-13 21:18:14 +02:00
headers := minio.NewGetReqHeaders()
headers.Add("Range", byteRange)
debug.Log("Load(%v) send range %v", h, byteRange)
2017-01-22 22:01:12 +01:00
s3: Use low-level API with a Range header for Load benchmark old ns/op new ns/op delta BenchmarkBackendMinio/LoadFile-4 9213315 11001787 +19.41% BenchmarkBackendMinio/LoadPartialFile-4 4176619 3479707 -16.69% BenchmarkBackendMinio/LoadPartialFileOffset-4 4391521 3139214 -28.52% BenchmarkBackendS3/LoadFile-4 2886070905 2505907501 -13.17% BenchmarkBackendS3/LoadPartialFile-4 762702722 735694398 -3.54% BenchmarkBackendS3/LoadPartialFileOffset-4 789724328 1108989142 +40.43% benchmark old MB/s new MB/s speedup BenchmarkBackendMinio/LoadFile-4 1821.21 1525.15 0.84x BenchmarkBackendMinio/LoadPartialFile-4 1004.49 1205.67 1.20x BenchmarkBackendMinio/LoadPartialFileOffset-4 955.34 1336.45 1.40x BenchmarkBackendS3/LoadFile-4 5.81 6.70 1.15x BenchmarkBackendS3/LoadPartialFile-4 5.50 5.70 1.04x BenchmarkBackendS3/LoadPartialFileOffset-4 5.31 3.78 0.71x benchmark old allocs new allocs delta BenchmarkBackendMinio/LoadFile-4 406 204 -49.75% BenchmarkBackendMinio/LoadPartialFile-4 225 206 -8.44% BenchmarkBackendMinio/LoadPartialFileOffset-4 227 207 -8.81% BenchmarkBackendS3/LoadFile-4 600 388 -35.33% BenchmarkBackendS3/LoadPartialFile-4 416 302 -27.40% BenchmarkBackendS3/LoadPartialFileOffset-4 417 303 -27.34% benchmark old bytes new bytes delta BenchmarkBackendMinio/LoadFile-4 29475 13904 -52.83% BenchmarkBackendMinio/LoadPartialFile-4 4218838 13958 -99.67% BenchmarkBackendMinio/LoadPartialFileOffset-4 4219175 14332 -99.66% BenchmarkBackendS3/LoadFile-4 114152 97424 -14.65% BenchmarkBackendS3/LoadPartialFile-4 4265416 56212 -98.68% BenchmarkBackendS3/LoadPartialFileOffset-4 4266520 56308 -98.68%
2017-05-13 21:18:14 +02:00
coreClient := minio.Core{be.client}
rd, _, err := coreClient.GetObject(be.bucketname, objName, headers)
2017-01-22 22:01:12 +01:00
s3: Use low-level API with a Range header for Load benchmark old ns/op new ns/op delta BenchmarkBackendMinio/LoadFile-4 9213315 11001787 +19.41% BenchmarkBackendMinio/LoadPartialFile-4 4176619 3479707 -16.69% BenchmarkBackendMinio/LoadPartialFileOffset-4 4391521 3139214 -28.52% BenchmarkBackendS3/LoadFile-4 2886070905 2505907501 -13.17% BenchmarkBackendS3/LoadPartialFile-4 762702722 735694398 -3.54% BenchmarkBackendS3/LoadPartialFileOffset-4 789724328 1108989142 +40.43% benchmark old MB/s new MB/s speedup BenchmarkBackendMinio/LoadFile-4 1821.21 1525.15 0.84x BenchmarkBackendMinio/LoadPartialFile-4 1004.49 1205.67 1.20x BenchmarkBackendMinio/LoadPartialFileOffset-4 955.34 1336.45 1.40x BenchmarkBackendS3/LoadFile-4 5.81 6.70 1.15x BenchmarkBackendS3/LoadPartialFile-4 5.50 5.70 1.04x BenchmarkBackendS3/LoadPartialFileOffset-4 5.31 3.78 0.71x benchmark old allocs new allocs delta BenchmarkBackendMinio/LoadFile-4 406 204 -49.75% BenchmarkBackendMinio/LoadPartialFile-4 225 206 -8.44% BenchmarkBackendMinio/LoadPartialFileOffset-4 227 207 -8.81% BenchmarkBackendS3/LoadFile-4 600 388 -35.33% BenchmarkBackendS3/LoadPartialFile-4 416 302 -27.40% BenchmarkBackendS3/LoadPartialFileOffset-4 417 303 -27.34% benchmark old bytes new bytes delta BenchmarkBackendMinio/LoadFile-4 29475 13904 -52.83% BenchmarkBackendMinio/LoadPartialFile-4 4218838 13958 -99.67% BenchmarkBackendMinio/LoadPartialFileOffset-4 4219175 14332 -99.66% BenchmarkBackendS3/LoadFile-4 114152 97424 -14.65% BenchmarkBackendS3/LoadPartialFile-4 4265416 56212 -98.68% BenchmarkBackendS3/LoadPartialFileOffset-4 4266520 56308 -98.68%
2017-05-13 21:18:14 +02:00
// return token
be.connChan <- struct{}{}
2017-01-22 22:01:12 +01:00
s3: Use low-level API with a Range header for Load benchmark old ns/op new ns/op delta BenchmarkBackendMinio/LoadFile-4 9213315 11001787 +19.41% BenchmarkBackendMinio/LoadPartialFile-4 4176619 3479707 -16.69% BenchmarkBackendMinio/LoadPartialFileOffset-4 4391521 3139214 -28.52% BenchmarkBackendS3/LoadFile-4 2886070905 2505907501 -13.17% BenchmarkBackendS3/LoadPartialFile-4 762702722 735694398 -3.54% BenchmarkBackendS3/LoadPartialFileOffset-4 789724328 1108989142 +40.43% benchmark old MB/s new MB/s speedup BenchmarkBackendMinio/LoadFile-4 1821.21 1525.15 0.84x BenchmarkBackendMinio/LoadPartialFile-4 1004.49 1205.67 1.20x BenchmarkBackendMinio/LoadPartialFileOffset-4 955.34 1336.45 1.40x BenchmarkBackendS3/LoadFile-4 5.81 6.70 1.15x BenchmarkBackendS3/LoadPartialFile-4 5.50 5.70 1.04x BenchmarkBackendS3/LoadPartialFileOffset-4 5.31 3.78 0.71x benchmark old allocs new allocs delta BenchmarkBackendMinio/LoadFile-4 406 204 -49.75% BenchmarkBackendMinio/LoadPartialFile-4 225 206 -8.44% BenchmarkBackendMinio/LoadPartialFileOffset-4 227 207 -8.81% BenchmarkBackendS3/LoadFile-4 600 388 -35.33% BenchmarkBackendS3/LoadPartialFile-4 416 302 -27.40% BenchmarkBackendS3/LoadPartialFileOffset-4 417 303 -27.34% benchmark old bytes new bytes delta BenchmarkBackendMinio/LoadFile-4 29475 13904 -52.83% BenchmarkBackendMinio/LoadPartialFile-4 4218838 13958 -99.67% BenchmarkBackendMinio/LoadPartialFileOffset-4 4219175 14332 -99.66% BenchmarkBackendS3/LoadFile-4 114152 97424 -14.65% BenchmarkBackendS3/LoadPartialFile-4 4265416 56212 -98.68% BenchmarkBackendS3/LoadPartialFileOffset-4 4266520 56308 -98.68%
2017-05-13 21:18:14 +02:00
return rd, err
2017-01-22 22:01:12 +01:00
}
2016-01-23 23:27:58 +01:00
// Stat returns information about a blob.
2017-01-22 22:01:12 +01:00
func (be *s3) Stat(h restic.Handle) (bi restic.FileInfo, err error) {
2016-09-27 22:35:08 +02:00
debug.Log("%v", h)
2017-04-11 22:04:18 +02:00
objName := be.Filename(h)
var obj *minio.Object
obj, err = be.client.GetObject(be.bucketname, objName)
2016-01-23 23:27:58 +01:00
if err != nil {
2016-09-27 22:35:08 +02:00
debug.Log("GetObject() err %v", err)
2016-08-31 22:39:36 +02:00
return restic.FileInfo{}, errors.Wrap(err, "client.GetObject")
2016-01-23 23:27:58 +01:00
}
// make sure that the object is closed properly.
defer func() {
e := obj.Close()
if err == nil {
2016-08-29 21:54:50 +02:00
err = errors.Wrap(e, "Close")
}
}()
2016-01-23 23:27:58 +01:00
fi, err := obj.Stat()
if err != nil {
2016-09-27 22:35:08 +02:00
debug.Log("Stat() err %v", err)
2016-08-31 22:39:36 +02:00
return restic.FileInfo{}, errors.Wrap(err, "Stat")
2016-01-23 23:27:58 +01:00
}
2016-08-31 22:39:36 +02:00
return restic.FileInfo{Size: fi.Size}, nil
2016-01-23 23:27:58 +01:00
}
2015-05-10 17:20:58 +02:00
// Test returns true if a blob of the given type and name exists in the backend.
func (be *s3) Test(h restic.Handle) (bool, error) {
2015-05-10 17:20:58 +02:00
found := false
2017-04-11 22:04:18 +02:00
objName := be.Filename(h)
_, err := be.client.StatObject(be.bucketname, objName)
if err == nil {
2015-05-10 17:20:58 +02:00
found = true
}
// If error, then not found
return found, nil
}
// Remove removes the blob with the given name and type.
func (be *s3) Remove(h restic.Handle) error {
2017-04-11 22:04:18 +02:00
objName := be.Filename(h)
err := be.client.RemoveObject(be.bucketname, objName)
2017-04-17 19:18:47 +02:00
debug.Log("Remove(%v) at %v -> err %v", h, objName, err)
2016-08-29 21:54:50 +02:00
return errors.Wrap(err, "client.RemoveObject")
2015-05-10 17:20:58 +02:00
}
// List returns a channel that yields all names of blobs of type t. A
// goroutine is started for this. If the channel done is closed, sending
// stops.
2016-08-31 22:39:36 +02:00
func (be *s3) List(t restic.FileType, done <-chan struct{}) <-chan string {
2016-09-27 22:35:08 +02:00
debug.Log("listing %v", t)
2015-05-10 17:20:58 +02:00
ch := make(chan string)
2017-04-11 22:04:18 +02:00
prefix := be.Dirname(restic.Handle{Type: t})
2015-05-10 17:20:58 +02:00
2015-12-29 00:27:29 +01:00
listresp := be.client.ListObjects(be.bucketname, prefix, true, done)
2015-05-10 17:20:58 +02:00
go func() {
defer close(ch)
for obj := range listresp {
2015-12-29 00:27:29 +01:00
m := strings.TrimPrefix(obj.Key, prefix)
2015-05-10 17:20:58 +02:00
if m == "" {
continue
}
select {
case ch <- m:
case <-done:
return
}
}
}()
return ch
}
// Remove keys for a specified backend type.
2016-08-31 22:39:36 +02:00
func (be *s3) removeKeys(t restic.FileType) error {
done := make(chan struct{})
defer close(done)
2016-08-31 22:39:36 +02:00
for key := range be.List(restic.DataFile, done) {
err := be.Remove(restic.Handle{Type: restic.DataFile, Name: key})
if err != nil {
return err
}
}
return nil
}
// Delete removes all restic keys in the bucket. It will not remove the bucket itself.
2016-01-26 22:19:10 +01:00
func (be *s3) Delete() error {
2016-08-31 22:39:36 +02:00
alltypes := []restic.FileType{
restic.DataFile,
restic.KeyFile,
restic.LockFile,
restic.SnapshotFile,
restic.IndexFile}
for _, t := range alltypes {
err := be.removeKeys(t)
if err != nil {
return nil
}
}
return be.Remove(restic.Handle{Type: restic.ConfigFile})
2015-05-10 17:20:58 +02:00
}
// Close does nothing
2016-01-26 22:19:10 +01:00
func (be *s3) Close() error { return nil }