From cba6de024fb5e96cf919195f4233ef35d17ed2dc Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Mon, 2 Oct 2023 13:31:04 +0200 Subject: [PATCH] cscli: restore config correctly if acquis.d already exists (#2504) --- cmd/crowdsec-cli/config_backup.go | 4 +++- cmd/crowdsec-cli/config_restore.go | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/crowdsec-cli/config_backup.go b/cmd/crowdsec-cli/config_backup.go index 717fc990b..74fcc8deb 100644 --- a/cmd/crowdsec-cli/config_backup.go +++ b/cmd/crowdsec-cli/config_backup.go @@ -11,7 +11,8 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/cwhub" ) -/* Backup crowdsec configurations to directory : +/* + Backup crowdsec configurations to directory : - Main config (config.yaml) - Profiles config (profiles.yaml) @@ -19,6 +20,7 @@ import ( - Backup of API credentials (local API and online API) - List of scenarios, parsers, postoverflows and collections that are up-to-date - Tainted/local/out-of-date scenarios, parsers, postoverflows and collections +- Acquisition files (acquis.yaml, acquis.d/*.yaml) */ func backupConfigToDirectory(dirPath string) error { var err error diff --git a/cmd/crowdsec-cli/config_restore.go b/cmd/crowdsec-cli/config_restore.go index 55ab7aa9b..90160db98 100644 --- a/cmd/crowdsec-cli/config_restore.go +++ b/cmd/crowdsec-cli/config_restore.go @@ -20,7 +20,8 @@ type OldAPICfg struct { Password string `json:"password"` } -/* Restore crowdsec configurations to directory : +/* + Restore crowdsec configurations to directory : - Main config (config.yaml) - Profiles config (profiles.yaml) @@ -28,6 +29,7 @@ type OldAPICfg struct { - Backup of API credentials (local API and online API) - List of scenarios, parsers, postoverflows and collections that are up-to-date - Tainted/local/out-of-date scenarios, parsers, postoverflows and collections +- Acquisition files (acquis.yaml, acquis.d/*.yaml) */ func restoreConfigFromDirectory(dirPath string, oldBackup bool) error { var err error @@ -111,7 +113,7 @@ func restoreConfigFromDirectory(dirPath string, oldBackup bool) error { /*if there is a acquisition dir, restore its content*/ if csConfig.Crowdsec.AcquisitionDirPath != "" { - if err = os.Mkdir(csConfig.Crowdsec.AcquisitionDirPath, 0o700); err != nil { + if err = os.MkdirAll(csConfig.Crowdsec.AcquisitionDirPath, 0o700); err != nil { return fmt.Errorf("error while creating %s : %s", csConfig.Crowdsec.AcquisitionDirPath, err) } }