From 9d7b6d3d9ad77d15d748956706b719b4701ca2e1 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 5 Sep 2024 15:13:00 +0200 Subject: [PATCH] feat(dump): add flag to allow specifying dump path Resolves https://community.vikunja.io/t/vikunja-0-24-docker-bin-sh/2621/3 --- pkg/cmd/dump.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/dump.go b/pkg/cmd/dump.go index 60e9eda2b..e0af6beaf 100644 --- a/pkg/cmd/dump.go +++ b/pkg/cmd/dump.go @@ -17,11 +17,14 @@ package cmd import ( + "path/filepath" "time" + "code.vikunja.io/api/pkg/config" "code.vikunja.io/api/pkg/initialize" "code.vikunja.io/api/pkg/log" "code.vikunja.io/api/pkg/modules/dump" + "github.com/spf13/cobra" ) @@ -29,6 +32,8 @@ func init() { rootCmd.AddCommand(dumpCmd) } +var dumpPathFlag string + var dumpCmd = &cobra.Command{ Use: "dump", Short: "Dump all vikunja data into a zip file. Includes config, files and db.", @@ -37,8 +42,18 @@ var dumpCmd = &cobra.Command{ }, Run: func(_ *cobra.Command, _ []string) { filename := "vikunja-dump_" + time.Now().Format("2006-01-02_15-03-05") + ".zip" - if err := dump.Dump(filename); err != nil { + + path := config.ServiceRootpath.GetString() + if dumpPathFlag != "" { + path = dumpPathFlag + } + + if err := dump.Dump(filepath.Join(path, filename)); err != nil { log.Critical(err.Error()) } }, } + +func init() { + dumpCmd.Flags().StringVarP(&dumpPathFlag, "path", "p", "", "The folder path where the dump file should be saved. Vikunja will use the configured root path or the binary location if the flag is not provided.") +}