Migrate data from from old PVC to a new PVC without change in PVC name

Sometimes it becomes necessary to update the StorageClass and create new PVCs and also migrate all data from existing PVCs to new PVCs created with new StorageClass.

This document will help you migrate all your data from existing PVCs to New PVCs without changing anything in your deployment / statefulset.

Here, it is assumed that you have already created a new StorageClass with updated PX volume parameters.
Reference to PX Volume parameters : Dynamic Provisioning of PVCs

The following are the steps:

  1. Scale down the application using the PVC and ensure that the same is detached.

pxctl volume inspect <pvc-id>

  1. Clone the original PVC volume at Portworx level and verify the same.

pxctl volume clone old-pvc-id --name old-pvc-id-clone
pxctl volume list | grep clone
pxctl volume inspect testvol-clone

  1. Now safely delete the old-pvc-id Portworx volume and create the new PVC with new SC with the same name as old PVC. This will create an empty PVC volume with the same name in detached state.

kubectl delete pvc <old-PVC-id> -n mytest
kubectl create -f newPVC.yaml -n mytest
pxctl volume list |grep <new-PVC-id>

  1. Run a dummy/test Pod to attach and mount the clone volume and copy the mount path of the volume.

mount | grep <cloned-volume>

  1. Use the copied mount path from above, say /var/lib/osd/mount/cloned-vol/ and import the data from attached clone volume to the new PVC volume.

pxctl volume import --src /var/lib/osd/mount/cloned-vol-id/ <new-pvc-id-volume>

This operation will copy all the data from the clone to the newly created PVC.

  1. Now you can scale back the application without modifying the Deployment/ Statefulset.
1 Like