New to Stash? Please start here.
This tutorial will show you how to restore a Stash backup. At first, backup a kubernetes workload volume by following the steps here.
To restore a backup, you need to create a
Recovery CRD by specifying
path and volume where the backup will be restored. Here, is a sample
Recovery to recover the latest snapshot.
$ kubectl apply -f ./docs/examples/tutorial/recovery.yaml recovery "stash-demo" created
apiVersion: stash.appscode.com/v1alpha1 kind: Recovery metadata: name: stash-demo namespace: default spec: repository: name: deployment.stash-demo namespace: default paths: - /source/data recoveredVolumes: - mountPath: /source/data hostPath: path: /data/stash-test/restic-restored
spec.repository.namespecifies the name of the
Repositorycrd that represents respective restic repository.
spec.repository.namespacespecifies the namespace of
spec.pathsspecifies the file-group paths that were backed up using
spec.recoveredVolumesindicates an array of volumes where snapshots will be recovered. Here,
mountPathspecifies where the volume will be mounted. Note that,
Recoveryrecovers data in the same paths from where the backup was taken (specified in
spec.paths). So, volumes must be mounted on those paths or their parent paths.
Stash operator watches for
Recovery objects using Kubernetes api. It collects required snapshot information from the specified
Restic object. Then it creates a recovery job that performs the recovery guides. On completion, job and associated pods are deleted by stash operator. To verify recovery, we can check the
$ kubectl get recovery stash-demo -o yaml apiVersion: stash.appscode.com/v1alpha1 kind: Recovery metadata: clusterName: "" creationTimestamp: 2017-12-04T06:27:16Z deletionGracePeriodSeconds: null deletionTimestamp: null generation: 0 initializers: null name: stash-demo namespace: default resourceVersion: "29671" selfLink: /apis/stash.appscode.com/v1alpha1/namespaces/default/recoveries/stash-demo uid: 2bf74432-d8bc-11e7-be92-0800277f19c0 spec: repository: name: deployment.stash-demo namespace: default paths: - /source/data recoveredVolumes: - mountPath: /source/data hostPath: path: /data/stash-test/restic-restored status: phase: Succeeded
With the help of Snapshot object, stash allows the users to recover a particular snapshot. Now, the users can specify which snapshot to recover. Here, is an example of how to recover a specific snapshot.
First, list the available snapshots,
$ kubectl get snapshots --all-namespaces NAME AGE deployment.stash-demo-d3050010 4m deployment.stash-demo-300d7c13 3m deployment.stash-demo-c24f6d96 2m deployment.stash-demo-80bcc7e3 1m deployment.stash-demo-3e79020e 35s
Now, create a
Recovery with specifying
$ kubectl apply -f ./docs/examples/tutorial/recovery-specific-snapshot.yaml recovery "stash-demo" created
apiVersion: stash.appscode.com/v1alpha1 kind: Recovery metadata: name: stash-demo namespace: default spec: repository: name: deployment.stash-demo namespace: default snapshot: deployment.stash-demo-d3050010 paths: - /source/data recoveredVolumes: - mountPath: /source/data hostPath: path: /data/stash-test/restic-restored
To cleanup the Kubernetes resources created by this tutorial, run:
$ kubectl delete deployment stash-demo $ kubectl delete secret stash-demo $ kubectl delete restic stash-demo $ kubectl delete recovery stash-demo $ kubectl delete repository deployment.stash-demo
If you would like to uninstall Stash operator, please follow the steps here.