diff --git a/cmd/dump.go b/cmd/dump.go index 102c6574..14742cf2 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -99,6 +99,10 @@ func dumpCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command, er if preBackupScripts == "" && cmdConfig.configuration != nil { preBackupScripts = cmdConfig.configuration.Dump.Scripts.PreBackup } + postBackupScripts := v.GetString("post-backup-scripts") + if postBackupScripts == "" && cmdConfig.configuration != nil { + postBackupScripts = cmdConfig.configuration.Dump.Scripts.PostBackup + } noDatabaseName := v.GetBool("no-database-name") if !v.IsSet("no-database-name") && cmdConfig.configuration != nil { noDatabaseName = cmdConfig.configuration.Dump.NoDatabaseName @@ -179,7 +183,7 @@ func dumpCmd(passedExecs execs, cmdConfig *cmdConfiguration) (*cobra.Command, er Compressor: compressor, Exclude: exclude, PreBackupScripts: preBackupScripts, - PostBackupScripts: preBackupScripts, + PostBackupScripts: postBackupScripts, SuppressUseDatabase: noDatabaseName, Compact: compact, MaxAllowedPacket: maxAllowedPacket, diff --git a/cmd/dump_test.go b/cmd/dump_test.go index fea44779..7fa882a1 100644 --- a/cmd/dump_test.go +++ b/cmd/dump_test.go @@ -106,6 +106,30 @@ func TestDumpCmd(t *testing.T) { {"incompatible flags: cron/frequency", []string{"--server", "abc", "--target", "file:///foo/bar", "--cron", "0 0 * * *", "--frequency", "10"}, "", true, core.DumpOptions{ DBConn: database.Connection{Host: "abcd", Port: 3306, User: "user2", Pass: "xxxx2"}, }, core.TimerOptions{Frequency: defaultFrequency, Begin: defaultBegin}, &core.PruneOptions{Targets: []storage.Storage{file.New(*fileTargetURL)}, Retention: "1h"}}, + + // pre- and post-backup scripts + {"prebackup scripts", []string{"--server", "abc", "--target", "file:///foo/bar", "--pre-backup-scripts", "/prebackup"}, "", false, core.DumpOptions{ + Targets: []storage.Storage{file.New(*fileTargetURL)}, + MaxAllowedPacket: defaultMaxAllowedPacket, + Compressor: &compression.GzipCompressor{}, + DBConn: database.Connection{Host: "abc", Port: defaultPort}, + PreBackupScripts: "/prebackup", + }, core.TimerOptions{Frequency: defaultFrequency, Begin: defaultBegin}, nil}, + {"postbackup scripts", []string{"--server", "abc", "--target", "file:///foo/bar", "--post-backup-scripts", "/postbackup"}, "", false, core.DumpOptions{ + Targets: []storage.Storage{file.New(*fileTargetURL)}, + MaxAllowedPacket: defaultMaxAllowedPacket, + Compressor: &compression.GzipCompressor{}, + DBConn: database.Connection{Host: "abc", Port: defaultPort}, + PostBackupScripts: "/postbackup", + }, core.TimerOptions{Frequency: defaultFrequency, Begin: defaultBegin}, nil}, + {"prebackup and postbackup scripts", []string{"--server", "abc", "--target", "file:///foo/bar", "--post-backup-scripts", "/postbackup", "--pre-backup-scripts", "/prebackup"}, "", false, core.DumpOptions{ + Targets: []storage.Storage{file.New(*fileTargetURL)}, + MaxAllowedPacket: defaultMaxAllowedPacket, + Compressor: &compression.GzipCompressor{}, + DBConn: database.Connection{Host: "abc", Port: defaultPort}, + PreBackupScripts: "/prebackup", + PostBackupScripts: "/postbackup", + }, core.TimerOptions{Frequency: defaultFrequency, Begin: defaultBegin}, nil}, } for _, tt := range tests {