mirror of
https://github.com/cupcakearmy/autorestic.git
synced 2024-12-22 16:26:25 +00:00
add config version to ensure compatibility
This commit is contained in:
parent
c250391f67
commit
113a97c283
@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Improved error handling
|
- Improved error handling
|
||||||
- Allow for specific snapshot to be restored
|
- Allow for specific snapshot to be restored
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- rclone in docker volumes
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- [Breaking Change] Declaration of docker volumes. See: https://autorestic.vercel.app/migration/1.4_1.5
|
- [Breaking Change] Declaration of docker volumes. See: https://autorestic.vercel.app/migration/1.4_1.5
|
||||||
@ -20,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [1.4.1] - 2021-10-31
|
## [1.4.1] - 2021-10-31
|
||||||
|
|
||||||
### Fixes
|
### Fixed
|
||||||
|
|
||||||
- Numeric values from config files not being passed to env.
|
- Numeric values from config files not being passed to env.
|
||||||
|
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
# Migration from `1.4` to `1.5`
|
# Migration from `1.4` to `1.5`
|
||||||
|
|
||||||
|
## Config files
|
||||||
|
|
||||||
|
- The config file now required to have a version number. This has to be added with `version: 2` at the root.
|
||||||
|
- Hooks now optionally support `dir: /some/dir` in the [options object](https://pkg.go.dev/github.com/cupcakearmy/autorestic/internal#Hooks).
|
||||||
|
- Docker volumes don't get prefixed with `volume:` anymore, rather you have to set the `type: volume` in the [location config](https://pkg.go.dev/github.com/cupcakearmy/autorestic/internal#Hooks).
|
||||||
|
|
||||||
|
See detailed instructions below.
|
||||||
|
|
||||||
## Hooks
|
## Hooks
|
||||||
|
|
||||||
Since `1.5` multiple sources for a location are possible.
|
Since `1.5` multiple sources for a location are possible.
|
||||||
|
@ -26,6 +26,7 @@ type OptionMap map[string][]interface{}
|
|||||||
type Options map[string]OptionMap
|
type Options map[string]OptionMap
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
Version string `yaml:"version"`
|
||||||
Extras interface{} `yaml:"extras"`
|
Extras interface{} `yaml:"extras"`
|
||||||
Locations map[string]Location `yaml:"locations"`
|
Locations map[string]Location `yaml:"locations"`
|
||||||
Backends map[string]Backend `yaml:"backends"`
|
Backends map[string]Backend `yaml:"backends"`
|
||||||
@ -35,7 +36,19 @@ type Config struct {
|
|||||||
var once sync.Once
|
var once sync.Once
|
||||||
var config *Config
|
var config *Config
|
||||||
|
|
||||||
|
func exitConfig(err error, msg string) {
|
||||||
|
if err != nil {
|
||||||
|
colors.Error.Println(err)
|
||||||
|
}
|
||||||
|
if msg != "" {
|
||||||
|
colors.Error.Println(msg)
|
||||||
|
}
|
||||||
|
lock.Unlock()
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
func GetConfig() *Config {
|
func GetConfig() *Config {
|
||||||
|
|
||||||
if config == nil {
|
if config == nil {
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
if err := viper.ReadInConfig(); err == nil {
|
if err := viper.ReadInConfig(); err == nil {
|
||||||
@ -53,12 +66,24 @@ func GetConfig() *Config {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var versionConfig interface{}
|
||||||
|
viper.UnmarshalKey("version", &versionConfig)
|
||||||
|
if versionConfig == nil {
|
||||||
|
exitConfig(nil, "no version specified in config file. please see docs on how to migrate")
|
||||||
|
}
|
||||||
|
version, ok := versionConfig.(int)
|
||||||
|
if !ok {
|
||||||
|
exitConfig(nil, "version specified in config file is not an int")
|
||||||
|
} else {
|
||||||
|
// Check for version
|
||||||
|
if version != 2 {
|
||||||
|
exitConfig(nil, "unsupported version number. please check the docs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
config = &Config{}
|
config = &Config{}
|
||||||
if err := viper.UnmarshalExact(config); err != nil {
|
if err := viper.UnmarshalExact(config); err != nil {
|
||||||
colors.Error.Println(err)
|
exitConfig(err, "Could not parse config file!")
|
||||||
colors.Error.Println("Could not parse config file!")
|
|
||||||
lock.Unlock()
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user