Skip to content

Commit f7af0fd

Browse files
author
Jeff McCormick
committed
update pgo restore to use restore-opts flag, also update backend code to support it, plus update the restore job template to support it
1 parent cb96903 commit f7af0fd

File tree

6 files changed

+21
-29
lines changed

6 files changed

+21
-29
lines changed

apiserver/backrestservice/backrestimpl.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ func Restore(request *msgs.RestoreRequest) msgs.RestoreResponse {
344344
return resp
345345
}
346346

347-
resp.Results = append(resp.Results, "restore performed on "+request.FromCluster+" to "+request.ToCluster+" type="+request.RestoreType)
347+
resp.Results = append(resp.Results, "restore performed on "+request.FromCluster+" to "+request.ToCluster+" opts="+request.RestoreOpts)
348348

349349
return resp
350350
}
@@ -358,8 +358,7 @@ func getRestoreParams(request *msgs.RestoreRequest) *crv1.Pgtask {
358358
spec.Parameters = make(map[string]string)
359359
spec.Parameters[util.LABEL_BACKREST_RESTORE_FROM_CLUSTER] = request.FromCluster
360360
spec.Parameters[util.LABEL_BACKREST_RESTORE_TO_CLUSTER] = request.ToCluster
361-
spec.Parameters[util.LABEL_BACKREST_RESTORE_TYPE] = request.RestoreType
362-
spec.Parameters[util.LABEL_BACKREST_RESTORE_PITR_TARGET] = request.PITRTarget
361+
spec.Parameters[util.LABEL_BACKREST_RESTORE_OPTS] = request.RestoreOpts
363362

364363
newInstance = &crv1.Pgtask{
365364
ObjectMeta: meta_v1.ObjectMeta{

apiservermsgs/backrestmsgs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ type RestoreResponse struct {
5353
type RestoreRequest struct {
5454
FromCluster string
5555
ToCluster string
56-
RestoreType string
56+
RestoreOpts string
5757
PITRTarget string
5858
}

conf/postgres-operator/backrest-restore-job.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
"name": "STANZA",
3131
"value": "db"
3232
},
33-
{{.DeltaEnvVar}}
33+
{
34+
"name": "BACKREST_CUSTOM_OPTS",
35+
"value": "{{.BackrestRestoreOpts}}"
36+
},
3437
{
3538
"name": "PG_HOSTNAME",
3639
"value": "{{.ToClusterName}}"

operator/backrest/restore.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type backrestRestoreJobTemplateFields struct {
4444
RestoreConfigMapName string
4545
FromClusterPVCName string
4646
ToClusterPVCName string
47+
BackrestRestoreOpts string
4748
DeltaEnvVar string
4849
PITRTargetEnvVar string
4950
CCPImagePrefix string
@@ -109,8 +110,7 @@ func Restore(namespace string, clientset *kubernetes.Clientset, task *crv1.Pgtas
109110
RestoreConfigMapName: task.Spec.Name,
110111
FromClusterPVCName: task.Spec.Parameters[util.LABEL_BACKREST_RESTORE_FROM_CLUSTER],
111112
ToClusterPVCName: task.Spec.Parameters[util.LABEL_BACKREST_RESTORE_TO_CLUSTER],
112-
DeltaEnvVar: getDeltaEnvVar(task.Spec.Parameters[util.LABEL_BACKREST_RESTORE_TYPE]),
113-
PITRTargetEnvVar: getPITREnvVar(task.Spec.Parameters[util.LABEL_BACKREST_RESTORE_TYPE], task.Spec.Parameters[util.LABEL_BACKREST_RESTORE_PITR_TARGET]),
113+
BackrestRestoreOpts: task.Spec.Parameters[util.LABEL_BACKREST_RESTORE_OPTS],
114114

115115
CCPImagePrefix: operator.Pgo.Cluster.CCPImagePrefix,
116116
CCPImageTag: operator.Pgo.Cluster.CCPImageTag,
@@ -169,6 +169,8 @@ func createRestoreJobConfigMap(clientset *kubernetes.Clientset, toName, fromName
169169
return err
170170

171171
}
172+
173+
/**
172174
func getDeltaEnvVar(restoretype string) string {
173175
if restoretype == util.LABEL_BACKREST_RESTORE_DELTA {
174176
return "{ \"name\": \"DELTA\"" + "},"
@@ -185,3 +187,4 @@ func getPITREnvVar(restoretype, pitrtarget string) string {
185187
}
186188
return ""
187189
}
190+
*/

pgo/cmd/restore.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,23 @@ import (
2222
"fmt"
2323
log "github.com/Sirupsen/logrus"
2424
msgs "github.com/crunchydata/postgres-operator/apiservermsgs"
25-
"github.com/crunchydata/postgres-operator/util"
25+
//"github.com/crunchydata/postgres-operator/util"
2626
"github.com/spf13/cobra"
2727
"net/http"
2828
"os"
2929
)
3030

3131
var ToCluster string
32-
var RestoreType string
32+
var RestoreOpts string
3333
var PITRTarget string
3434

3535
var restoreCmd = &cobra.Command{
3636
Use: "restore",
3737
Short: "perform a restore",
3838
Long: `RELOAD performs a pgbackrest restore to a new PG cluster, for example:
3939
pgo restore mycluster --to-cluster=restoredcluster
40-
pgo restore mycluster --restore-type=delta --to-cluster=restoredcluster
41-
pgo restore mycluster --restore-type=full --to-cluster=restoredcluster
42-
pgo restore mycluster --restore-type=pitr --pitr-target="xxx" --to-cluster=restoredcluster`,
40+
pgo restore mycluster --restore-opts="--delta" --to-cluster=restoredcluster
41+
pgo restore mycluster --restore-opts="--delta --type=time --target='2018-08-16 10:34:19.247526-04'" --to-cluster=restoredcluster`,
4342
Run: func(cmd *cobra.Command, args []string) {
4443
log.Debug("restore called")
4544
if len(args) == 0 {
@@ -49,16 +48,8 @@ var restoreCmd = &cobra.Command{
4948
fmt.Println("Error: You must specify the --to-cluster flag.")
5049
os.Exit(2)
5150
}
52-
if RestoreType != util.LABEL_BACKREST_RESTORE_FULL && RestoreType != util.LABEL_BACKREST_RESTORE_PITR && RestoreType != util.LABEL_BACKREST_RESTORE_DELTA {
53-
fmt.Println("Error: You must specify --restore-type value of " + util.LABEL_BACKREST_RESTORE_FULL + " or " + util.LABEL_BACKREST_RESTORE_PITR + " or " + util.LABEL_BACKREST_RESTORE_DELTA)
54-
os.Exit(2)
55-
}
56-
if RestoreType == util.LABEL_BACKREST_RESTORE_PITR && PITRTarget == "" {
57-
fmt.Println("Error: With --restore-type=pitr you mush specify a --pitr-target value which is a PG timestamp string")
58-
os.Exit(2)
59-
}
60-
if RestoreType != util.LABEL_BACKREST_RESTORE_PITR && PITRTarget != "" {
61-
fmt.Println("Error: --pitr-target is only valid when --restore-type=pitr")
51+
if RestoreOpts == "" {
52+
fmt.Println("Error: You must specify --restore-opts flag")
6253
os.Exit(2)
6354
}
6455
restore(args)
@@ -71,7 +62,7 @@ func init() {
7162
RootCmd.AddCommand(restoreCmd)
7263

7364
restoreCmd.Flags().StringVarP(&ToCluster, "to-cluster", "", "", "The name of the new cluster to restore to ")
74-
restoreCmd.Flags().StringVarP(&RestoreType, "restore-type", "", "full", "default is full, other values are delta and pitr")
65+
restoreCmd.Flags().StringVarP(&RestoreOpts, "restore-opts", "", "full", "default is full, other values are entered free form")
7566
restoreCmd.Flags().StringVarP(&PITRTarget, "pitr-target", "", "", "the PITR target which is a PG timestamp such as '2018-08-13 11:25:42.582117-04'")
7667

7768
}
@@ -83,7 +74,7 @@ func restore(args []string) {
8374
request := new(msgs.RestoreRequest)
8475
request.FromCluster = args[0]
8576
request.ToCluster = ToCluster
86-
request.RestoreType = RestoreType
77+
request.RestoreOpts = RestoreOpts
8778

8879
jsonValue, _ := json.Marshal(request)
8980

util/labels.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ const LABEL_POD_NAME = "podname"
5959
const LABEL_BACKREST_COMMAND = "backrest-command"
6060
const LABEL_BACKREST_RESTORE_FROM_CLUSTER = "backrest-restore-from-cluster"
6161
const LABEL_BACKREST_RESTORE_TO_CLUSTER = "backrest-restore-to-cluster"
62-
const LABEL_BACKREST_RESTORE_TYPE = "backrest-restore-type"
63-
const LABEL_BACKREST_RESTORE_FULL = "backrest-restore-full"
64-
const LABEL_BACKREST_RESTORE_PITR = "backrest-restore-pitr"
65-
const LABEL_BACKREST_RESTORE_DELTA = "backrest-restore-delta"
66-
const LABEL_BACKREST_RESTORE_PITR_TARGET = "backrest-restore-pitr-target"
62+
const LABEL_BACKREST_RESTORE_OPTS = "backrest-restore-opts"
6763
const LABEL_BADGER = "crunchy-pgbadger"
6864
const LABEL_BACKUP_TYPE_BASEBACKUP = "pgbasebackup"
6965
const LABEL_BACKUP_TYPE_BACKREST = "pgbackrest"

0 commit comments

Comments
 (0)