@@ -9,16 +9,18 @@ import (
99 "k8s.io/client-go/rest"
1010 "k8s.io/client-go/tools/clientcmd"
1111 "os"
12+ "strings"
1213)
1314
1415var Clientset * kubernetes.Clientset
1516var COMMAND , PODNAME , Namespace string
1617
18+ const sourceCommand = `source /.bashrc && `
1719const backrestCommand = "pgbackrest"
1820
1921const backrestStanza = "--stanza=db"
20- const backrestBackupCommand = " backup"
21- const backrestInfoCommand = " info"
22+ const backrestBackupCommand = ` backup`
23+ const backrestInfoCommand = ` info`
2224const containername = "database"
2325
2426func 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