forked from Altinity/clickhouse-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_custom.go
42 lines (39 loc) · 1.09 KB
/
delete_custom.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package custom
import (
"context"
"fmt"
"github.com/MaXal/clickhouse-backup/v2/pkg/config"
"github.com/MaXal/clickhouse-backup/v2/pkg/utils"
"github.com/apex/log"
"time"
)
func DeleteRemote(ctx context.Context, cfg *config.Config, backupName string) error {
if cfg.Custom.DeleteCommand == "" {
return fmt.Errorf("CUSTOM_DELETE_COMMAND is not defined")
}
startCustomDelete := time.Now()
templateData := map[string]interface{}{
"BACKUP_NAME": backupName,
"backup_name": backupName,
"name": backupName,
"backupName": backupName,
"backup": backupName,
"cfg": cfg,
}
args := ApplyCommandTemplate(cfg.Custom.DeleteCommand, templateData)
err := utils.ExecCmd(ctx, cfg.Custom.CommandTimeoutDuration, args[0], args[1:]...)
if err == nil {
log.WithFields(log.Fields{
"backup": backupName,
"operation": "delete_custom",
"duration": utils.HumanizeDuration(time.Since(startCustomDelete)),
}).Info("done")
return nil
} else {
log.WithFields(log.Fields{
"backup": backupName,
"operation": "delete_custom",
}).Error(err.Error())
return err
}
}