mirror of
https://github.com/restic/restic.git
synced 2025-08-21 05:17:35 +00:00
Add Azure Blob Storage as backend
Environment variables: AZURE_ACCOUNT_NAME=storage-account-name AZURE_ACCOUNT_KEY=storage-account-key Environment variables for test: RESTIC_TEST_AZURE_ACCOUNT_NAME=storage-account-name RESTIC_TEST_AZURE_ACCOUNT_KEY=storage-account-key RESTIC_TEST_AZURE_REPOSITORY=azure:restic-test-container Init repository: $ restic -r azure:container-name:/prefix/dir init
This commit is contained in:

committed by
Alexander Neumann

parent
2c22ff175c
commit
3a85b6b7c6
57
internal/backend/azure/config.go
Normal file
57
internal/backend/azure/config.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package azure
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/restic/restic/internal/options"
|
||||
)
|
||||
|
||||
// Config contains all configuration necessary to connect to an azure compatible
|
||||
// server.
|
||||
type Config struct {
|
||||
AccountName string
|
||||
AccountKey string
|
||||
Container 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("azure", Config{})
|
||||
}
|
||||
|
||||
// ParseConfig parses the string s and extracts the azure config. The
|
||||
// configuration format is azure:containerName:/[prefix].
|
||||
func ParseConfig(s string) (interface{}, error) {
|
||||
if strings.HasPrefix(s, "azure:") {
|
||||
s = s[6:]
|
||||
} else {
|
||||
return nil, errors.New("azure: invalid format")
|
||||
}
|
||||
// use the first entry of the path as the container 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("azure: invalid format, container name not found")
|
||||
}
|
||||
cfg := NewConfig()
|
||||
cfg.Container = p[0]
|
||||
if p[1] != "" {
|
||||
cfg.Prefix = path.Clean(p[1])
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
Reference in New Issue
Block a user