mirror of
https://github.com/restic/restic.git
synced 2025-08-26 09:28:01 +00:00
Add Google Cloud Storage as backend
Environment variables:
GOOGLE_PROJECT_ID=gcp-project-id
GOOGLE_APPLICATION_CREDENTIALS=path-to-json-file
Environment variables for test:
RESTIC_TEST_GS_PROJECT_ID=gcp-project-id
RESTIC_TEST_GS_APPLICATION_CREDENTIALS=path-to-json-file
RESTIC_TEST_GS_REPOSITORY=gs:us-central1/test-bucket
Init repository:
$ restic -r gs🪣/[prefix] init
This commit is contained in:

committed by
Alexander Neumann

parent
2c22ff175c
commit
ba75a3884c
57
internal/backend/gs/config.go
Normal file
57
internal/backend/gs/config.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package gs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/restic/restic/internal/options"
|
||||
)
|
||||
|
||||
// Config contains all configuration necessary to connect to an gcs compatible
|
||||
// server.
|
||||
type Config struct {
|
||||
ProjectID string
|
||||
JSONKeyPath string
|
||||
Bucket string
|
||||
Prefix string
|
||||
|
||||
Connections uint `option:"connections" help:"set a limit for the number of concurrent connections (default: 20)"`
|
||||
}
|
||||
|
||||
// NewConfig returns a new Config with the default values filled in.
|
||||
func NewConfig() Config {
|
||||
return Config{
|
||||
Connections: 5,
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
options.Register("gs", Config{})
|
||||
}
|
||||
|
||||
// ParseConfig parses the string s and extracts the gcs config. The
|
||||
// supported configuration format is gs:bucketName:/[prefix].
|
||||
func ParseConfig(s string) (interface{}, error) {
|
||||
if strings.HasPrefix(s, "gs:") {
|
||||
s = s[3:]
|
||||
} else {
|
||||
return nil, errors.New("gs: invalid format")
|
||||
}
|
||||
// use the first entry of the path as the bucket name and the
|
||||
// remainder as prefix
|
||||
path := strings.SplitN(s, ":/", 2)
|
||||
return createConfig(path)
|
||||
}
|
||||
|
||||
func createConfig(p []string) (interface{}, error) {
|
||||
if len(p) < 2 {
|
||||
return nil, errors.New("gs: invalid format, bucket name not found")
|
||||
}
|
||||
cfg := NewConfig()
|
||||
cfg.Bucket = p[0]
|
||||
if p[1] != "" {
|
||||
cfg.Prefix = path.Clean(p[1])
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
Reference in New Issue
Block a user