Skip to content

Commit

Permalink
Add Stash CLI (#734)
Browse files Browse the repository at this point in the history
fixes #715
  • Loading branch information
Dipta Das authored and tamalsaha committed Apr 18, 2019
1 parent 286792a commit d113b24
Show file tree
Hide file tree
Showing 56 changed files with 3,660 additions and 574 deletions.
19 changes: 19 additions & 0 deletions docs/examples/pv-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Backup Persistent Volume using Stash CLI

```
$ kubectl create ns demo
namespace/demo created
$ kubectl apply -f ./docs/examples/pv-cli/functions.yaml
$ kubectl apply -f ./docs/examples/pv-cli/tasks.yaml
$ kubectl apply -f ./docs/examples/pv-cli/repo_secret.yaml
secret/local-secret created
$ kubectl apply -f ./docs/examples/pv-cli/backup_template.yaml
backupconfigurationtemplate.stash.appscode.com/pvc-backup created
$ kubectl apply -f ./docs/examples/pv-cli/rbac.yaml
clusterrole.rbac.authorization.k8s.io/update-status-roles created
serviceaccount/pvc-backup-restore created
rolebinding.rbac.authorization.k8s.io/update-status-binding created
$ kubectl apply -f ./docs/examples/pv-cli/pv.yam
persistentvolume/demo-pv created
$ stash cli backup-pv --namespace demo --template pvc-backup --volume demo-pv --directories /source/data --mountpath /source/data
```
23 changes: 23 additions & 0 deletions docs/examples/pv-cli/backup_template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: stash.appscode.com/v1beta1
kind: BackupConfigurationTemplate
metadata:
name: pvc-backup
spec:
runtimeSettings:
pod:
serviceAccountName: pvc-backup-restore
backend:
local:
mountPath: /safe/data
hostPath:
path: /data/stash-test/${TARGET_NAMESPACE}/${TARGET_KIND}/${TARGET_NAME}
storageSecretName: local-secret
schedule: "* * * * *"
task:
name: pvc-backup
retentionPolicy:
name: 'keep-last-5'
keepLast: 5
prune: true

# stash cli backup-pv --namespace demo --template pvc-backup --volume demo-pv --directories /source/data --mountpath /source/data
89 changes: 89 additions & 0 deletions docs/examples/pv-cli/functions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: update-status
spec:
image: diptadas/stash:status
args:
- update-status
- --namespace=${NAMESPACE="default"}
- --repository=${REPOSITORY_NAME:=}
- --backup-session=${BACKUP_SESSION:=}
- --restore-session=${RESTORE_SESSION:=}
- --output-dir=${outputDir}
- --enable-status-subresource=${ENABLE_STATUS_SUBRESOURCE:=false}
volumeMounts:
- name: ${outputVolume}
mountPath: ${outputDir}
---
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: pvc-backup
spec:
image: diptadas/stash:status
args:
- backup-pvc
- --provider=${REPOSITORY_PROVIDER}
- --bucket=${REPOSITORY_BUCKET:=}
- --endpoint=${REPOSITORY_ENDPOINT:=}
- --path=${REPOSITORY_PREFIX:=}
- --secret-dir=/etc/repository/secret # specified
- --scratch-dir=/tmp/restic/scratch # specified
- --hostname=${HOSTNAME}
- --backup-dirs=${TARGET_DIRECTORIES}
- --retention-keep-last=${RETENTION_KEEP_LAST:=0}
- --retention-keep-hourly=${RETENTION_KEEP_HOURLY:=0}
- --retention-keep-daily=${RETENTION_KEEP_DAILY:=0}
- --retention-keep-weekly=${RETENTION_KEEP_WEEKLY:=0}
- --retention-keep-monthly=${RETENTION_KEEP_MONTHLY:=0}
- --retention-keep-yearly=${RETENTION_KEEP_YEARLY:=0}
- --retention-keep-tags=${RETENTION_KEEP_TAGS:=}
- --retention-prune=${RETENTION_PRUNE:=false}
- --retention-dry-run=${RETENTION_DRY_RUN:=false}
- --output-dir=${outputDir}
- --enable-cache=${ENABLE_CACHE:=true}
- --max-connections=${MAX_CONNECTIONS:=0}
#- --metrics-enabled
#- --metrics-pushgateway-url
#- --metrics-dir
#- --metrics-labels
volumeMounts:
- name: ${targetVolume}
mountPath: ${TARGET_MOUNT_PATH}
- name: ${secretVolume}
mountPath: /etc/repository/secret
- name: ${outputVolume}
mountPath: ${outputDir}
---
apiVersion: stash.appscode.com/v1beta1
kind: Function
metadata:
name: pvc-restore
spec:
image: diptadas/stash:status
args:
- restore-pvc
- --provider=${REPOSITORY_PROVIDER}
- --bucket=${REPOSITORY_BUCKET:=}
- --endpoint=${REPOSITORY_ENDPOINT:=}
- --path=${REPOSITORY_PREFIX:=}
- --secret-dir=/etc/repository/secret # specified
- --scratch-dir=/tmp/restic/scratch # specified
- --hostname=${HOSTNAME}
- --restore-dirs=${RESTORE_DIRECTORIES}
- --snapshots=${RESTORE_SNAPSHOTS:=}
- --output-dir=${outputDir}
- --enable-cache=${ENABLE_CACHE:=true}
- --max-connections=${MAX_CONNECTIONS:=0}
#- --metrics-enabled
#- --metrics-pushgateway-url
#- --metrics-dir
#- --metrics-labels
volumeMounts:
- name: ${targetVolume}
mountPath: ${TARGET_MOUNT_PATH}
- name: ${secretVolume}
mountPath: /etc/repository/secret
- name: ${outputVolume}
mountPath: ${outputDir}
14 changes: 14 additions & 0 deletions docs/examples/pv-cli/pv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: demo-pv
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
hostPath:
path: /tmp/hostpath-provisioner/pvc-feec96ca-5c1c-11e9-9a75-08002766ec59
type: ""
storageClassName: standard
volumeMode: Filesystem
41 changes: 41 additions & 0 deletions docs/examples/pv-cli/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: update-status-roles
labels:
app: stash
rules:
- apiGroups:
- stash.appscode.com
resources:
- "*"
verbs: ["*"]
- apiGroups:
- ""
resources:
- "events"
verbs: ["create"]
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: pvc-backup-restore
namespace: demo
labels:
app: stash
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: update-status-binding
namespace: demo
labels:
app: stash
roleRef:
kind: ClusterRole
apiGroup: rbac.authorization.k8s.io
name: update-status-roles
subjects:
- kind: ServiceAccount
name: pvc-backup-restore
namespace: demo
9 changes: 9 additions & 0 deletions docs/examples/pv-cli/repo_secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: local-secret
namespace: demo
data:
RESTIC_PASSWORD: bm90QHNlY3JldA==
type: Opaque

67 changes: 67 additions & 0 deletions docs/examples/pv-cli/tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: stash.appscode.com/v1beta1
kind: Task
metadata:
name: pvc-backup-task
spec:
steps:
- name: pvc-backup
params:
- name: outputDir
value: /etc/backup # specified
- name: scratchDirVolume
value: scratch-volume # specified
- name: targetVolume
value: target-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: target-volume
persistentVolumeClaim:
claimName: ${TARGET_NAME}
- name: secret-volume
secret:
secretName: ${REPOSITORY_SECRET_NAME}
- name: output-volume
emptyDir: {}
---
apiVersion: stash.appscode.com/v1beta1
kind: Task
metadata:
name: pvc-restore-task
spec:
steps:
- name: pvc-restore
params:
- name: outputDir
value: /etc/restore # specified
- name: scratchDirVolume
value: scratch-volume # specified
- name: targetVolume
value: target-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: target-volume
persistentVolumeClaim:
claimName: ${TARGET_NAME}
- name: secret-volume
secret:
secretName: ${REPOSITORY_SECRET_NAME}
- name: output-volume
emptyDir: {}
13 changes: 9 additions & 4 deletions glide.lock

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

Loading

0 comments on commit d113b24

Please sign in to comment.