Skip to content

Commit a76427c

Browse files
author
Jeff McCormick
committed
add --pvc-name flag to pgo backup command
1 parent d435358 commit a76427c

File tree

7 files changed

+29
-5
lines changed

7 files changed

+29
-5
lines changed

apis/cr/v1/backup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type PgbackupSpec struct {
3232
BackupPass string `json:"backuppass"`
3333
BackupPort string `json:"backupport"`
3434
BackupStatus string `json:"backupstatus"`
35+
BackupPVC string `json:"backuppvc"`
3536
}
3637

3738
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

apis/cr/v1/deepcopy.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func (in *Pgbackup) DeepCopyInto(out *Pgbackup) {
1616
BackupPass: in.Spec.BackupPass,
1717
BackupPort: in.Spec.BackupPort,
1818
BackupStatus: in.Spec.BackupStatus,
19+
BackupPVC: in.Spec.BackupPVC,
1920
}
2021
out.Status = in.Status
2122
}

apiserver/backupservice/backupimpl.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ func CreateBackup(request *msgs.CreateBackupRequest) msgs.CreateBackupResponse {
172172
resp.Results = append(resp.Results, msg)
173173
break
174174
}
175+
if request.PVCName != "" {
176+
log.Debug("jeff----> backuppvc is " + request.PVCName)
177+
newInstance.Spec.BackupPVC = request.PVCName
178+
}
175179

176180
err = kubeapi.Createpgbackup(apiserver.RESTClient, newInstance, apiserver.Namespace)
177181
if err != nil {

apiservermsgs/backupmsgs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type CreateBackupRequest struct {
3030
Namespace string
3131
Args []string
3232
Selector string
33+
PVCName string
3334
StorageConfig string
3435
}
3536

hugo/content/getting-started/_index.adoc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ pgo create cluster testcluster --autofail
127127
or watch for *NotReady* events on this cluster, and when those occur
128128
to create a failover state machine which acts as a timer for the cluster.
129129
If the timer expires, then a failover is triggered on the cluster turning
130-
one of the cluster replica pods into the replacement primary pod.
130+
one of the cluster replica pods into the replacement primary pod. See
131+
the How It Works documentation for more details on *auto failover*.
131132

132133
=== pgo backup
133134

@@ -175,6 +176,14 @@ for this cluster that might exist. The backup files will still
175176
be left intact but the actual Kubernetes Job will be removed prior
176177
to creating a new Job with the same name.
177178

179+
You can override the PVC used by the backup job with the following:
180+
....
181+
pgo backup mycluster --pvc-name=myremotepvc
182+
....
183+
184+
This might be useful for special backup cases, perhaps to create
185+
a backup on a disaster recovery PVC.
186+
178187
=== pgo delete backup
179188

180189
To delete a backup enter the following:

operator/backup/backup.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ func AddBackupBase(clientset *kubernetes.Clientset, client *rest.RESTClient, job
5656

5757
//create the PVC if necessary
5858
var pvcName string
59-
pvcName, err = pvc.CreatePVC(clientset, &job.Spec.StorageSpec, job.Spec.Name+"-backup", job.Spec.BackupHost, namespace)
60-
if err != nil {
61-
log.Error(err.Error())
59+
if job.Spec.BackupPVC != "" {
60+
pvcName = job.Spec.BackupPVC
6261
} else {
63-
log.Info("created backup PVC =" + pvcName + " in namespace " + namespace)
62+
pvcName, err = pvc.CreatePVC(clientset, &job.Spec.StorageSpec, job.Spec.Name+"-backup", job.Spec.BackupHost, namespace)
63+
if err != nil {
64+
log.Error(err.Error())
65+
} else {
66+
log.Info("created backup PVC =" + pvcName + " in namespace " + namespace)
67+
}
6468
}
6569

6670
//update the pvc name in the CRD

pgo/cmd/backup.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import (
2929
"os"
3030
)
3131

32+
var PVCName string
33+
3234
var backupCmd = &cobra.Command{
3335
Use: "backup",
3436
Short: "perform a Backup",
@@ -53,6 +55,7 @@ func init() {
5355
RootCmd.AddCommand(backupCmd)
5456

5557
backupCmd.Flags().StringVarP(&Selector, "selector", "s", "", "The selector to use for cluster filtering ")
58+
backupCmd.Flags().StringVarP(&PVCName, "pvc-name", "", "", "The PVC name to use for the backup instead of the default backup PVC ")
5659
backupCmd.Flags().StringVarP(&StorageConfig, "storage-config", "", "", "The storage config to use for the backup volume ")
5760
backupCmd.Flags().BoolVarP(&NoPrompt, "no-prompt", "n", false, "--no-prompt causes there to be no command line confirmation when doing a backup command")
5861

@@ -196,6 +199,7 @@ func createBackup(args []string) {
196199
request := new(msgs.CreateBackupRequest)
197200
request.Args = args
198201
request.Selector = Selector
202+
request.PVCName = PVCName
199203
request.StorageConfig = StorageConfig
200204

201205
jsonValue, _ := json.Marshal(request)

0 commit comments

Comments
 (0)