Goal

The document will help you find a way to backup and restore in a proper situation.

Terminology

Backup Kubernetes Volume

Method 1: General way to backup file and folder

We could use kubectl-cp to copy a file or a directory.[1]

$ kubectl cp <file-spec-src> <file-spec-dest>
$ kubectl cp <namespace>/<some-pod>:/tmp/bar_dir /tmp/foo_dir

# Example
$ kubectl cp hub/jupyter-phadmin:. ~/jupyter-phadmin

# Check the folder or file.
$ ls -l

Reverse the source and destination to restore files or directories.

Method 2: Mount volume - Filesystem level backup

In mount volume cases, the backup and restore could be done by filesystem level copy, because there are files or directory in the volume's target path.

Before running the backup instance, please make sure the backup pod is not running.

Find the pvc name of backup volume

$ kubectl get pvc -n hub claim-phadmin
NAME            STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
claim-phadmin   Bound    pvc-660b4c5e-4ee8-42d7-8516-4346870b2fd6   20Gi       RWO            rook-block     5d