-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [x] Merge #674 - [x] What should be host-name? - [ ] Set backup/restore session status
- Loading branch information
Showing
14 changed files
with
551 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
apiVersion: stash.appscode.com/v1beta1 | ||
kind: BackupConfiguration | ||
metadata: | ||
name: pvc-backup-config | ||
namespace: demo | ||
spec: | ||
task: | ||
name: pvc-backup-task | ||
repository: | ||
name: hello-repo | ||
schedule: "0 * * * *" | ||
target: | ||
ref: | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
name: test-pvc-source | ||
mountPath: /etc/target | ||
directories: | ||
- /etc/target/dir-01 | ||
- /etc/target/dir-02 | ||
retentionPolicy: | ||
keepLast: 5 | ||
prune: true | ||
|
||
--- | ||
apiVersion: stash.appscode.com/v1beta1 | ||
kind: BackupSession | ||
metadata: | ||
name: pvc-backup-01 | ||
namespace: demo | ||
spec: | ||
backupConfiguration: | ||
name: pvc-backup-config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
kind: Pod | ||
apiVersion: v1 | ||
metadata: | ||
name: test-check-dest | ||
namespace: demo | ||
spec: | ||
containers: | ||
- name: busybox | ||
image: busybox | ||
command: ["/bin/sh","-c"] | ||
args: | ||
- 'set -x; ls /etc/target' | ||
volumeMounts: | ||
- mountPath: /etc/target | ||
name: test-pvc-dest | ||
restartPolicy: Never | ||
volumes: | ||
- name: test-pvc-dest | ||
persistentVolumeClaim: | ||
claimName: test-pvc-dest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
apiVersion: stash.appscode.com/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: pvc-backup | ||
spec: | ||
image: diptadas/stash:pvc | ||
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 | ||
- --enable-cache=false # 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} | ||
#- --metrics-enabled | ||
#- --metrics-pushgateway-url | ||
#- --metrics-dir | ||
#- --metrics-labels | ||
volumeMounts: | ||
- name: ${scratchDirVolume} | ||
mountPath: /tmp/restic/scratch | ||
- name: ${targetVolume} | ||
mountPath: ${TARGET_MOUNT_PATH} | ||
- name: ${secretVolume} | ||
mountPath: /etc/repository/secret | ||
--- | ||
apiVersion: stash.appscode.com/v1beta1 | ||
kind: Function | ||
metadata: | ||
name: pvc-restore | ||
spec: | ||
image: diptadas/stash:pvc | ||
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 | ||
- --enable-cache=false # specified | ||
- --hostname=${HOSTNAME} | ||
- --restore-dirs=${RESTORE_DIRECTORIES} | ||
- --snapshots=${RESTORE_SNAPSHOTS=""} | ||
- --output-dir=${outputDir} | ||
#- --metrics-enabled | ||
#- --metrics-pushgateway-url | ||
#- --metrics-dir | ||
#- --metrics-labels | ||
volumeMounts: | ||
- name: ${scratchDirVolume} | ||
mountPath: /tmp/restic/scratch | ||
- name: ${targetVolume} | ||
mountPath: ${TARGET_MOUNT_PATH} | ||
- name: ${secretVolume} | ||
mountPath: /etc/repository/secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
kind: PersistentVolume | ||
apiVersion: v1 | ||
metadata: | ||
name: test-pv-volume | ||
labels: | ||
type: local | ||
spec: | ||
capacity: | ||
storage: 1Gi | ||
accessModes: | ||
- ReadWriteOnce | ||
hostPath: | ||
path: "/tmp/data" | ||
--- | ||
kind: PersistentVolumeClaim | ||
apiVersion: v1 | ||
metadata: | ||
name: test-pvc-source | ||
namespace: demo | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 256M | ||
--- | ||
kind: PersistentVolumeClaim | ||
apiVersion: v1 | ||
metadata: | ||
name: test-pvc-dest | ||
namespace: demo | ||
spec: | ||
accessModes: | ||
- ReadWriteOnce | ||
resources: | ||
requests: | ||
storage: 256M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
apiVersion: stash.appscode.com/v1beta1 | ||
kind: RestoreSession | ||
metadata: | ||
name: pvc-restore-01 | ||
namespace: demo | ||
spec: | ||
task: | ||
name: pvc-restore-task | ||
repository: | ||
name: hello-repo | ||
target: | ||
ref: | ||
apiVersion: v1 | ||
kind: PersistentVolumeClaim | ||
name: test-pvc-dest | ||
mountPath: /etc/target | ||
rules: | ||
- hosts: | ||
- host-0 | ||
paths: | ||
- /etc/target/dir-01 | ||
- /etc/target/dir-02 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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 | ||
volumes: | ||
- name: target-volume | ||
persistentVolumeClaim: | ||
claimName: ${TARGET_NAME} | ||
- name: secret-volume | ||
secret: | ||
secretName: ${REPOSITORY_SECRET_NAME} | ||
- name: scratch-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 | ||
volumes: | ||
- name: target-volume | ||
persistentVolumeClaim: | ||
claimName: ${TARGET_NAME} | ||
- name: secret-volume | ||
secret: | ||
secretName: ${REPOSITORY_SECRET_NAME} | ||
- name: scratch-volume | ||
emptyDir: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
kind: Pod | ||
apiVersion: v1 | ||
metadata: | ||
name: test-write-soruce | ||
namespace: demo | ||
spec: | ||
containers: | ||
- name: busybox | ||
image: busybox | ||
command: ["/bin/sh","-c"] | ||
args: | ||
- 'set -x; rm -r /etc/target/*; mkdir /etc/target/dir-01; mkdir /etc/target/dir-02; ls /etc/target' | ||
volumeMounts: | ||
- mountPath: /etc/target | ||
name: test-pvc-source | ||
restartPolicy: Never | ||
volumes: | ||
- name: test-pvc-source | ||
persistentVolumeClaim: | ||
claimName: test-pvc-source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
--- | ||
title: Backup and Restore PVC | Stash | ||
description: Backup and Restore PVC using Stash | ||
menu: | ||
product_stash_0.8.3: | ||
identifier: backup_restore_pvc | ||
name: Backup and Restore PVC | ||
parent: guides | ||
weight: 15 | ||
product_name: stash | ||
menu_name: product_stash_0.8.3 | ||
section_menu_id: guides | ||
--- | ||
|
||
> New to Stash? Please start [here](/docs/concepts/README.md). | ||
# Backup and Restore PVC | ||
|
||
In this tutorial we will backup some directories of a persistent volume and restore it in another persistent volume. | ||
|
||
## Before You Begin | ||
|
||
At first, you need to have a Kubernetes cluster, and the `kubectl` command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using [Minikube](https://github.com/kubernetes/minikube). Then install `Stash` in your cluster following the steps [here](/docs/setup/install.md). | ||
|
||
To keep things isolated, we are going to use a separate namespace called `demo` throughout this tutorial. | ||
|
||
```console | ||
$ kubectl create ns demo | ||
namespace/demo created | ||
``` | ||
|
||
>Note: YAML files used in this tutorial are stored in [/docs/examples/pvc](/docs/examples/pvc) directory of [appscode/stash](https://github.com/appscode/stash) repository. | ||
## Create Functions and Tasks | ||
|
||
```bash | ||
$ kubectl apply -f /docs/examples/pvc/functions.yaml; kubectl apply -f /docs/examples/pvc/tasks.yaml | ||
function.stash.appscode.com/pvc-backup created | ||
task.stash.appscode.com/pvc-backup-task created | ||
function.stash.appscode.com/pvc-restore created | ||
task.stash.appscode.com/pvc-restore-task created | ||
``` | ||
|
||
## Create Repository | ||
|
||
```bash | ||
$ kubectl create secret generic gcs-secret -n demo --from-file=./RESTIC_PASSWORD --from-file=./GOOGLE_PROJECT_ID --from-file=./GOOGLE_SERVICE_ACCOUNT_JSON_KEY | ||
secret/gcs-secret created | ||
``` | ||
|
||
```bash | ||
$ kubectl apply -f /docs/examples/pvc/repo.yaml | ||
repository.stash.appscode.com/hello-repo created | ||
``` | ||
|
||
## Create PVC | ||
|
||
Create Persistent Volume and two separate PVC for source and destination. | ||
|
||
```bash | ||
$ kubectl apply -f /docs/examples/pvc/pvc.yaml | ||
persistentvolume/test-pv-volume created | ||
persistentvolumeclaim/test-pvc-source created | ||
persistentvolumeclaim/test-pvc-dest created | ||
``` | ||
|
||
## Write to Source PVC | ||
|
||
```bash | ||
$ kubectl apply -f /docs/examples/pvc/write.yaml | ||
pod/test-write-soruce created | ||
``` | ||
|
||
## Backup Source PVC | ||
|
||
```bash | ||
$ kubectl apply -f /docs/examples/pvc/backup.yaml | ||
backupconfiguration.stash.appscode.com/pvc-backup-config created | ||
backupsession.stash.appscode.com/pvc-backup-01 created | ||
``` | ||
|
||
## Restore to Destination PVC | ||
|
||
```bash | ||
$ kubectl apply -f /docs/examples/pvc/restore.yaml | ||
restoresession.stash.appscode.com/pvc-restore-01 created | ||
``` | ||
|
||
## Check Destination PVC | ||
|
||
```bash | ||
$ kubectl apply -f /docs/examples/pvc/check.yaml | ||
pod/test-check-dest created | ||
``` | ||
|
||
```bash | ||
$ kc logs -n demo -f test-check-dest | ||
+ ls /etc/target | ||
dir-01 | ||
dir-02 | ||
``` | ||
|
||
## Cleanup | ||
|
||
To cleanup the Kubernetes resources created by this tutorial, run: | ||
|
||
```console | ||
$ kubectl delete -f /docs/examples/pvc | ||
$ kubectl delete namespace demo | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.