2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 03:18:55 +00:00

Place all restic data under a key prefix.

Deleting a restic repository now only deletes restic keys, leaving the
rest of the bucket in tact.
This commit is contained in:
Chris Howey 2015-06-14 08:02:29 -05:00
parent d30a95e8ad
commit e963faf846

View File

@ -16,12 +16,13 @@ import (
const maxKeysInList = 1000 const maxKeysInList = 1000
const connLimit = 10 const connLimit = 10
const backendPrefix = "restic"
func s3path(t backend.Type, name string) string { func s3path(t backend.Type, name string) string {
if t == backend.Config { if t == backend.Config {
return string(t) return backendPrefix + "/" + string(t)
} }
return string(t) + "/" + name return backendPrefix + "/" + string(t) + "/" + name
} }
type S3 struct { type S3 struct {
@ -173,7 +174,7 @@ func (b *S3) Remove(t backend.Type, name string) error {
func (b *S3) List(t backend.Type, done <-chan struct{}) <-chan string { func (b *S3) List(t backend.Type, done <-chan struct{}) <-chan string {
ch := make(chan string) ch := make(chan string)
prefix := string(t) + "/" prefix := s3path(t, "")
listresp, err := b.bucket.List(prefix, "/", "", maxKeysInList) listresp, err := b.bucket.List(prefix, "/", "", maxKeysInList)
@ -218,9 +219,24 @@ func (b *S3) List(t backend.Type, done <-chan struct{}) <-chan string {
return ch return ch
} }
// Delete removes the repository and all files. // Remove keys for a specified backend type
func (b *S3) removeKeys(t backend.Type) {
doneChan := make(chan struct{})
for key := range b.List(backend.Data, doneChan) {
b.Remove(backend.Data, key)
}
doneChan <- struct{}{}
}
// Delete removes all restic keys
func (b *S3) Delete() error { func (b *S3) Delete() error {
return b.bucket.DelBucket() b.removeKeys(backend.Data)
b.removeKeys(backend.Key)
b.removeKeys(backend.Lock)
b.removeKeys(backend.Snapshot)
b.removeKeys(backend.Index)
b.removeKeys(backend.Config)
return nil
} }
// Close does nothing // Close does nothing