Skip to content

Commit

Permalink
Merge pull request #4743 from MichaelEischer/deprecate-s3legacy-layout
Browse files Browse the repository at this point in the history
Deprecate s3legacy layout
  • Loading branch information
MichaelEischer committed Apr 11, 2024
2 parents 8efc3a8 + 591b421 commit 55d56db
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 9 deletions.
14 changes: 12 additions & 2 deletions changelog/unreleased/issue-4602
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
Change: Deprecate legacy index format
Change: Deprecate legacy index format and s3legacy layout

Support for the legacy index format used by restic before version 0.2.0 has
been depreacted and will be removed in the next minor restic version. You can
been deprecated and will be removed in the next minor restic version. You can
use `restic repair index` to update the index to the current format.

It is possible to temporarily reenable support for the legacy index format by
setting the environment variable
`RESTIC_FEATURES=deprecate-legacy-index=false`. Note that this feature flag
will be removed in the next minor restic version.

Support for the s3legacy layout used for the S3 backend before restic 0.7.0
has been deprecated and will be removed in the next minor restic version. You
can migrate your S3 repository using `RESTIC_FEATURES=deprecate-s3-legacy-layout=false restic migrate s3_layout`.

It is possible to temporarily reenable support for the legacy s3layout by
setting the environment variable
`RESTIC_FEATURES=deprecate-s3-legacy-layout=false`. Note that this feature flag
will be removed in the next minor restic version.

https://github.com/restic/restic/issues/4602
https://github.com/restic/restic/pull/4724
https://github.com/restic/restic/pull/4743
2 changes: 2 additions & 0 deletions cmd/restic/cmd_restore_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"
"time"

"github.com/restic/restic/internal/feature"
"github.com/restic/restic/internal/filter"
"github.com/restic/restic/internal/restic"
rtest "github.com/restic/restic/internal/test"
Expand Down Expand Up @@ -274,6 +275,7 @@ func TestRestoreNoMetadataOnIgnoredIntermediateDirs(t *testing.T) {
}

func TestRestoreLocalLayout(t *testing.T) {
defer feature.TestSetFlag(t, feature.Flag, feature.DeprecateS3LegacyLayout, false)()
env, cleanup := withTestEnvironment(t)
defer cleanup()

Expand Down
11 changes: 11 additions & 0 deletions internal/backend/layout/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/restic/restic/internal/backend"
"github.com/restic/restic/internal/debug"
"github.com/restic/restic/internal/errors"
"github.com/restic/restic/internal/feature"
"github.com/restic/restic/internal/fs"
"github.com/restic/restic/internal/restic"
)
Expand Down Expand Up @@ -93,6 +94,8 @@ func hasBackendFile(ctx context.Context, fs Filesystem, dir string) (bool, error
// cannot be detected automatically.
var ErrLayoutDetectionFailed = errors.New("auto-detecting the filesystem layout failed")

var ErrLegacyLayoutFound = errors.New("detected legacy S3 layout. Use `RESTIC_FEATURES=deprecate-s3-legacy-layout=false restic migrate s3_layout` to migrate your repository")

// DetectLayout tries to find out which layout is used in a local (or sftp)
// filesystem at the given path. If repo is nil, an instance of LocalFilesystem
// is used.
Expand Down Expand Up @@ -123,6 +126,10 @@ func DetectLayout(ctx context.Context, repo Filesystem, dir string) (Layout, err
}

if foundKeyFile && !foundKeysFile {
if feature.Flag.Enabled(feature.DeprecateS3LegacyLayout) {
return nil, ErrLegacyLayoutFound
}

debug.Log("found s3 layout at %v", dir)
return &S3LegacyLayout{
Path: dir,
Expand All @@ -145,6 +152,10 @@ func ParseLayout(ctx context.Context, repo Filesystem, layout, defaultLayout, pa
Join: repo.Join,
}
case "s3legacy":
if feature.Flag.Enabled(feature.DeprecateS3LegacyLayout) {
return nil, ErrLegacyLayoutFound
}

l = &S3LegacyLayout{
Path: path,
Join: repo.Join,
Expand Down
3 changes: 3 additions & 0 deletions internal/backend/layout/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

"github.com/restic/restic/internal/backend"
"github.com/restic/restic/internal/feature"
rtest "github.com/restic/restic/internal/test"
)

Expand Down Expand Up @@ -352,6 +353,7 @@ func TestS3LegacyLayout(t *testing.T) {
}

func TestDetectLayout(t *testing.T) {
defer feature.TestSetFlag(t, feature.Flag, feature.DeprecateS3LegacyLayout, false)()
path := rtest.TempDir(t)

var tests = []struct {
Expand Down Expand Up @@ -389,6 +391,7 @@ func TestDetectLayout(t *testing.T) {
}

func TestParseLayout(t *testing.T) {
defer feature.TestSetFlag(t, feature.Flag, feature.DeprecateS3LegacyLayout, false)()
path := rtest.TempDir(t)

var tests = []struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/local/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// Config holds all information needed to open a local repository.
type Config struct {
Path string
Layout string `option:"layout" help:"use this backend directory layout (default: auto-detect)"`
Layout string `option:"layout" help:"use this backend directory layout (default: auto-detect) (deprecated)"`

Connections uint `option:"connections" help:"set a limit for the number of concurrent operations (default: 2)"`
}
Expand Down
2 changes: 2 additions & 0 deletions internal/backend/local/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"testing"

"github.com/restic/restic/internal/backend"
"github.com/restic/restic/internal/feature"
rtest "github.com/restic/restic/internal/test"
)

func TestLayout(t *testing.T) {
defer feature.TestSetFlag(t, feature.Flag, feature.DeprecateS3LegacyLayout, false)()
path := rtest.TempDir(t)

var tests = []struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/s3/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Config struct {
Secret options.SecretString
Bucket string
Prefix string
Layout string `option:"layout" help:"use this backend layout (default: auto-detect)"`
Layout string `option:"layout" help:"use this backend layout (default: auto-detect) (deprecated)"`
StorageClass string `option:"storage-class" help:"set S3 storage class (STANDARD, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING or REDUCED_REDUNDANCY)"`

Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 5)"`
Expand Down
2 changes: 1 addition & 1 deletion internal/backend/sftp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type Config struct {
User, Host, Port, Path string

Layout string `option:"layout" help:"use this backend directory layout (default: auto-detect)"`
Layout string `option:"layout" help:"use this backend directory layout (default: auto-detect) (deprecated)"`
Command string `option:"command" help:"specify command to create sftp connection"`
Args string `option:"args" help:"specify arguments for ssh"`

Expand Down
2 changes: 2 additions & 0 deletions internal/backend/sftp/layout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/restic/restic/internal/backend"
"github.com/restic/restic/internal/backend/sftp"
"github.com/restic/restic/internal/feature"
rtest "github.com/restic/restic/internal/test"
)

Expand All @@ -16,6 +17,7 @@ func TestLayout(t *testing.T) {
t.Skip("sftp server binary not available")
}

defer feature.TestSetFlag(t, feature.Flag, feature.DeprecateS3LegacyLayout, false)()
path := rtest.TempDir(t)

var tests = []struct {
Expand Down
10 changes: 6 additions & 4 deletions internal/feature/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ var Flag = New()

// flag names are written in kebab-case
const (
DeprecateLegacyIndex FlagName = "deprecate-legacy-index"
DeviceIDForHardlinks FlagName = "device-id-for-hardlinks"
DeprecateLegacyIndex FlagName = "deprecate-legacy-index"
DeprecateS3LegacyLayout FlagName = "deprecate-s3-legacy-layout"
DeviceIDForHardlinks FlagName = "device-id-for-hardlinks"
)

func init() {
Flag.SetFlags(map[FlagName]FlagDesc{
DeprecateLegacyIndex: {Type: Beta, Description: "disable support for index format used by restic 0.1.0. Use `restic repair index` to update the index if necessary."},
DeviceIDForHardlinks: {Type: Alpha, Description: "store deviceID only for hardlinks to reduce metadata changes for example when using btrfs subvolumes. Will be removed in a future restic version after repository format 3 is available"},
DeprecateLegacyIndex: {Type: Beta, Description: "disable support for index format used by restic 0.1.0. Use `restic repair index` to update the index if necessary."},
DeprecateS3LegacyLayout: {Type: Beta, Description: "disable support for S3 legacy layout used up to restic 0.7.0. Use `RESTIC_FEATURES=deprecate-s3-legacy-layout=false restic migrate s3_layout` to migrate your S3 repository if necessary."},
DeviceIDForHardlinks: {Type: Alpha, Description: "store deviceID only for hardlinks to reduce metadata changes for example when using btrfs subvolumes. Will be removed in a future restic version after repository format 3 is available"},
})
}

0 comments on commit 55d56db

Please sign in to comment.