Using Db2 container commands - Db2uInstance
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: When you run these steps, you might be at risk of losing your data unless you
take the mentioned precautions.
Procedure
-
Set an environment variable for your Db2uInstance.
- Run the following command to get the name of your Db2uInstance:
oc get db2uinstance - Replace <db2uinstance_id> with the name of your Db2uInstance:
DB2_CR_ID=<db2uinstance_id>
- Run the following command to get the name of your Db2uInstance:
- Run the following commands to put your clusters in maintenance mode:
oc annotate db2uinstance $DB2_CR_ID db2u.databases.ibm.com/maintenance-pause-reconcile=true --overwrite - Scale down your deployment.
DB2U_STS=$(oc get sts --selector="app=${DB2_CR_ID},type=engine" --no-headers | awk '{print $1}'); echo $DB2U_STSNUM_REPLICAS=$(oc get sts ${DB2U_STS} -ojsonpath={.spec.replicas})ETCD_STS=$(oc get sts --selector="app=${DB2_CR_ID},component=etcd" --no-headers | awk '{print $1}'); echo $ETCD_STSoc scale sts ${DB2U_STS} --replicas=0oc scale sts ${ETCD_STS} --replicas=0 - Copy the existing PVC definitions:
oc label pvc c-${DB2_CR_ID}-meta app=${DB2_CR_ID}oc label pvc c-${DB2_CR_ID}-backup app=${DB2_CR_ID}oc label pvc c-${DB2_CR_ID}-share app=${DB2_CR_ID}for PVC in $(oc get pvc -l app=$DB2_CR_ID --no-headers | awk '{print $1}'); do oc get pvc $PVC -oyaml > ${PVC}_copy.yaml ; done - Set your existing PVs' reclaim policy to
retainin case something goes wrong:for PV in $(oc get pv --no-headers | grep $DB2_CR_ID | awk '{print $1}'); do oc patch pv $PV -p "{\"spec\":{\"persistentVolumeReclaimPolicy\":\"Retain\"}}" ; doneImportant: Manually verify that each PV is set toretainor you are at risk of losing your data. - Delete the existing PVCs:
oc delete pvc -l app=${DB2_CR_ID}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 4. The steps differ depending on your provider:
- Scale up your deployment: Attention: The tools pod is only used in Db2 where more than one node is being used for a deployment. If you are using a one-node Db2 deployment, you do not need to run any commands that use
TOOLS_DEPLOY.oc scale sts ${ETCD_STS} --replicas=${NUM_REPLICAS}oc scale sts ${DB2U_STS} --replicas=${NUM_REPLICAS} - Bring the database out of write-suspend after you restore it.
CATALOG_POD=$(oc get po -l name=dashmpp-head-0,app=${DB2_CR_ID} --no-headers | awk '{print $1}')oc exec -it ${CATALOG_POD} -- manage_snapshots --action restore - Exit maintenance mode.
oc annotate db2uinstance $DB2_CR_ID db2u.databases.ibm.com/maintenance-pause-reconcile=false --overwrite