Performing a snapshot restore with Db2 container commands
You can restore a snapshot backup of your Db2 database by putting your database in maintenance mode and restoring your volume snapshots.
About this task
Important: In running these steps, you might be at risk of losing your data unless you
take the mentioned precautions.
Procedure
-
Put your cluster in maintenance mode:
DB2U_CLUSTER=$(oc get db2ucluster --no-headers | head -n1 | awk '{print $1}'); echo $DB2U_CLUSTER
oc annotate db2ucluster $DB2U_CLUSTER db2u.databases.ibm.com/maintenance-pause-reconcile=true --overwrite
- Scale down your deployment:
DB2U_STS=$(oc get sts --selector="app=${DB2U_CLUSTER},type=engine" --no-headers | awk '{print $1}'); echo $DB2U_STS
NUM_REPLICAS=$(oc get sts ${DB2U_STS} -ojsonpath={.spec.replicas})
ETCD_STS=$(oc get sts --selector="app=${DB2U_CLUSTER},component=etcd" --no-headers | awk '{print $1}'); echo $ETCD_STS
oc scale sts ${DB2U_STS} --replicas=0
oc scale sts ${ETCD_STS} --replicas=0
- Copy the existing PVC definitions:
oc label pvc c-${DB2U_CLUSTER}-meta app=${DB2U_CLUSTER}
oc label pvc c-${DB2U_CLUSTER}-backup app=${DB2U_CLUSTER}
oc label pvc c-${DB2U_CLUSTER}-share app=${DB2U_CLUSTER}
for PVC in $(oc get pvc -l app=$DB2U_CLUSTER --no-headers | awk '{print $1}'); do oc get pvc $PVC -oyaml > ${PVC}_copy.yaml ; done
- Set your existing PVs reclaim policy to
retain
in case something goes wrong:for PV in $(oc get pv --no-headers | grep $DB2U_CLUSTER | awk '{print $1}'); do oc patch pv $PV -p "{\"spec\":{\"persistentVolumeReclaimPolicy\":\"Retain\"}}" ; done
Important: Manually verify that each PV is set toretain
or you are at risk of losing your data. - Delete the existing PVCs:
oc delete pvc -l app=${DB2U_CLUSTER}
CAUTION:Do this step only if you are confident that you are able to restore your volumesnapshots, and your PV reclaim policies are set toretain
. If you are unsure, try the next step instead by restoring your volumesnapshots to dummy PVCs with different names first. - Restore your volumesnapshot to PVCs with the same name and namespace that you copied in
step 3. The steps will differ depending on your provider:
- Scale up your deployment:
oc scale sts ${ETCD_STS} --replicas=${NUM_REPLICAS}
oc scale sts ${DB2U_STS} --replicas=${NUM_REPLICAS}
- Bring the database out of write-suspend after restoring:
CATALOG_POD=$(oc get po -l name=dashmpp-head-0,app=${DB2U_CLUSTER} --no-headers | awk '{print $1}')
oc exec -it ${CATALOG_POD} -- manage_snapshots --action restore
- Exit maintenance mode:
oc annotate db2ucluster $DB2U_CLUSTER db2u.databases.ibm.com/maintenance-pause-reconcile=false --overwrite