2015-03-28 11:50:23 +01:00
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
2017-06-03 17:39:57 +02:00
|
|
|
"context"
|
2024-05-11 00:07:04 +02:00
|
|
|
"fmt"
|
2020-12-19 12:39:48 +01:00
|
|
|
"hash"
|
2015-03-28 11:50:23 +01:00
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2019-10-09 21:42:15 +02:00
|
|
|
"syscall"
|
2015-03-28 11:50:23 +01:00
|
|
|
|
2017-07-23 14:21:03 +02:00
|
|
|
"github.com/restic/restic/internal/backend"
|
2022-10-15 16:23:39 +02:00
|
|
|
"github.com/restic/restic/internal/backend/layout"
|
2023-06-08 13:04:34 +02:00
|
|
|
"github.com/restic/restic/internal/backend/limiter"
|
|
|
|
"github.com/restic/restic/internal/backend/location"
|
2023-10-01 10:24:33 +02:00
|
|
|
"github.com/restic/restic/internal/backend/util"
|
2017-07-23 14:21:03 +02:00
|
|
|
"github.com/restic/restic/internal/debug"
|
2022-06-12 17:45:34 +02:00
|
|
|
"github.com/restic/restic/internal/errors"
|
2017-07-23 14:21:03 +02:00
|
|
|
"github.com/restic/restic/internal/fs"
|
2020-12-16 13:58:02 +01:00
|
|
|
|
|
|
|
"github.com/cenkalti/backoff/v4"
|
2015-03-28 11:50:23 +01:00
|
|
|
)
|
|
|
|
|
2016-01-24 20:23:50 +01:00
|
|
|
// Local is a backend in a local directory.
|
2015-03-28 11:50:23 +01:00
|
|
|
type Local struct {
|
2017-03-25 13:20:03 +01:00
|
|
|
Config
|
2022-10-15 16:23:39 +02:00
|
|
|
layout.Layout
|
2023-10-01 10:24:33 +02:00
|
|
|
util.Modes
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
2023-10-01 11:40:12 +02:00
|
|
|
// ensure statically that *Local implements backend.Backend.
|
|
|
|
var _ backend.Backend = &Local{}
|
2016-08-31 22:39:36 +02:00
|
|
|
|
2024-05-11 00:07:04 +02:00
|
|
|
var errTooShort = fmt.Errorf("file is too short")
|
|
|
|
|
2023-06-08 13:04:34 +02:00
|
|
|
func NewFactory() location.Factory {
|
2023-06-08 17:32:43 +02:00
|
|
|
return location.NewLimitedBackendFactory("local", ParseConfig, location.NoPassword, limiter.WrapBackendConstructor(Create), limiter.WrapBackendConstructor(Open))
|
2023-06-08 13:04:34 +02:00
|
|
|
}
|
|
|
|
|
2024-08-26 21:16:22 +02:00
|
|
|
func open(cfg Config) (*Local, error) {
|
2024-08-26 20:28:39 +02:00
|
|
|
l := layout.NewDefaultLayout(cfg.Path, filepath.Join)
|
2017-03-26 21:53:26 +02:00
|
|
|
|
2024-07-21 15:22:21 +02:00
|
|
|
fi, err := os.Stat(l.Filename(backend.Handle{Type: backend.ConfigFile}))
|
2023-10-01 10:24:33 +02:00
|
|
|
m := util.DeriveModesFromFileInfo(fi, err)
|
2022-04-26 19:15:09 +02:00
|
|
|
debug.Log("using (%03O file, %03O dir) permissions", m.File, m.Dir)
|
|
|
|
|
2021-08-07 19:50:00 +02:00
|
|
|
return &Local{
|
|
|
|
Config: cfg,
|
|
|
|
Layout: l,
|
2022-04-26 19:15:09 +02:00
|
|
|
Modes: m,
|
2021-08-07 19:50:00 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open opens the local backend as specified by config.
|
2024-08-26 21:16:22 +02:00
|
|
|
func Open(_ context.Context, cfg Config) (*Local, error) {
|
2024-08-26 20:28:39 +02:00
|
|
|
debug.Log("open local backend at %v", cfg.Path)
|
2024-08-26 21:16:22 +02:00
|
|
|
return open(cfg)
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create creates all the necessary files and directories for a new local
|
2015-05-04 20:39:45 +02:00
|
|
|
// backend at dir. Afterwards a new config blob should be created.
|
2024-08-26 21:16:22 +02:00
|
|
|
func Create(_ context.Context, cfg Config) (*Local, error) {
|
2024-08-26 20:28:39 +02:00
|
|
|
debug.Log("create local backend at %v", cfg.Path)
|
2017-04-02 19:54:11 +02:00
|
|
|
|
2024-08-26 21:16:22 +02:00
|
|
|
be, err := open(cfg)
|
2017-04-02 19:54:11 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-05-04 20:39:45 +02:00
|
|
|
// test if config file already exists
|
2024-07-21 15:22:21 +02:00
|
|
|
_, err = os.Lstat(be.Filename(backend.Handle{Type: backend.ConfigFile}))
|
2015-03-28 11:50:23 +01:00
|
|
|
if err == nil {
|
2015-05-03 16:43:27 +02:00
|
|
|
return nil, errors.New("config file already exists")
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
2017-04-19 18:56:01 +02:00
|
|
|
// create paths for data and refs
|
2017-03-26 21:53:26 +02:00
|
|
|
for _, d := range be.Paths() {
|
2024-07-21 15:22:21 +02:00
|
|
|
err := os.MkdirAll(d, be.Modes.Dir)
|
2015-03-28 11:50:23 +01:00
|
|
|
if err != nil {
|
2021-06-07 19:26:25 +02:00
|
|
|
return nil, errors.WithStack(err)
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 21:53:26 +02:00
|
|
|
return be, nil
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
2021-08-07 19:50:00 +02:00
|
|
|
func (b *Local) Connections() uint {
|
|
|
|
return b.Config.Connections
|
|
|
|
}
|
|
|
|
|
2020-12-19 12:39:48 +01:00
|
|
|
// Hasher may return a hash function for calculating a content hash for the backend
|
|
|
|
func (b *Local) Hasher() hash.Hash {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-05-01 20:07:29 +02:00
|
|
|
// HasAtomicReplace returns whether Save() can atomically replace files
|
|
|
|
func (b *Local) HasAtomicReplace() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-06-15 13:40:27 +02:00
|
|
|
// IsNotExist returns true if the error is caused by a non existing file.
|
|
|
|
func (b *Local) IsNotExist(err error) bool {
|
2021-06-07 19:26:25 +02:00
|
|
|
return errors.Is(err, os.ErrNotExist)
|
2017-06-15 13:40:27 +02:00
|
|
|
}
|
|
|
|
|
2024-05-11 00:07:04 +02:00
|
|
|
func (b *Local) IsPermanentError(err error) bool {
|
|
|
|
return b.IsNotExist(err) || errors.Is(err, errTooShort) || errors.Is(err, os.ErrPermission)
|
|
|
|
}
|
|
|
|
|
2016-01-26 22:12:53 +01:00
|
|
|
// Save stores data in the backend at the handle.
|
2023-10-01 11:40:12 +02:00
|
|
|
func (b *Local) Save(_ context.Context, h backend.Handle, rd backend.RewindReader) (err error) {
|
2020-11-02 10:34:21 +01:00
|
|
|
finalname := b.Filename(h)
|
|
|
|
dir := filepath.Dir(finalname)
|
2016-01-24 16:59:38 +01:00
|
|
|
|
2020-12-16 13:58:02 +01:00
|
|
|
defer func() {
|
2020-12-20 21:12:27 +01:00
|
|
|
// Mark non-retriable errors as such
|
|
|
|
if errors.Is(err, syscall.ENOSPC) || os.IsPermission(err) {
|
2020-12-16 13:58:02 +01:00
|
|
|
err = backoff.Permanent(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2020-11-02 10:34:21 +01:00
|
|
|
// Create new file with a temporary name.
|
|
|
|
tmpname := filepath.Base(finalname) + "-tmp-"
|
|
|
|
f, err := tempFile(dir, tmpname)
|
2018-01-05 17:51:09 +01:00
|
|
|
|
|
|
|
if b.IsNotExist(err) {
|
|
|
|
debug.Log("error %v: creating dir", err)
|
|
|
|
|
|
|
|
// error is caused by a missing directory, try to create it
|
2024-07-21 15:22:21 +02:00
|
|
|
mkdirErr := os.MkdirAll(dir, b.Modes.Dir)
|
2018-01-05 17:51:09 +01:00
|
|
|
if mkdirErr != nil {
|
2020-11-02 10:34:21 +01:00
|
|
|
debug.Log("error creating dir %v: %v", dir, mkdirErr)
|
2018-01-05 17:51:09 +01:00
|
|
|
} else {
|
|
|
|
// try again
|
2020-11-02 10:34:21 +01:00
|
|
|
f, err = tempFile(dir, tmpname)
|
2018-01-05 17:51:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 21:53:26 +02:00
|
|
|
if err != nil {
|
2021-06-07 19:26:25 +02:00
|
|
|
return errors.WithStack(err)
|
2017-03-26 21:53:26 +02:00
|
|
|
}
|
|
|
|
|
2020-11-02 10:34:21 +01:00
|
|
|
defer func(f *os.File) {
|
|
|
|
if err != nil {
|
|
|
|
_ = f.Close() // Double Close is harmless.
|
|
|
|
// Remove after Rename is harmless: we embed the final name in the
|
|
|
|
// temporary's name and no other goroutine will get the same data to
|
|
|
|
// Save, so the temporary name should never be reused by another
|
|
|
|
// goroutine.
|
2024-07-21 15:22:21 +02:00
|
|
|
_ = os.Remove(f.Name())
|
2020-11-02 10:34:21 +01:00
|
|
|
}
|
|
|
|
}(f)
|
|
|
|
|
2021-02-02 15:44:40 +01:00
|
|
|
// preallocate disk space
|
|
|
|
if size := rd.Length(); size > 0 {
|
|
|
|
if err := fs.PreallocateFile(f, size); err != nil {
|
|
|
|
debug.Log("Failed to preallocate %v with size %v: %v", finalname, size, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-26 21:53:26 +02:00
|
|
|
// save data, then sync
|
2020-12-18 23:41:29 +01:00
|
|
|
wbytes, err := io.Copy(f, rd)
|
2017-03-26 21:53:26 +02:00
|
|
|
if err != nil {
|
2021-06-07 19:26:25 +02:00
|
|
|
return errors.WithStack(err)
|
2017-03-26 21:53:26 +02:00
|
|
|
}
|
2020-12-18 23:41:29 +01:00
|
|
|
// sanity check
|
|
|
|
if wbytes != rd.Length() {
|
|
|
|
return errors.Errorf("wrote %d bytes instead of the expected %d bytes", wbytes, rd.Length())
|
|
|
|
}
|
2017-03-26 21:53:26 +02:00
|
|
|
|
2020-11-02 10:34:21 +01:00
|
|
|
// Ignore error if filesystem does not support fsync.
|
2021-07-09 17:11:39 +02:00
|
|
|
err = f.Sync()
|
2022-11-11 14:53:42 +01:00
|
|
|
syncNotSup := err != nil && (errors.Is(err, syscall.ENOTSUP) || isMacENOTTY(err))
|
2021-07-09 17:11:39 +02:00
|
|
|
if err != nil && !syncNotSup {
|
2020-11-02 10:34:21 +01:00
|
|
|
return errors.WithStack(err)
|
2017-03-26 21:53:26 +02:00
|
|
|
}
|
2016-01-24 16:59:38 +01:00
|
|
|
|
2020-11-02 10:34:21 +01:00
|
|
|
// Close, then rename. Windows doesn't like the reverse order.
|
|
|
|
if err = f.Close(); err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
if err = os.Rename(f.Name(), finalname); err != nil {
|
2021-06-07 19:26:25 +02:00
|
|
|
return errors.WithStack(err)
|
2016-01-24 16:59:38 +01:00
|
|
|
}
|
|
|
|
|
2021-07-09 17:11:39 +02:00
|
|
|
// Now sync the directory to commit the Rename.
|
|
|
|
if !syncNotSup {
|
|
|
|
err = fsyncDir(dir)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-06 13:11:55 +01:00
|
|
|
// try to mark file as read-only to avoid accidental modifications
|
2020-10-06 18:28:01 +02:00
|
|
|
// ignore if the operation fails as some filesystems don't allow the chmod call
|
|
|
|
// e.g. exfat and network file systems with certain mount options
|
2022-04-26 19:15:09 +02:00
|
|
|
err = setFileReadonly(finalname, b.Modes.File)
|
2020-10-06 18:28:01 +02:00
|
|
|
if err != nil && !os.IsPermission(err) {
|
2021-06-07 19:26:25 +02:00
|
|
|
return errors.WithStack(err)
|
2020-10-06 18:28:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2016-01-24 01:15:35 +01:00
|
|
|
}
|
|
|
|
|
2022-12-02 19:36:43 +01:00
|
|
|
var tempFile = os.CreateTemp // Overridden by test.
|
2020-12-16 13:58:02 +01:00
|
|
|
|
2018-01-17 05:59:16 +01:00
|
|
|
// Load runs fn with a reader that yields the contents of the file at h at the
|
|
|
|
// given offset.
|
2023-10-01 11:40:12 +02:00
|
|
|
func (b *Local) Load(ctx context.Context, h backend.Handle, length int, offset int64, fn func(rd io.Reader) error) error {
|
2023-10-01 10:24:33 +02:00
|
|
|
return util.DefaultLoad(ctx, h, length, offset, b.openReader, fn)
|
2018-01-17 05:59:16 +01:00
|
|
|
}
|
|
|
|
|
2023-10-01 11:40:12 +02:00
|
|
|
func (b *Local) openReader(_ context.Context, h backend.Handle, length int, offset int64) (io.ReadCloser, error) {
|
2024-07-21 15:22:21 +02:00
|
|
|
f, err := os.Open(b.Filename(h))
|
2017-01-22 22:01:12 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2024-05-11 00:07:04 +02:00
|
|
|
fi, err := f.Stat()
|
|
|
|
if err != nil {
|
|
|
|
_ = f.Close()
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
size := fi.Size()
|
|
|
|
if size < offset+int64(length) {
|
|
|
|
_ = f.Close()
|
|
|
|
return nil, errTooShort
|
|
|
|
}
|
|
|
|
|
2017-01-22 22:01:12 +01:00
|
|
|
if offset > 0 {
|
|
|
|
_, err = f.Seek(offset, 0)
|
|
|
|
if err != nil {
|
2017-06-03 17:39:57 +02:00
|
|
|
_ = f.Close()
|
2017-01-22 22:01:12 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if length > 0 {
|
2024-04-25 21:20:23 +02:00
|
|
|
return util.LimitReadCloser(f, int64(length)), nil
|
2017-01-22 22:01:12 +01:00
|
|
|
}
|
|
|
|
|
2023-04-07 23:02:35 +02:00
|
|
|
return f, nil
|
2017-01-22 22:01:12 +01:00
|
|
|
}
|
|
|
|
|
2016-01-23 23:27:58 +01:00
|
|
|
// Stat returns information about a blob.
|
2023-10-01 11:40:12 +02:00
|
|
|
func (b *Local) Stat(_ context.Context, h backend.Handle) (backend.FileInfo, error) {
|
2024-07-21 15:22:21 +02:00
|
|
|
fi, err := os.Stat(b.Filename(h))
|
2016-01-23 23:27:58 +01:00
|
|
|
if err != nil {
|
2023-10-01 11:40:12 +02:00
|
|
|
return backend.FileInfo{}, errors.WithStack(err)
|
2016-01-23 23:27:58 +01:00
|
|
|
}
|
|
|
|
|
2023-10-01 11:40:12 +02:00
|
|
|
return backend.FileInfo{Size: fi.Size(), Name: h.Name}, nil
|
2016-01-23 23:27:58 +01:00
|
|
|
}
|
|
|
|
|
2015-03-28 11:50:23 +01:00
|
|
|
// Remove removes the blob with the given name and type.
|
2023-10-01 11:40:12 +02:00
|
|
|
func (b *Local) Remove(_ context.Context, h backend.Handle) error {
|
2017-03-26 21:53:26 +02:00
|
|
|
fn := b.Filename(h)
|
2015-08-14 15:30:36 +02:00
|
|
|
|
2015-08-19 22:02:47 +02:00
|
|
|
// reset read-only flag
|
2024-07-21 15:22:21 +02:00
|
|
|
err := os.Chmod(fn, 0666)
|
2020-10-06 18:28:01 +02:00
|
|
|
if err != nil && !os.IsPermission(err) {
|
2021-06-07 19:26:25 +02:00
|
|
|
return errors.WithStack(err)
|
2015-08-19 22:02:47 +02:00
|
|
|
}
|
|
|
|
|
2024-07-21 15:22:21 +02:00
|
|
|
return os.Remove(fn)
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
2018-01-20 19:34:38 +01:00
|
|
|
// List runs fn for each file in the backend which has the type t. When an
|
|
|
|
// error occurs (or fn returns an error), List stops and returns it.
|
2023-10-01 11:40:12 +02:00
|
|
|
func (b *Local) List(ctx context.Context, t backend.FileType, fn func(backend.FileInfo) error) (err error) {
|
2018-01-20 13:43:07 +01:00
|
|
|
basedir, subdirs := b.Basedir(t)
|
2020-11-19 16:46:42 +01:00
|
|
|
if subdirs {
|
|
|
|
err = visitDirs(ctx, basedir, fn)
|
|
|
|
} else {
|
2021-02-27 00:02:13 +01:00
|
|
|
err = visitFiles(ctx, basedir, fn, false)
|
2020-11-19 16:46:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if b.IsNotExist(err) {
|
|
|
|
debug.Log("ignoring non-existing directory")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// The following two functions are like filepath.Walk, but visit only one or
|
|
|
|
// two levels of directory structure (including dir itself as the first level).
|
|
|
|
// Also, visitDirs assumes it sees a directory full of directories, while
|
|
|
|
// visitFiles wants a directory full or regular files.
|
2023-10-01 11:40:12 +02:00
|
|
|
func visitDirs(ctx context.Context, dir string, fn func(backend.FileInfo) error) error {
|
2024-07-21 15:22:21 +02:00
|
|
|
d, err := os.Open(dir)
|
2020-11-19 16:46:42 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sub, err := d.Readdirnames(-1)
|
2021-01-30 19:35:46 +01:00
|
|
|
if err != nil {
|
|
|
|
// ignore subsequent errors
|
|
|
|
_ = d.Close()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = d.Close()
|
2020-11-19 16:46:42 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range sub {
|
2021-02-27 00:02:13 +01:00
|
|
|
err = visitFiles(ctx, filepath.Join(dir, f), fn, true)
|
2018-01-20 13:43:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-19 16:46:42 +01:00
|
|
|
}
|
|
|
|
return ctx.Err()
|
|
|
|
}
|
2015-03-28 11:50:23 +01:00
|
|
|
|
2023-10-01 11:40:12 +02:00
|
|
|
func visitFiles(ctx context.Context, dir string, fn func(backend.FileInfo) error, ignoreNotADirectory bool) error {
|
2024-07-21 15:22:21 +02:00
|
|
|
d, err := os.Open(dir)
|
2020-11-19 16:46:42 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-03-28 11:50:23 +01:00
|
|
|
|
2021-02-27 00:02:13 +01:00
|
|
|
if ignoreNotADirectory {
|
|
|
|
fi, err := d.Stat()
|
|
|
|
if err != nil || !fi.IsDir() {
|
2021-11-06 19:44:57 +01:00
|
|
|
// ignore subsequent errors
|
|
|
|
_ = d.Close()
|
2021-02-27 00:02:13 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 16:46:42 +01:00
|
|
|
sub, err := d.Readdir(-1)
|
2021-01-30 19:35:46 +01:00
|
|
|
if err != nil {
|
|
|
|
// ignore subsequent errors
|
|
|
|
_ = d.Close()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = d.Close()
|
2020-11-19 16:46:42 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-12-14 19:13:01 +01:00
|
|
|
|
2020-11-19 16:46:42 +01:00
|
|
|
for _, fi := range sub {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2018-01-20 19:34:38 +01:00
|
|
|
return ctx.Err()
|
2020-11-19 16:46:42 +01:00
|
|
|
default:
|
2018-01-20 19:34:38 +01:00
|
|
|
}
|
|
|
|
|
2023-10-01 11:40:12 +02:00
|
|
|
err := fn(backend.FileInfo{
|
2020-11-19 16:46:42 +01:00
|
|
|
Name: fi.Name(),
|
|
|
|
Size: fi.Size(),
|
|
|
|
})
|
2018-01-20 13:43:07 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-04-10 21:35:30 +02:00
|
|
|
}
|
2020-11-19 16:46:42 +01:00
|
|
|
return nil
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete removes the repository and all files.
|
2023-05-18 19:18:09 +02:00
|
|
|
func (b *Local) Delete(_ context.Context) error {
|
2024-07-21 15:22:21 +02:00
|
|
|
return os.RemoveAll(b.Path)
|
2015-08-14 15:30:36 +02:00
|
|
|
}
|
2015-03-28 11:50:23 +01:00
|
|
|
|
2015-08-14 15:30:36 +02:00
|
|
|
// Close closes all open files.
|
|
|
|
func (b *Local) Close() error {
|
2016-01-26 22:07:51 +01:00
|
|
|
// this does not need to do anything, all open files are closed within the
|
|
|
|
// same function.
|
2015-08-14 15:30:36 +02:00
|
|
|
return nil
|
|
|
|
}
|
feat(backends/s3): add warmup support before repacks and restores (#5173)
* feat(backends/s3): add warmup support before repacks and restores
This commit introduces basic support for transitioning pack files stored
in cold storage to hot storage on S3 and S3-compatible providers.
To prevent unexpected behavior for existing users, the feature is gated
behind new flags:
- `s3.enable-restore`: opt-in flag (defaults to false)
- `s3.restore-days`: number of days for the restored objects to remain
in hot storage (defaults to `7`)
- `s3.restore-timeout`: maximum time to wait for a single restoration
(default to `1 day`)
- `s3.restore-tier`: retrieval tier at which the restore will be
processed. (default to `Standard`)
As restoration times can be lengthy, this implementation preemptively
restores selected packs to prevent incessant restore-delays during
downloads. This is slightly sub-optimal as we could process packs
out-of-order (as soon as they're transitioned), but this would really
add too much complexity for a marginal gain in speed.
To maintain simplicity and prevent resources exhautions with lots of
packs, no new concurrency mechanisms or goroutines were added. This just
hooks gracefully into the existing routines.
**Limitations:**
- Tests against the backend were not written due to the lack of cold
storage class support in MinIO. Testing was done manually on
Scaleway's S3-compatible object storage. If necessary, we could
explore testing with LocalStack or mocks, though this requires further
discussion.
- Currently, this feature only warms up before restores and repacks
(prune/copy), as those are the two main use-cases I came across.
Support for other commands may be added in future iterations, as long
as affected packs can be calculated in advance.
- The feature is gated behind a new alpha `s3-restore` feature flag to
make it explicit that the feature is still wet behind the ears.
- There is no explicit user notification for ongoing pack restorations.
While I think it is not necessary because of the opt-in flag, showing
some notice may improve usability (but would probably require major
refactoring in the progress bar which I didn't want to start). Another
possibility would be to add a flag to send restores requests and fail
early.
See https://github.com/restic/restic/issues/3202
* ui: warn user when files are warming up from cold storage
* refactor: remove the PacksWarmer struct
It's easier to handle multiple handles in the backend directly, and it
may open the door to reducing the number of requests made to the backend
in the future.
2025-02-01 19:26:27 +01:00
|
|
|
|
|
|
|
// Warmup not implemented
|
|
|
|
func (b *Local) Warmup(_ context.Context, _ []backend.Handle) ([]backend.Handle, error) {
|
|
|
|
return []backend.Handle{}, nil
|
|
|
|
}
|
|
|
|
func (b *Local) WarmupWait(_ context.Context, _ []backend.Handle) error { return nil }
|