Skip to content

Commit

Permalink
Add beforeScript field (#265)
Browse files Browse the repository at this point in the history
Co-authored-by: Kirill Kholodilin <[email protected]>
  • Loading branch information
chrl and Kirill Kholodilin authored May 30, 2021
1 parent ddea52d commit e10cc5b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/pkged.go

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions core/backup/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package backup

import (
"fmt"
"os"
"os/exec"
"time"

"github.com/clivern/walrus/core/model"
Expand Down Expand Up @@ -43,6 +45,19 @@ func (m *Manager) ProcessBackup(message module.BackupMessage) error {
fileName,
)

if message.Cron.Request.BeforeScript != "" {

cmd := exec.Command("sh", "-c", message.Cron.Request.BeforeScript)

cmd.Stdin = os.Stdin
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return err
}
}

// BackupDirectory
if message.Cron.Request.Type == model.BackupDirectory {
err := m.BackupDirectory(
Expand Down
3 changes: 3 additions & 0 deletions core/controller/tower/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func CreateHostCron(c *gin.Context) {
Request: model.Request{
Type: inputs["type"],
Directory: inputs["directory"],
BeforeScript: inputs["beforeScript"],
RetentionDays: retention,

// MySQL
Expand Down Expand Up @@ -382,6 +383,7 @@ func UpdateHostCron(c *gin.Context) {

cronData.Name = inputs["name"]
cronData.Request.Directory = inputs["directory"]
cronData.Request.BeforeScript = inputs["beforeScript"]
cronData.Request.RetentionDays = retention
cronData.Request.Type = inputs["type"]

Expand Down Expand Up @@ -520,6 +522,7 @@ func GetHostCron(c *gin.Context) {
"request": gin.H{
"type": cronData.Request.Type,
"directory": cronData.Request.Directory,
"beforeScript": cronData.Request.BeforeScript,
"retentionDays": cronData.Request.RetentionDays,

// MySQL
Expand Down
1 change: 1 addition & 0 deletions core/model/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const (
type Request struct {
Type string `json:"type"` // @BackupSQLite, @BackupMySQL, @BackupDirectory, @BackupRedis, @BackupPostgreSQL
Directory string `json:"directory"`
BeforeScript string `json:"beforeScript"`
RetentionDays int `json:"retentionDays"`

MySQLHost string `json:"mysqlHost"`
Expand Down
15 changes: 15 additions & 0 deletions web/src/views/Host.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@
</b-select>
</b-field>

<b-field label="Run Script Before">
<b-input
type="text"
v-model="form.beforeScript"
placeholder="/usr/bin/innobackupex --incremental"
>
</b-input>
</b-field>

<template v-if="form.type == '@BackupDirectory'">
<b-field label="Directory Path">
<b-input
Expand Down Expand Up @@ -301,6 +310,7 @@ export default {
name: "",
interval: 30,
retention: 10,
beforeScript: "",
directory: "",

mysqlHost: "127.0.0.1",
Expand Down Expand Up @@ -411,6 +421,7 @@ export default {
this.form.interval = 30;
this.form.retention = 10;
this.form.directory = "";
this.form.beforeScript = "";
this.form.intervalType = "@minute";
this.form.type = "@BackupDirectory";
this.form.hostId = hostId;
Expand All @@ -430,6 +441,7 @@ export default {
this.form.name = data.name;
this.form.interval = data.interval;
this.form.retention = data.request.retentionDays;
this.form.beforeScript = data.request.beforeScript;
this.form.directory = data.request.directory;

this.form.mysqlHost = data.request.mysqlHost;
Expand Down Expand Up @@ -469,6 +481,7 @@ export default {
this.form.interval = 30;
this.form.retention = 10;
this.form.directory = "";
this.form.beforeScript = "";
this.form.intervalType = "@minute";
this.form.type = "@BackupDirectory";
this.form.hostId = hostId;
Expand All @@ -494,6 +507,7 @@ export default {
this.form.interval = 30;
this.form.retention = 10;
this.form.directory = "";
this.form.beforeScript = "";
this.form.intervalType = "@minute";
this.form.type = "@BackupDirectory";
this.form.hostId = "";
Expand Down Expand Up @@ -526,6 +540,7 @@ export default {
name: this.form.name,
interval: this.form.interval.toString(),
retention: this.form.retention.toString(),
beforeScript: this.form.beforeScript,
directory: this.form.directory,
intervalType: this.form.intervalType,

Expand Down

0 comments on commit e10cc5b

Please sign in to comment.