2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

Merge pull request #1437 from restic/fix-1292

s3: Document and remove default prefix
This commit is contained in:
Alexander Neumann 2017-11-25 11:34:26 +01:00
commit 1ebf0e8de8
5 changed files with 37 additions and 22 deletions

View File

@ -4,6 +4,14 @@ released version of restic from the perspective of the user.
Important Changes in 0.X.Y Important Changes in 0.X.Y
========================== ==========================
* The s3 backend used the subdir `restic` within a bucket if no explicit path
after the bucket name was specified. Since this version, restic does not use
this default path any more. If you created a repo on s3 in a bucket without
specifying a path within the bucket, you need to add `/restic` at the end of
the repository specification to access your repo: `s3:s3.amazonaws.com/bucket/restic`
https://github.com/restic/restic/issues/1292
https://github.com/restic/restic/pull/1437
* We've added a local cache for metadata so that restic doesn't need to load * We've added a local cache for metadata so that restic doesn't need to load
all metadata (snapshots, indexes, ...) from the repo each time it starts. By all metadata (snapshots, indexes, ...) from the repo each time it starts. By
default the cache is active, but there's a new global option `--no-cache` default the cache is active, but there's a new global option `--no-cache`

View File

@ -176,6 +176,15 @@ different location, so you need to create it using a different program.
Afterwards, the S3 server (``s3.amazonaws.com``) will redirect restic to Afterwards, the S3 server (``s3.amazonaws.com``) will redirect restic to
the correct endpoint. the correct endpoint.
Until version 0.8.0, restic used a default prefix of ``restic``, so the files
in the bucket were placed in a directory named ``restic``. If you want to
access a repository created with an older version of restic, specify the path
after the bucket name like this:
.. code-block:: console
$ restic -r s3:s3.amazonaws.com/bucket_name/restic [...]
For an S3-compatible server that is not Amazon (like Minio, see below), For an S3-compatible server that is not Amazon (like Minio, see below),
or is only available via HTTP, you can specify the URL to the server or is only available via HTTP, you can specify the URL to the server
like this: ``s3:http://server:port/bucket_name``. like this: ``s3:http://server:port/bucket_name``.

View File

@ -169,7 +169,7 @@ var parseTests = []struct {
Config: s3.Config{ Config: s3.Config{
Endpoint: "eu-central-1", Endpoint: "eu-central-1",
Bucket: "bucketname", Bucket: "bucketname",
Prefix: "restic", Prefix: "",
Connections: 5, Connections: 5,
}, },
}, },
@ -180,7 +180,7 @@ var parseTests = []struct {
Config: s3.Config{ Config: s3.Config{
Endpoint: "hostname.foo", Endpoint: "hostname.foo",
Bucket: "bucketname", Bucket: "bucketname",
Prefix: "restic", Prefix: "",
Connections: 5, Connections: 5,
}, },
}, },
@ -202,7 +202,7 @@ var parseTests = []struct {
Config: s3.Config{ Config: s3.Config{
Endpoint: "eu-central-1", Endpoint: "eu-central-1",
Bucket: "repo", Bucket: "repo",
Prefix: "restic", Prefix: "",
Connections: 5, Connections: 5,
}, },
}, },
@ -224,7 +224,7 @@ var parseTests = []struct {
Config: s3.Config{ Config: s3.Config{
Endpoint: "hostname.foo", Endpoint: "hostname.foo",
Bucket: "repo", Bucket: "repo",
Prefix: "restic", Prefix: "",
Connections: 5, Connections: 5,
}, },
}, },
@ -246,7 +246,7 @@ var parseTests = []struct {
Config: s3.Config{ Config: s3.Config{
Endpoint: "hostname.foo", Endpoint: "hostname.foo",
Bucket: "repo", Bucket: "repo",
Prefix: "restic", Prefix: "",
UseHTTP: true, UseHTTP: true,
Connections: 5, Connections: 5,
}, },

View File

@ -34,11 +34,9 @@ func init() {
options.Register("s3", Config{}) options.Register("s3", Config{})
} }
const defaultPrefix = "restic"
// ParseConfig parses the string s and extracts the s3 config. The two // ParseConfig parses the string s and extracts the s3 config. The two
// supported configuration formats are s3://host/bucketname/prefix and // supported configuration formats are s3://host/bucketname/prefix and
// s3:host:bucketname/prefix. The host can also be a valid s3 region // s3:host/bucketname/prefix. The host can also be a valid s3 region
// name. If no prefix is given the prefix "restic" will be used. // name. If no prefix is given the prefix "restic" will be used.
func ParseConfig(s string) (interface{}, error) { func ParseConfig(s string) (interface{}, error) {
switch { switch {
@ -71,15 +69,15 @@ func ParseConfig(s string) (interface{}, error) {
} }
func createConfig(endpoint string, p []string, useHTTP bool) (interface{}, error) { func createConfig(endpoint string, p []string, useHTTP bool) (interface{}, error) {
var prefix string if len(p) < 1 {
switch {
case len(p) < 1:
return nil, errors.New("s3: invalid format, host/region or bucket name not found") return nil, errors.New("s3: invalid format, host/region or bucket name not found")
case len(p) == 1 || p[1] == "": }
prefix = defaultPrefix
default: var prefix string
if len(p) > 1 && p[1] != "" {
prefix = path.Clean(p[1]) prefix = path.Clean(p[1])
} }
cfg := NewConfig() cfg := NewConfig()
cfg.Endpoint = endpoint cfg.Endpoint = endpoint
cfg.UseHTTP = useHTTP cfg.UseHTTP = useHTTP

View File

@ -9,13 +9,13 @@ var configTests = []struct {
{"s3://eu-central-1/bucketname", Config{ {"s3://eu-central-1/bucketname", Config{
Endpoint: "eu-central-1", Endpoint: "eu-central-1",
Bucket: "bucketname", Bucket: "bucketname",
Prefix: "restic", Prefix: "",
Connections: 5, Connections: 5,
}}, }},
{"s3://eu-central-1/bucketname/", Config{ {"s3://eu-central-1/bucketname/", Config{
Endpoint: "eu-central-1", Endpoint: "eu-central-1",
Bucket: "bucketname", Bucket: "bucketname",
Prefix: "restic", Prefix: "",
Connections: 5, Connections: 5,
}}, }},
{"s3://eu-central-1/bucketname/prefix/directory", Config{ {"s3://eu-central-1/bucketname/prefix/directory", Config{
@ -33,13 +33,13 @@ var configTests = []struct {
{"s3:eu-central-1/foobar", Config{ {"s3:eu-central-1/foobar", Config{
Endpoint: "eu-central-1", Endpoint: "eu-central-1",
Bucket: "foobar", Bucket: "foobar",
Prefix: "restic", Prefix: "",
Connections: 5, Connections: 5,
}}, }},
{"s3:eu-central-1/foobar/", Config{ {"s3:eu-central-1/foobar/", Config{
Endpoint: "eu-central-1", Endpoint: "eu-central-1",
Bucket: "foobar", Bucket: "foobar",
Prefix: "restic", Prefix: "",
Connections: 5, Connections: 5,
}}, }},
{"s3:eu-central-1/foobar/prefix/directory", Config{ {"s3:eu-central-1/foobar/prefix/directory", Config{
@ -57,26 +57,26 @@ var configTests = []struct {
{"s3:https://hostname:9999/foobar", Config{ {"s3:https://hostname:9999/foobar", Config{
Endpoint: "hostname:9999", Endpoint: "hostname:9999",
Bucket: "foobar", Bucket: "foobar",
Prefix: "restic", Prefix: "",
Connections: 5, Connections: 5,
}}, }},
{"s3:https://hostname:9999/foobar/", Config{ {"s3:https://hostname:9999/foobar/", Config{
Endpoint: "hostname:9999", Endpoint: "hostname:9999",
Bucket: "foobar", Bucket: "foobar",
Prefix: "restic", Prefix: "",
Connections: 5, Connections: 5,
}}, }},
{"s3:http://hostname:9999/foobar", Config{ {"s3:http://hostname:9999/foobar", Config{
Endpoint: "hostname:9999", Endpoint: "hostname:9999",
Bucket: "foobar", Bucket: "foobar",
Prefix: "restic", Prefix: "",
UseHTTP: true, UseHTTP: true,
Connections: 5, Connections: 5,
}}, }},
{"s3:http://hostname:9999/foobar/", Config{ {"s3:http://hostname:9999/foobar/", Config{
Endpoint: "hostname:9999", Endpoint: "hostname:9999",
Bucket: "foobar", Bucket: "foobar",
Prefix: "restic", Prefix: "",
UseHTTP: true, UseHTTP: true,
Connections: 5, Connections: 5,
}}, }},