Skip to content

Commit

Permalink
Backup and restore Postgres DB (#695)
Browse files Browse the repository at this point in the history
- [x] merge #694 
- [x] merge #691 
- [x] Additional arguments can be passed as a single string using `pgArgs` param in Backup Config

Ref: https://github.com/kubedb/postgres/tree/master/hack/docker/postgres-tools/10.2
  • Loading branch information
Dipta Das authored and tamalsaha committed Mar 29, 2019
1 parent dc5d0ce commit 260f79d
Show file tree
Hide file tree
Showing 35 changed files with 4,778 additions and 45 deletions.
33 changes: 33 additions & 0 deletions docs/examples/pg/backup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: stash.appscode.com/v1beta1
kind: BackupConfiguration
metadata:
name: pg-backup-config
namespace: demo
spec:
runtimeSettings:
pod:
serviceAccountName: pg-backup-restore
task:
name: pg-backup-task
params:
- name: HOSTNAME
value: demo-host # TODO: decide
repository:
name: hello-repo
target:
ref:
apiVersion: appcatalog.appscode.com/v1alpha1
kind: AppBinding
name: quick-postgres
retentionPolicy:
keepLast: 5
prune: true
---
apiVersion: stash.appscode.com/v1beta1
kind: BackupSession
metadata:
name: pg-backup-01
namespace: demo
spec:
backupConfiguration:
name: pg-backup-config
83 changes: 83 additions & 0 deletions docs/examples/pg/functions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: update-status
spec:
image: diptadas/stash:pg
args:
- update-status
- --namespace=${NAMESPACE:=default}
- --repository=${REPOSITORY_NAME:=}
- --backup-session=${BACKUP_SESSION:=}
- --restore-session=${RESTORE_SESSION:=}
- --output-dir=${outputDir:=}
volumeMounts:
- name: ${outputVolume}
mountPath: ${outputDir}
---
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: pg-backup
spec:
image: diptadas/stash:pg
args:
- backup-pg
- --provider=${REPOSITORY_PROVIDER:=}
- --bucket=${REPOSITORY_BUCKET:=}
- --endpoint=${REPOSITORY_ENDPOINT:=}
- --path=${REPOSITORY_PREFIX:=}
- --secret-dir=/etc/repository/secret # specified
- --scratch-dir=/tmp/restic/scratch # specified
#- --backup-dirs=${TARGET_DIRECTORIES:=}
- --pg-args=${pgArgs:=} # user input
- --namespace=${NAMESPACE:=default}
- --app-binding=${TARGET_NAME:=}
- --retention-keep-last=${RETENTION_KEEP_LAST:=0} # TODO: complete list
- --retention-keep-tags=${RETENTION_KEEP_TAGS:=}
- --retention-prune=${RETENTION_PRUNE:=false}
- --retention-dry-run=${RETENTION_DRY_RUN:=false}
- --output-dir=${outputDir:=}
#- --metrics-enabled
#- --metrics-pushgateway-url
#- --metrics-dir
#- --metrics-labels
volumeMounts:
- name: ${scratchDirVolume}
mountPath: /tmp/restic/scratch
- name: ${secretVolume}
mountPath: /etc/repository/secret
- name: ${outputVolume}
mountPath: ${outputDir}
---
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: pg-restore
spec:
image: diptadas/stash:pg
args:
- restore-pg
- --provider=${REPOSITORY_PROVIDER:=}
- --bucket=${REPOSITORY_BUCKET:=}
- --endpoint=${REPOSITORY_ENDPOINT:=}
- --path=${REPOSITORY_PREFIX:=}
- --secret-dir=/etc/repository/secret # specified
- --scratch-dir=/tmp/restic/scratch # specified
#- --restore-dirs=${RESTORE_DIRECTORIES:=}
- --pg-args=${pgArgs:=} # user input
- --namespace=${NAMESPACE:=}
- --app-binding=${TARGET_NAME:=}
- --snapshot=${RESTORE_SNAPSHOTS:=} # TODO: sliceVar
- --output-dir=${outputDir:=}
#- --metrics-enabled
#- --metrics-pushgateway-url
#- --metrics-dir
#- --metrics-labels
volumeMounts:
- name: ${scratchDirVolume}
mountPath: /tmp/restic/scratch
- name: ${secretVolume}
mountPath: /etc/repository/secret
- name: ${outputVolume}
mountPath: ${outputDir}
46 changes: 46 additions & 0 deletions docs/examples/pg/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: pg-backup-restore
labels:
app: stash
rules:
- apiGroups:
- stash.appscode.com
resources:
- "*"
verbs: ["*"]
- apiGroups:
- appcatalog.appscode.com
resources:
- "appbindings"
verbs: ["get"]
- apiGroups:
- ""
resources:
- "secrets"
verbs: ["get"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: pg-backup-restore
namespace: demo
labels:
app: stash
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pg-backup-restore
namespace: demo
labels:
app: stash
roleRef:
kind: ClusterRole
apiGroup: rbac.authorization.k8s.io
name: pg-backup-restore
subjects:
- kind: ServiceAccount
name: pg-backup-restore
namespace: demo
11 changes: 11 additions & 0 deletions docs/examples/pg/repo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: stash.appscode.com/v1alpha1
kind: Repository
metadata:
name: hello-repo
namespace: demo
spec:
backend:
gcs:
bucket: hello-bucket
prefix: hello-prefix
storageSecretName: gcs-secret
24 changes: 24 additions & 0 deletions docs/examples/pg/restore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: stash.appscode.com/v1beta1
kind: RestoreSession
metadata:
name: pg-restore-01
namespace: demo
spec:
runtimeSettings:
pod:
serviceAccountName: pg-backup-restore
task:
name: pg-restore-task
params:
- name: HOSTNAME
value: demo-host # TODO: decide
repository:
name: hello-repo
target:
ref:
apiVersion: appcatalog.appscode.com/v1alpha1
kind: AppBinding
name: quick-postgres
rules:
- hosts:
- demo-host
61 changes: 61 additions & 0 deletions docs/examples/pg/tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: stash.appscode.com/v1beta1
kind: Task
metadata:
name: pg-backup-task
spec:
steps:
- name: pg-backup
params:
- name: outputDir
value: /etc/backup # specified
- name: scratchDirVolume
value: scratch-volume # specified
- name: secretVolume
value: secret-volume # specified
- name: outputVolume
value: output-volume # specified
- name: update-status
params:
- name: outputDir
value: /etc/backup # specified
- name: outputVolume
value: output-volume # specified
volumes:
- name: secret-volume
secret:
secretName: ${REPOSITORY_SECRET_NAME}
- name: scratch-volume
emptyDir: {}
- name: output-volume
emptyDir: {}
---
apiVersion: stash.appscode.com/v1beta1
kind: Task
metadata:
name: pg-restore-task
spec:
steps:
- name: pg-restore
params:
- name: outputDir
value: /etc/restore # specified
- name: scratchDirVolume
value: scratch-volume # specified
- name: secretVolume
value: secret-volume # specified
- name: outputVolume
value: output-volume # specified
- name: update-status
params:
- name: outputDir
value: /etc/backup # specified
- name: outputVolume
value: output-volume # specified
volumes:
- name: secret-volume
secret:
secretName: ${REPOSITORY_SECRET_NAME}
- name: scratch-volume
emptyDir: {}
- name: output-volume
emptyDir: {}
26 changes: 18 additions & 8 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import:
- package: github.com/cenkalti/backoff
version: v2.1.1
- package: github.com/codeskyblue/go-sh
version: '0.2'
version: f4ce45e7999ee02d582441c916f1b32fb548dba6
- package: github.com/cpuguy83/go-md2man
version: v1.0.8
- package: github.com/davecgh/go-spew
Expand Down
Loading

0 comments on commit 260f79d

Please sign in to comment.