feat: add --preserve-config flag to restore command (#1939)
Add a new `--preserve-config` flag to the restore command that allows users to restore database and files from a dump while keeping their existing configuration file untouched.
This commit is contained in:
parent
f14f6ba38f
commit
0a78f7608a
|
|
@ -23,8 +23,11 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var preserveConfig bool
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(restoreCmd)
|
rootCmd.AddCommand(restoreCmd)
|
||||||
|
restoreCmd.Flags().BoolVar(&preserveConfig, "preserve-config", false, "Preserve existing configuration instead of restoring from dump")
|
||||||
}
|
}
|
||||||
|
|
||||||
var restoreCmd = &cobra.Command{
|
var restoreCmd = &cobra.Command{
|
||||||
|
|
@ -35,7 +38,7 @@ var restoreCmd = &cobra.Command{
|
||||||
initialize.FullInitWithoutAsync()
|
initialize.FullInitWithoutAsync()
|
||||||
},
|
},
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
Run: func(_ *cobra.Command, args []string) {
|
||||||
if err := dump.Restore(args[0]); err != nil {
|
if err := dump.Restore(args[0], !preserveConfig); err != nil {
|
||||||
log.Critical(err.Error())
|
log.Critical(err.Error())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ import (
|
||||||
const maxConfigSize = 5 * 1024 * 1024 // 5 MB, should be largely enough
|
const maxConfigSize = 5 * 1024 * 1024 // 5 MB, should be largely enough
|
||||||
|
|
||||||
// Restore takes a zip file name and restores it
|
// Restore takes a zip file name and restores it
|
||||||
func Restore(filename string) error {
|
func Restore(filename string, overrideConfig bool) error {
|
||||||
|
|
||||||
r, err := zip.OpenReader(filename)
|
r, err := zip.OpenReader(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -101,10 +101,15 @@ func Restore(filename string) error {
|
||||||
|
|
||||||
///////
|
///////
|
||||||
// Restore the config file
|
// Restore the config file
|
||||||
|
if overrideConfig {
|
||||||
err = restoreConfig(configFile, dotEnvFile)
|
err = restoreConfig(configFile, dotEnvFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Warning("Preserving existing configuration (--preserve-config flag used)")
|
||||||
|
log.Warning("Configuration preserved - ensure your current config is compatible with the restored data")
|
||||||
|
}
|
||||||
log.Info("Restoring...")
|
log.Info("Restoring...")
|
||||||
|
|
||||||
// Init the configFile again since the restored configuration is most likely different from the one before
|
// Init the configFile again since the restored configuration is most likely different from the one before
|
||||||
|
|
@ -188,7 +193,9 @@ func Restore(filename string) error {
|
||||||
///////
|
///////
|
||||||
// Done
|
// Done
|
||||||
log.Infof("Done restoring dump.")
|
log.Infof("Done restoring dump.")
|
||||||
|
if overrideConfig {
|
||||||
log.Infof("Restart Vikunja to make sure the new configuration file is applied.")
|
log.Infof("Restart Vikunja to make sure the new configuration file is applied.")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue