feat: add backup path (#10649)

## Description
Closes:  #10533

Cosmovisor can cause problems related to disk space when they try backing up, not enough space might fail the node.
A new feature is added to allow user to set a backup path, which can be separated from the node-home directory.
A new env var `DAEMON_BACKUP_DIR` is added. If `DAEMON_BACKUP_DIR` is set, backups will go there instead of `DAEMON_HOME`. 

- [x] add custom data backup dir 
- [x] add tests



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
This commit is contained in:
yaruwangway 2022-01-04 15:25:45 +01:00 committed by GitHub
parent f8b552b42b
commit 344be864de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 129 additions and 62 deletions

View File

@ -39,7 +39,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features ### Features
+ [\#10285](https://github.com/cosmos/cosmos-sdk/pull/10316) Added `run` action. + [\#10285](https://github.com/cosmos/cosmos-sdk/pull/10316) Added `run` action.
+ [\#10533](https://github.com/cosmos/cosmos-sdk/pull/10649) Added environmental variable `DAEMON_BACKUP_DIR` to allow node to set a custom backup directory.
### Deprecated ### Deprecated
+ [\#10285](https://github.com/cosmos/cosmos-sdk/pull/10316) Running `cosmovisor` without the `run` argument. + [\#10285](https://github.com/cosmos/cosmos-sdk/pull/10316) Running `cosmovisor` without the `run` argument.

View File

@ -25,15 +25,16 @@ const (
EnvDownloadBin = "DAEMON_ALLOW_DOWNLOAD_BINARIES" EnvDownloadBin = "DAEMON_ALLOW_DOWNLOAD_BINARIES"
EnvRestartUpgrade = "DAEMON_RESTART_AFTER_UPGRADE" EnvRestartUpgrade = "DAEMON_RESTART_AFTER_UPGRADE"
EnvSkipBackup = "UNSAFE_SKIP_BACKUP" EnvSkipBackup = "UNSAFE_SKIP_BACKUP"
EnvDataBackupPath = "DAEMON_DATA_BACKUP_DIR"
EnvInterval = "DAEMON_POLL_INTERVAL" EnvInterval = "DAEMON_POLL_INTERVAL"
EnvPreupgradeMaxRetries = "DAEMON_PREUPGRADE_MAX_RETRIES" EnvPreupgradeMaxRetries = "DAEMON_PREUPGRADE_MAX_RETRIES"
) )
const ( const (
rootName = "cosmovisor" rootName = "cosmovisor"
genesisDir = "genesis" genesisDir = "genesis"
upgradesDir = "upgrades" upgradesDir = "upgrades"
currentLink = "current" currentLink = "current"
) )
// must be the same as x/upgrade/types.UpgradeInfoFilename // must be the same as x/upgrade/types.UpgradeInfoFilename
@ -47,6 +48,7 @@ type Config struct {
RestartAfterUpgrade bool RestartAfterUpgrade bool
PollInterval time.Duration PollInterval time.Duration
UnsafeSkipBackup bool UnsafeSkipBackup bool
DataBackupPath string
PreupgradeMaxRetries int PreupgradeMaxRetries int
// currently running upgrade // currently running upgrade
@ -129,8 +131,13 @@ func (cfg *Config) CurrentBin() (string, error) {
func GetConfigFromEnv() (*Config, error) { func GetConfigFromEnv() (*Config, error) {
var errs []error var errs []error
cfg := &Config{ cfg := &Config{
Home: os.Getenv(EnvHome), Home: os.Getenv(EnvHome),
Name: os.Getenv(EnvName), Name: os.Getenv(EnvName),
DataBackupPath: os.Getenv(EnvDataBackupPath),
}
if cfg.DataBackupPath == "" {
cfg.DataBackupPath = cfg.Home
} }
var err error var err error
@ -213,6 +220,25 @@ func (cfg *Config) validate() []error {
} }
} }
// check the DataBackupPath
if cfg.UnsafeSkipBackup == true {
return errs
}
// if UnsafeSkipBackup is false, check if the DataBackupPath valid
switch {
case cfg.DataBackupPath == "":
errs = append(errs, errors.New(EnvDataBackupPath + " must not be empty"))
case !filepath.IsAbs(cfg.DataBackupPath):
errs = append(errs, errors.New(cfg.DataBackupPath + " must be an absolute path"))
default:
switch info, err := os.Stat(cfg.DataBackupPath); {
case err != nil:
errs = append(errs, fmt.Errorf("%q must be a valid directory: %w", cfg.DataBackupPath, err))
case !info.IsDir():
errs = append(errs, fmt.Errorf("%q must be a valid directory", cfg.DataBackupPath))
}
}
return errs return errs
} }
@ -305,6 +331,7 @@ func (cfg Config) DetailString() string {
{EnvRestartUpgrade, fmt.Sprintf("%t", cfg.RestartAfterUpgrade)}, {EnvRestartUpgrade, fmt.Sprintf("%t", cfg.RestartAfterUpgrade)},
{EnvInterval, fmt.Sprintf("%s", cfg.PollInterval)}, {EnvInterval, fmt.Sprintf("%s", cfg.PollInterval)},
{EnvSkipBackup, fmt.Sprintf("%t", cfg.UnsafeSkipBackup)}, {EnvSkipBackup, fmt.Sprintf("%t", cfg.UnsafeSkipBackup)},
{EnvDataBackupPath, cfg.DataBackupPath},
{EnvPreupgradeMaxRetries, fmt.Sprintf("%d", cfg.PreupgradeMaxRetries)}, {EnvPreupgradeMaxRetries, fmt.Sprintf("%d", cfg.PreupgradeMaxRetries)},
} }
derivedEntries := []struct{ name, value string }{ derivedEntries := []struct{ name, value string }{
@ -312,6 +339,7 @@ func (cfg Config) DetailString() string {
{"Upgrade Dir", cfg.BaseUpgradeDir()}, {"Upgrade Dir", cfg.BaseUpgradeDir()},
{"Genesis Bin", cfg.GenesisBin()}, {"Genesis Bin", cfg.GenesisBin()},
{"Monitored File", cfg.UpgradeInfoFilePath()}, {"Monitored File", cfg.UpgradeInfoFilePath()},
{"Data Backup Dir", cfg.DataBackupPath},
} }
var sb strings.Builder var sb strings.Builder

View File

@ -32,6 +32,7 @@ type cosmovisorEnv struct {
DownloadBin string DownloadBin string
RestartUpgrade string RestartUpgrade string
SkipBackup string SkipBackup string
DataBackupPath string
Interval string Interval string
PreupgradeMaxRetries string PreupgradeMaxRetries string
} }
@ -44,6 +45,7 @@ func (c cosmovisorEnv) ToMap() map[string]string {
EnvDownloadBin: c.DownloadBin, EnvDownloadBin: c.DownloadBin,
EnvRestartUpgrade: c.RestartUpgrade, EnvRestartUpgrade: c.RestartUpgrade,
EnvSkipBackup: c.SkipBackup, EnvSkipBackup: c.SkipBackup,
EnvDataBackupPath: c.DataBackupPath,
EnvInterval: c.Interval, EnvInterval: c.Interval,
EnvPreupgradeMaxRetries: c.PreupgradeMaxRetries, EnvPreupgradeMaxRetries: c.PreupgradeMaxRetries,
} }
@ -62,6 +64,8 @@ func (c *cosmovisorEnv) Set(envVar, envVal string) {
c.RestartUpgrade = envVal c.RestartUpgrade = envVal
case EnvSkipBackup: case EnvSkipBackup:
c.SkipBackup = envVal c.SkipBackup = envVal
case EnvDataBackupPath:
c.DataBackupPath = envVal
case EnvInterval: case EnvInterval:
c.Interval = envVal c.Interval = envVal
case EnvPreupgradeMaxRetries: case EnvPreupgradeMaxRetries:
@ -145,6 +149,7 @@ func (s *argsTestSuite) TestConfigPaths() {
} }
// Test validate // Test validate
// add more test in test validate
func (s *argsTestSuite) TestValidate() { func (s *argsTestSuite) TestValidate() {
relPath := filepath.Join("testdata", "validate") relPath := filepath.Join("testdata", "validate")
absPath, err := filepath.Abs(relPath) absPath, err := filepath.Abs(relPath)
@ -158,11 +163,27 @@ func (s *argsTestSuite) TestValidate() {
valid bool valid bool
}{ }{
"happy": { "happy": {
cfg: Config{Home: absPath, Name: "bind"}, cfg: Config{Home: absPath, Name: "bind", DataBackupPath: absPath},
valid: true, valid: true,
}, },
"happy with download": { "happy with download": {
cfg: Config{Home: absPath, Name: "bind", AllowDownloadBinaries: true}, cfg: Config{Home: absPath, Name: "bind", AllowDownloadBinaries: true, DataBackupPath: absPath},
valid: true,
},
"happy with skip data backup": {
cfg: Config{Home: absPath, Name: "bind", UnsafeSkipBackup: true, DataBackupPath: absPath},
valid: true,
},
"happy with skip data backup and empty data backup path": {
cfg: Config{Home: absPath, Name: "bind", UnsafeSkipBackup: true, DataBackupPath: ""},
valid: true,
},
"happy with skip data backup and no such data backup path dir": {
cfg: Config{Home: absPath, Name: "bind", UnsafeSkipBackup: true, DataBackupPath: filepath.FromSlash("/no/such/dir")},
valid: true,
},
"happy with skip data backup and relative data backup path": {
cfg: Config{Home: absPath, Name: "bind", UnsafeSkipBackup: true, DataBackupPath: relPath},
valid: true, valid: true,
}, },
"missing home": { "missing home": {
@ -173,7 +194,7 @@ func (s *argsTestSuite) TestValidate() {
cfg: Config{Home: absPath}, cfg: Config{Home: absPath},
valid: false, valid: false,
}, },
"relative path": { "relative home path": {
cfg: Config{Home: relPath, Name: "bind"}, cfg: Config{Home: relPath, Name: "bind"},
valid: false, valid: false,
}, },
@ -181,10 +202,22 @@ func (s *argsTestSuite) TestValidate() {
cfg: Config{Home: testdata, Name: "bind"}, cfg: Config{Home: testdata, Name: "bind"},
valid: false, valid: false,
}, },
"no such dir": { "no such home dir": {
cfg: Config{Home: filepath.FromSlash("/no/such/dir"), Name: "bind"}, cfg: Config{Home: filepath.FromSlash("/no/such/dir"), Name: "bind"},
valid: false, valid: false,
}, },
"empty data backup path": {
cfg: Config{Home: absPath, Name: "bind", DataBackupPath: ""},
valid: false,
},
"no such data backup path dir": {
cfg: Config{Home: absPath, Name: "bind", DataBackupPath: filepath.FromSlash("/no/such/dir")},
valid: false,
},
"relative data backup path": {
cfg: Config{Home: absPath, Name: "bind", DataBackupPath: relPath},
valid: false,
},
} }
for _, tc := range cases { for _, tc := range cases {
@ -202,7 +235,7 @@ func (s *argsTestSuite) TestEnsureBin() {
absPath, err := filepath.Abs(relPath) absPath, err := filepath.Abs(relPath)
s.Require().NoError(err) s.Require().NoError(err)
cfg := Config{Home: absPath, Name: "dummyd"} cfg := Config{Home: absPath, Name: "dummyd", DataBackupPath: absPath}
s.Require().Len(cfg.validate(), 0, "validation errors") s.Require().Len(cfg.validate(), 0, "validation errors")
s.Require().NoError(EnsureBinary(cfg.GenesisBin())) s.Require().NoError(EnsureBinary(cfg.GenesisBin()))
@ -275,6 +308,7 @@ func (s *argsTestSuite) TestDetailString() {
restartAfterUpgrade := true restartAfterUpgrade := true
pollInterval := 406 * time.Millisecond pollInterval := 406 * time.Millisecond
unsafeSkipBackup := false unsafeSkipBackup := false
dataBackupPath := "/home"
preupgradeMaxRetries := 8 preupgradeMaxRetries := 8
cfg := &Config{ cfg := &Config{
Home: home, Home: home,
@ -283,6 +317,7 @@ func (s *argsTestSuite) TestDetailString() {
RestartAfterUpgrade: restartAfterUpgrade, RestartAfterUpgrade: restartAfterUpgrade,
PollInterval: pollInterval, PollInterval: pollInterval,
UnsafeSkipBackup: unsafeSkipBackup, UnsafeSkipBackup: unsafeSkipBackup,
DataBackupPath: dataBackupPath,
PreupgradeMaxRetries: preupgradeMaxRetries, PreupgradeMaxRetries: preupgradeMaxRetries,
} }
@ -294,12 +329,14 @@ func (s *argsTestSuite) TestDetailString() {
fmt.Sprintf("%s: %t", EnvRestartUpgrade, restartAfterUpgrade), fmt.Sprintf("%s: %t", EnvRestartUpgrade, restartAfterUpgrade),
fmt.Sprintf("%s: %s", EnvInterval, pollInterval), fmt.Sprintf("%s: %s", EnvInterval, pollInterval),
fmt.Sprintf("%s: %t", EnvSkipBackup, unsafeSkipBackup), fmt.Sprintf("%s: %t", EnvSkipBackup, unsafeSkipBackup),
fmt.Sprintf("%s: %s", EnvDataBackupPath, home),
fmt.Sprintf("%s: %d", EnvPreupgradeMaxRetries, preupgradeMaxRetries), fmt.Sprintf("%s: %d", EnvPreupgradeMaxRetries, preupgradeMaxRetries),
"Derived Values:", "Derived Values:",
fmt.Sprintf("Root Dir: %s", home), fmt.Sprintf("Root Dir: %s", home),
fmt.Sprintf("Upgrade Dir: %s", home), fmt.Sprintf("Upgrade Dir: %s", home),
fmt.Sprintf("Genesis Bin: %s", home), fmt.Sprintf("Genesis Bin: %s", home),
fmt.Sprintf("Monitored File: %s", home), fmt.Sprintf("Monitored File: %s", home),
fmt.Sprintf("Data Backup Dir: %s", home),
} }
actual := cfg.DetailString() actual := cfg.DetailString()
@ -317,7 +354,7 @@ func (s *argsTestSuite) TestGetConfigFromEnv() {
absPath, perr := filepath.Abs(relPath) absPath, perr := filepath.Abs(relPath)
s.Require().NoError(perr) s.Require().NoError(perr)
newConfig := func(home, name string, downloadBin, restartUpgrade, skipBackup bool, interval, preupgradeMaxRetries int) *Config { newConfig := func(home, name, dataBackupPath string, downloadBin, restartUpgrade, skipBackup bool, interval, preupgradeMaxRetries int) *Config {
return &Config{ return &Config{
Home: home, Home: home,
Name: name, Name: name,
@ -325,6 +362,7 @@ func (s *argsTestSuite) TestGetConfigFromEnv() {
RestartAfterUpgrade: restartUpgrade, RestartAfterUpgrade: restartUpgrade,
PollInterval: time.Millisecond * time.Duration(interval), PollInterval: time.Millisecond * time.Duration(interval),
UnsafeSkipBackup: skipBackup, UnsafeSkipBackup: skipBackup,
DataBackupPath: dataBackupPath,
PreupgradeMaxRetries: preupgradeMaxRetries, PreupgradeMaxRetries: preupgradeMaxRetries,
} }
} }
@ -335,160 +373,160 @@ func (s *argsTestSuite) TestGetConfigFromEnv() {
expectedCfg *Config expectedCfg *Config
expectedErrCount int expectedErrCount int
}{ }{
// EnvHome, EnvName, EnvDownloadBin, EnvRestartUpgrade, EnvSkipBackup, EnvInterval, EnvPreupgradeMaxRetries // EnvHome, EnvName, EnvDownloadBin, EnvRestartUpgrade, EnvSkipBackup, EnvDataBackupPath, EnvDataBackupPath, EnvInterval, EnvPreupgradeMaxRetries
{ {
name: "all bad", name: "all bad",
envVals: cosmovisorEnv{"", "", "bad", "bad", "bad", "bad", "bad"}, envVals: cosmovisorEnv{"", "", "bad", "bad", "bad", "", "bad", "bad"},
expectedCfg: nil, expectedCfg: nil,
expectedErrCount: 7, expectedErrCount: 8,
}, },
{ {
name: "all good", name: "all good",
envVals: cosmovisorEnv{absPath, "testname", "true", "false", "true", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "true", "false", "true", "", "303", "1"},
expectedCfg: newConfig(absPath, "testname", true, false, true, 303, 1), expectedCfg: newConfig(absPath, "testname", absPath, true, false, true, 303, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "nothing set", name: "nothing set",
envVals: cosmovisorEnv{"", "", "", "", "", "", ""}, envVals: cosmovisorEnv{"", "", "", "", "", "", "", ""},
expectedCfg: nil, expectedCfg: nil,
expectedErrCount: 2, expectedErrCount: 3,
}, },
// Note: Home and Name tests are done in TestValidate // Note: Home and Name tests are done in TestValidate
{ {
name: "download bin bad", name: "download bin bad",
envVals: cosmovisorEnv{absPath, "testname", "bad", "false", "true", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "bad", "false", "true", "", "303", "1"},
expectedCfg: nil, expectedCfg: nil,
expectedErrCount: 1, expectedErrCount: 1,
}, },
{ {
name: "download bin not set", name: "download bin not set",
envVals: cosmovisorEnv{absPath, "testname", "", "false", "true", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "", "false", "true", "", "303", "1"},
expectedCfg: newConfig(absPath, "testname", false, false, true, 303, 1), expectedCfg: newConfig(absPath, "testname", absPath, false, false, true, 303, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "download bin true", name: "download bin true",
envVals: cosmovisorEnv{absPath, "testname", "true", "false", "true", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "true", "false", "true", "", "303", "1"},
expectedCfg: newConfig(absPath, "testname", true, false, true, 303, 1), expectedCfg: newConfig(absPath, "testname", absPath, true, false, true, 303, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "download bin false", name: "download bin false",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "true", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "true", "", "303", "1"},
expectedCfg: newConfig(absPath, "testname", false, false, true, 303, 1), expectedCfg: newConfig(absPath, "testname", absPath, false, false, true, 303, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
// EnvHome, EnvName, EnvDownloadBin, EnvRestartUpgrade, EnvSkipBackup, EnvInterval, EnvPreupgradeMaxRetries // EnvHome, EnvName, EnvDownloadBin, EnvRestartUpgrade, EnvSkipBackup, EnvDataBackupPath, EnvInterval, EnvPreupgradeMaxRetries
{ {
name: "restart upgrade bad", name: "restart upgrade bad",
envVals: cosmovisorEnv{absPath, "testname", "true", "bad", "true", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "true", "bad", "true", "", "303", "1"},
expectedCfg: nil, expectedCfg: nil,
expectedErrCount: 1, expectedErrCount: 1,
}, },
{ {
name: "restart upgrade not set", name: "restart upgrade not set",
envVals: cosmovisorEnv{absPath, "testname", "true", "", "true", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "true", "", "true", "", "303", "1"},
expectedCfg: newConfig(absPath, "testname", true, true, true, 303, 1), expectedCfg: newConfig(absPath, "testname", absPath, true, true, true, 303, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "restart upgrade true", name: "restart upgrade true",
envVals: cosmovisorEnv{absPath, "testname", "true", "true", "true", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "true", "true", "true", "", "303", "1"},
expectedCfg: newConfig(absPath, "testname", true, true, true, 303, 1), expectedCfg: newConfig(absPath, "testname", absPath, true, true, true, 303, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "restart upgrade true", name: "restart upgrade true",
envVals: cosmovisorEnv{absPath, "testname", "true", "false", "true", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "true", "false", "true", "", "303", "1"},
expectedCfg: newConfig(absPath, "testname", true, false, true, 303, 1), expectedCfg: newConfig(absPath, "testname", absPath, true, false, true, 303, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
// EnvHome, EnvName, EnvDownloadBin, EnvRestartUpgrade, EnvSkipBackup, EnvInterval, EnvPreupgradeMaxRetries // EnvHome, EnvName, EnvDownloadBin, EnvRestartUpgrade, EnvSkipBackup, EnvDataBackupPath, EnvInterval, EnvPreupgradeMaxRetries
{ {
name: "skip unsafe backups bad", name: "skip unsafe backups bad",
envVals: cosmovisorEnv{absPath, "testname", "true", "false", "bad", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "true", "false", "bad", "", "303", "1"},
expectedCfg: nil, expectedCfg: nil,
expectedErrCount: 1, expectedErrCount: 1,
}, },
{ {
name: "skip unsafe backups not set", name: "skip unsafe backups not set",
envVals: cosmovisorEnv{absPath, "testname", "true", "false", "", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "true", "false", "", "", "303", "1"},
expectedCfg: newConfig(absPath, "testname", true, false, false, 303, 1), expectedCfg: newConfig(absPath, "testname", absPath, true, false, false, 303, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "skip unsafe backups true", name: "skip unsafe backups true",
envVals: cosmovisorEnv{absPath, "testname", "true", "false", "true", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "true", "false", "true", "", "303", "1"},
expectedCfg: newConfig(absPath, "testname", true, false, true, 303, 1), expectedCfg: newConfig(absPath, "testname", absPath, true, false, true, 303, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "skip unsafe backups false", name: "skip unsafe backups false",
envVals: cosmovisorEnv{absPath, "testname", "true", "false", "false", "303", "1"}, envVals: cosmovisorEnv{absPath, "testname", "true", "false", "false", "", "303", "1"},
expectedCfg: newConfig(absPath, "testname", true, false, false, 303, 1), expectedCfg: newConfig(absPath, "testname", absPath, true, false, false, 303, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
// EnvHome, EnvName, EnvDownloadBin, EnvRestartUpgrade, EnvSkipBackup, EnvInterval, EnvPreupgradeMaxRetries // EnvHome, EnvName, EnvDownloadBin, EnvRestartUpgrade, EnvSkipBackup, EnvDataBackupPath, EnvInterval, EnvPreupgradeMaxRetries
{ {
name: "poll interval bad", name: "poll interval bad",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "bad", "1"}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "bad", "1"},
expectedCfg: nil, expectedCfg: nil,
expectedErrCount: 1, expectedErrCount: 1,
}, },
{ {
name: "poll interval 0", name: "poll interval 0",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "0", "1"}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "0", "1"},
expectedCfg: nil, expectedCfg: nil,
expectedErrCount: 1, expectedErrCount: 1,
}, },
{ {
name: "poll interval not set", name: "poll interval not set",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "1"}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "", "1"},
expectedCfg: newConfig(absPath, "testname", false, false, false, 300, 1), expectedCfg: newConfig(absPath, "testname", absPath, false, false, false, 300, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "poll interval 987", name: "poll interval 987",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "987", "1"}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "987", "1"},
expectedCfg: newConfig(absPath, "testname", false, false, false, 987, 1), expectedCfg: newConfig(absPath, "testname", absPath, false, false, false, 987, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "poll interval 1s", name: "poll interval 1s",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "1s", "1"}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "1s", "1"},
expectedCfg: newConfig(absPath, "testname", false, false, false, 1000, 1), expectedCfg: newConfig(absPath, "testname", absPath, false, false, false, 1000, 1),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "poll interval -3m", name: "poll interval -3m",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "-3m", "1"}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "-3m", "1"},
expectedCfg: nil, expectedCfg: nil,
expectedErrCount: 1, expectedErrCount: 1,
}, },
// EnvHome, EnvName, EnvDownloadBin, EnvRestartUpgrade, EnvSkipBackup, EnvInterval, EnvPreupgradeMaxRetries // EnvHome, EnvName, EnvDownloadBin, EnvRestartUpgrade, EnvSkipBackup, EnvDataBackupPath, EnvInterval, EnvPreupgradeMaxRetries
{ {
name: "prepupgrade max retries bad", name: "prepupgrade max retries bad",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "406", "bad"}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "406", "bad"},
expectedCfg: nil, expectedCfg: nil,
expectedErrCount: 1, expectedErrCount: 1,
}, },
{ {
name: "prepupgrade max retries 0", name: "prepupgrade max retries 0",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "406", "0"}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "406", "0"},
expectedCfg: newConfig(absPath, "testname", false, false, false, 406, 0), expectedCfg: newConfig(absPath, "testname", absPath, false, false, false, 406, 0),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "prepupgrade max retries not set", name: "prepupgrade max retries not set",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "406", ""}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "406", ""},
expectedCfg: newConfig(absPath, "testname", false, false, false, 406, 0), expectedCfg: newConfig(absPath, "testname", absPath, false, false, false, 406, 0),
expectedErrCount: 0, expectedErrCount: 0,
}, },
{ {
name: "prepupgrade max retries 5", name: "prepupgrade max retries 5",
envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "406", "5"}, envVals: cosmovisorEnv{absPath, "testname", "false", "false", "false", "", "406", "5"},
expectedCfg: newConfig(absPath, "testname", false, false, false, 406, 5), expectedCfg: newConfig(absPath, "testname", absPath, false, false, false, 406, 5),
expectedErrCount: 0, expectedErrCount: 0,
}, },
} }
@ -521,6 +559,7 @@ func (s *argsTestSuite) TestLogConfigOrError() {
RestartAfterUpgrade: true, RestartAfterUpgrade: true,
PollInterval: 999, PollInterval: 999,
UnsafeSkipBackup: false, UnsafeSkipBackup: false,
DataBackupPath: "/no/place/like/it",
PreupgradeMaxRetries: 20, PreupgradeMaxRetries: 20,
} }
errNormal := fmt.Errorf("this is a single error") errNormal := fmt.Errorf("this is a single error")

View File

@ -131,7 +131,7 @@ func doBackup(cfg *Config) error {
// a destination directory, Format YYYY-MM-DD // a destination directory, Format YYYY-MM-DD
st := time.Now() st := time.Now()
stStr := fmt.Sprintf("%d-%d-%d", st.Year(), st.Month(), st.Day()) stStr := fmt.Sprintf("%d-%d-%d", st.Year(), st.Month(), st.Day())
dst := filepath.Join(cfg.Home, fmt.Sprintf("data"+"-backup-%s", stStr)) dst := filepath.Join(cfg.DataBackupPath, fmt.Sprintf("data"+"-backup-%s", stStr))
Logger.Info().Time("backup start time", st).Msg("starting to take backup of data directory") Logger.Info().Time("backup start time", st).Msg("starting to take backup of data directory")