mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 06:46:34 +00:00
Automatically exclude current restic cache
This commit is contained in:
parent
58699e3c90
commit
610b676444
@ -387,6 +387,16 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// exclude restic cache
|
||||||
|
if repo.Cache != nil {
|
||||||
|
f, err := rejectResticCache(repo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rejectFuncs = append(rejectFuncs, f)
|
||||||
|
}
|
||||||
|
|
||||||
err = repo.LoadIndex(context.TODO())
|
err = repo.LoadIndex(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
"github.com/restic/restic/internal/filter"
|
"github.com/restic/restic/internal/filter"
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
|
"github.com/restic/restic/internal/repository"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RejectFunc is a function that takes a filename and os.FileInfo of a
|
// RejectFunc is a function that takes a filename and os.FileInfo of a
|
||||||
@ -177,3 +178,27 @@ func rejectByDevice(samples []string) (RejectFunc, error) {
|
|||||||
panic(fmt.Sprintf("item %v, device id %v not found, allowedDevs: %v", item, id, allowed))
|
panic(fmt.Sprintf("item %v, device id %v not found, allowedDevs: %v", item, id, allowed))
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// rejectResticCache returns a RejectFunc that rejects the restic cache
|
||||||
|
// directory (if set).
|
||||||
|
func rejectResticCache(repo *repository.Repository) (RejectFunc, error) {
|
||||||
|
if repo.Cache == nil {
|
||||||
|
return func(string, os.FileInfo) bool {
|
||||||
|
return false
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
cacheBase := repo.Cache.BaseDir()
|
||||||
|
|
||||||
|
if cacheBase == "" {
|
||||||
|
return nil, errors.New("cacheBase is empty string")
|
||||||
|
}
|
||||||
|
|
||||||
|
return func(item string, _ os.FileInfo) bool {
|
||||||
|
if fs.HasPathPrefix(cacheBase, item) {
|
||||||
|
debug.Log("rejecting restic cache directory %v", item)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
5
internal/cache/cache.go
vendored
5
internal/cache/cache.go
vendored
@ -152,3 +152,8 @@ func (c *Cache) Wrap(be restic.Backend) restic.Backend {
|
|||||||
Cache: c,
|
Cache: c,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BaseDir returns the base directory.
|
||||||
|
func (c *Cache) BaseDir() string {
|
||||||
|
return c.Base
|
||||||
|
}
|
||||||
|
@ -4,6 +4,9 @@ import "io"
|
|||||||
|
|
||||||
// Cache manages a local cache.
|
// Cache manages a local cache.
|
||||||
type Cache interface {
|
type Cache interface {
|
||||||
|
// BaseDir returns the base directory of the cache.
|
||||||
|
BaseDir() string
|
||||||
|
|
||||||
// Wrap returns a backend with a cache.
|
// Wrap returns a backend with a cache.
|
||||||
Wrap(Backend) Backend
|
Wrap(Backend) Backend
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user