Skip to content

Commit a47cbd9

Browse files
author
Jeff McCormick
committed
changed pgo-backrest to issue commands using bash and source the .bashrc in order for backrest commands to work on rhel systems
1 parent cf71fee commit a47cbd9

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

pgo-backrest/pgo-backrest.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ import (
99
"k8s.io/client-go/rest"
1010
"k8s.io/client-go/tools/clientcmd"
1111
"os"
12+
"strings"
1213
)
1314

1415
var Clientset *kubernetes.Clientset
1516
var COMMAND, PODNAME, Namespace string
1617

18+
const sourceCommand = `source /.bashrc && `
1719
const backrestCommand = "pgbackrest"
1820

1921
const backrestStanza = "--stanza=db"
20-
const backrestBackupCommand = "backup"
21-
const backrestInfoCommand = "info"
22+
const backrestBackupCommand = `backup`
23+
const backrestInfoCommand = `info`
2224
const containername = "database"
2325

2426
func main() {
@@ -65,16 +67,20 @@ func main() {
6567
panic(err.Error())
6668
}
6769

70+
bashcmd := make([]string, 1)
71+
bashcmd[0] = "bash"
6872
cmd := make([]string, 0)
6973

7074
switch COMMAND {
7175
case crv1.PgtaskBackrestInfo:
7276
log.Info("backrest info command requested")
77+
cmd = append(cmd, sourceCommand)
7378
cmd = append(cmd, backrestCommand)
7479
cmd = append(cmd, backrestStanza)
7580
cmd = append(cmd, backrestBackupCommand)
7681
case crv1.PgtaskBackrestBackup:
7782
log.Info("backrest backup command requested")
83+
cmd = append(cmd, sourceCommand)
7884
cmd = append(cmd, backrestCommand)
7985
cmd = append(cmd, backrestStanza)
8086
cmd = append(cmd, backrestBackupCommand)
@@ -83,8 +89,9 @@ func main() {
8389
os.Exit(2)
8490
}
8591

86-
log.Infof("command is %v ", cmd)
87-
output, stderr, err := kubeapi.ExecToPodThroughAPI(config, Clientset, cmd, containername, PODNAME, Namespace, nil)
92+
log.Infof("command is %s ", strings.Join(cmd, " "))
93+
reader := strings.NewReader(strings.Join(cmd, " "))
94+
output, stderr, err := kubeapi.ExecToPodThroughAPI(config, Clientset, bashcmd, containername, PODNAME, Namespace, reader)
8895
log.Info("output=[" + output + "]")
8996
log.Info("stderr=[" + stderr + "]")
9097

0 commit comments

Comments
 (0)