Backing up and restoring Db2 Warehouse separately from Cloud Pak for Data
You can create an offline backup of a Db2® Warehouse instance separately from Cloud Pak for Data and restore it to the same cluster with the Cloud Pak for Data OpenShift® APIs for Data Protection (OADP) backup and restore utility.
Back up and restore a Db2 Warehouse instance separately from Cloud Pak for Data when Db2 Warehouse backups are very large, or you want to back up Db2 Warehouse more frequently than Cloud Pak for Data.
Backing up and restoring Db2 Warehouse and Cloud Pak for Data separately involves the following tasks:
- Prepare to backup Cloud Pak for Data and Db2 Warehouse.
- Back up Cloud Pak for Data, excluding Db2 Warehouse.
- Back up Db2 Warehouse.
- Restore Cloud Pak for Data and Db2 Warehouse.
Ensure that you source the environment variables before you run the commands in this task.
Preparing for the backup
To prepare for the backup, check the state of nodes, pods, and custom resources. Then prepare to exclude Db2 Warehouse from a Cloud Pak for Data backup by labeling PVCs, PVs, snapshots, and pod template in StatefulSets.
- Check that all nodes are in the
Ready
state:oc get nodes
- Check that all Db2
Warehouse
pods are running in
1/1
:oc get pod | grep c-db2wh
- Check the status of the Db2
Warehouse service.
- Identify the db2ucluster
instance:
oc get db2ucluster | grep db2wh
Keep track of the db2ucluster ID, as it is used in some of the following steps.
- Open a remote shell to the
container.
oc rsh c-db2wh-<xxxxxxxxxxxxx>-db2u-0
- Switch to the database instance owner
db2inst1
:su - db2inst1
- Check that all partitions are
running:
rah 'ps -fea' 2>&1 | grep db2sysc | grep -v grep
- Connect to the
database:
db2 connect to mydb
- Check if you can select from a table by running a simple
query:
db2 select name from sysibm.systables
- Identify the db2ucluster
instance:
- Check that the status of custom resources is
Completed
orReady
.- Check that the status of the IBM Cloud Pak® for Data control plane custom resource is
Completed
state:oc describe ZenService lite-cr | grep "Zen Status"
If the status is
Failed
and the user-home-pvc PVC was increased in size, run the following commands:oc project ${PROJECT_CPFS_OPS} oc get pod | grep zen oc rsh ibm-zen-operator-xxxxxxxx-xxxx vi 4.4.3/roles/0010-infra/tasks/main.yml
Then comment with
#
the sectionsCreate user-home-pvc PVC
andWait until the user-home-pvc PVC is bound
. - Check that the
STATE
of the db2ucluster custom resources are in aReady
state:oc get db2ucluster
Note: If any of the custom resources are inInMaintenance
state, and the db2ucluster is working (for example, you can connect to the databases and they are not in write-suspend mode), delete the following line in the yaml file:db2u.databases.ibm.com/maintenance-pause-reconcile: 'true'
- Check that the status of custom resources in the Cloud Pak for Data project is
Completed
:cpd-cli manage get-cr-status \ --cpd_instance_ns=${PROJECT_CPD_INSTANCE}
- Check that the status of the IBM Cloud Pak® for Data control plane custom resource is
- Label Db2
Warehouse PVCs,
PVs, and snapshots to exclude them from the Cloud Pak for Data backup.
- Label
PVCs:
oc label pvc `oc get pvc --show-labels | grep db2wh | awk '{print $1}'` velero.io/exclude-from-backup=true
- Label
PVs:
oc label pv `oc get pv --show-labels | grep db2wh | awk '{print $1}'` velero.io/exclude-from-backup=true
- Label
snapshots:
oc label volumesnapshots `oc get volumesnapshots --show-labels | grep db2wh | awk '{print $1}'` velero.io/exclude-from-backup=true
- Label
PVCs:
- Label pod templates in StatefulSets.
- Identify
StatefulSets:
oc get sts -l app=${DB2UCLUSTER}
- Take note of original replicas, and scale down
db2ucluster:
oc scale sts c-${DB2UCLUSTER}-db2u --replicas=0
- Review the pod
status:
watch "oc get pod |grep c-db2wh-<xxxxxxxxxxx>"
- Take note of original replicas, and scale down
etcd:
oc scale sts c-${DB2UCLUSTER}-etcd --replicas=0
- Review the pod
status:
watch "oc get pod |grep c-db2wh-<xxxxxxxxxxx>"
- Take note of original replicas, and scale down
tools:
oc scale deploy c-${DB2UCLUSTER}-tools --replicas=0
- Review the pod
status:
watch "oc get pod |grep c-db2wh-<xxxxxxxxxxx>"
- When Db2
Warehouse is scaled
down, label the Pod Templates in StatefulSets and
Deployments:
oc patch StatefulSet c-db2wh-xxxxxxxxxxxxx-db2u --patch '{"spec": {"template": {"metadata": {"labels": {"velero.io/exclude-from-backup": "true"}}}}}' oc patch StatefulSet c-db2wh-xxxxxxxxxxxxx-etcd --patch '{"spec": {"template": {"metadata": {"labels": {"velero.io/exclude-from-backup": "true"}}}}}' oc patch deploy c-db2wh-xxxxxxxxxxx-tools --patch '{"spec": {"template": {"metadata": {"labels": {"velero.io/exclude-from-backup": "true"}}}}}'
oc patch StatefulSet c-db2wh-xxxxxxxxxxxxx-etcd --patch '{"spec": {"template": {"metadata": {"labels": {"velero.io/exclude-from-backup": "true"}}}}}'
oc patch deploy c-db2wh-xxxxxxxxxxx-tools --patch '{"spec": {"template": {"metadata": {"labels": {"velero.io/exclude-from-backup": "true"}}}}}'
- Scale up to original
replicas:
oc scale deploy c-${DB2UCLUSTER}-tools --replicas=1
oc scale sts c-${DB2UCLUSTER}-etcd --replicas=<original-number-of-replicas>
oc scale sts c-${DB2UCLUSTER}-db2u --replicas=<original-number-of-replicas>
- Review the pod
status:
watch "oc get pod |grep c-db2wh-<xxxxxxxxxxx>"
- Repeat step 3 to check the status of the Db2 Warehouse service.
- Identify
StatefulSets:
Backing up Cloud Pak for Data
Back up Cloud Pak for Data with Db2 Warehouse excluded by doing the following steps.
- Quiesce the IBM Cloud Pak for Data control plane.
cpd-cli oadp backup prehooks \ --include-namespaces=${PROJECT_CPD_INSTANCE}
- Create the
backup.
cpd-cli oadp backup create <cpd_backup_name> \ --include-namespaces cpd \ --exclude-resources='Event,Event.events.k8s.io' \ --default-volumes-to-restic \ --cleanup-completed-resources \ --log-level=debug \ --verbose \ --skip-hooks \ --snapshot-volumes=false
In an environment that uses a private container registry, such as an air-gapped cluster, additionally specify the appropriate
--image-prefix
.
The cluster can pull images from the IBM Entitled Registry
Restriction: This option is available only if the cluster can connect to the internet.cpd-cli oadp backup create <cpd_backup_name> \ --include-namespaces cpd \ --exclude-resources='Event,Event.events.k8s.io' \ --default-volumes-to-restic \ --cleanup-completed-resources \ --log-level=debug \ --verbose \ --skip-hooks \ --image-prefix=registry.redhat.io/ubi8 \ --snapshot-volumes=false
The cluster pulls images from a private container registry
Restriction: This option is available only if an administrator moved the backup and restore utility images to a private container registry.cpd-cli oadp backup create <cpd_backup_name> \ --include-namespaces cpd \ --exclude-resources='Event,Event.events.k8s.io' \ --default-volumes-to-restic \ --cleanup-completed-resources \ --log-level=debug \ --verbose \ --skip-hooks \ --image-prefix=${PRIVATE_REGISTRY_LOCATION} \ --snapshot-volumes=false
- To review the status of the backup, run the following
command.
cpd-cli oadp backup status <cpd_backup_name> \ --details
- To review the backup log, run the following
command.
cpd-cli oadp backup logs <cpd_backup_name>
- If the backup failed, delete it, and then restart the
backup.
cpd-cli oadp backup delete <cpd_backup_name>
- Unquiesce the IBM Cloud Pak for Data control plane.
./cpd-cli oadp backup posthooks \ --include-namespaces=${PROJECT_CPD_INSTANCE}
Note: If the wkc-job-unquiesce job is taking a long time to complete, review the pod logs. If the wkf-workflow service pod is in0/1
, restart it. Then the wkc-job-unquiesce job continues.
Backing up Db2 Warehouse
Back up Db2 Warehouse by creating a Container Storage Interface (CSI) volume snapshot.
- Run the Db2
Warehouse
pre-backup hook that invokes Db2 write-suspend.
- Identify the
db2ucluster:
oc get db2ucluster | grep db2wh
The command returns
DB2UCLUSTER=db2wh-<xxxxxxxxxxxxxxxx>
- Identify the catalog
node:
CATALOG_POD=$(oc get po -l name=dashmpp-head-0,app=${DB2UCLUSTER} --no-headers | awk '{print $1}')
- Suspend the Db2
Warehouse
database on the pod that was identified in the previous
step:
oc rsh ${CATALOG_POD} bash
su - db2inst1
cd /db2u/scripts
./manage_snapshots.sh --action suspend
- Identify the
db2ucluster:
- Apply Db2
Warehouse
instance-specific resource label to Db2
instance PVCs and resources (meta and backup PVCs are not currently
labeled).
INSTANCE_ID=$(echo ${DB2UCLUSTER} | cut -d "-" -f2)
oc label pvc c-${DB2UCLUSTER}-meta app=${DB2UCLUSTER} component=db2wh db2u/cpdbr=db2u formation_id=${DB2UCLUSTER} cpdsupport/addOnId=db2wh icpdsupport/app=${DB2UCLUSTER} icpdsupport/createdBy=1000330999 icpdsupport/podSelector=db2u-log icpdsupport/serviceInstanceId=${INSTANCE_ID} role=db type=engine
oc label pvc c-${DB2UCLUSTER}-backup app=${DB2UCLUSTER} component=db2wh db2u/cpdbr=db2u formation_id=${DB2UCLUSTER} icpdsupport/addOnId=db2wh icpdsupport/app=${DB2UCLUSTER} icpdsupport/createdBy=1000330999 icpdsupport/podSelector=db2u-log icpdsupport/serviceInstanceId=${INSTANCE_ID} role=db type=engine
- Create the
backup.
cpd-cli oadp backup create <db2wh_backup_name> \ --include-namespaces=${PROJECT_CPD_INSTANCE} \ --skip-hooks=true \ --snapshot-volumes \ --include-resources='ns,pvc,pv,volumesnapshot,volumesnapshotcontent' \ --selector="app=${DB2UCLUSTER}"
- Resume the Db2
Warehouse
database on the pod (same pod as in step
1):
oc rsh ${CATALOG_POD} bash
su - db2inst1
cd /db2u/scripts
./manage_snapshots.sh --action resume
- Check the status of Db2 Warehouse.
Restoring Cloud Pak for Data and Db2 Warehouse
Restore Cloud Pak for Data and Db2 Warehouse by doing the following steps.
- Note down the following values in the original Cloud Pak for Data project (namespace) yaml:
openshift.io/sa.scc.supplemental-groups: <xxxxxxxxxx/xxxxx>
openshift.io/sa.scc.uid-range: <xxxxxxxxxx/xxxxx>
openshift.io/requester: <requester_id>
openshift.io/sa.scc.mcs: '<xx>:<xxx>,<xxx>'
- Delete the Cloud Pak for Data instance.
- Restore the Db2
Warehouse
volumes:
cpd-cli oadp restore create <db2wh_restore_name> \ --from-backup=<db2wh_backup_name> \ --skip-hooks=true
- Check that the restore is
completed:
cpd-cli oadp restore list
- Change the project uid.
- Edit the Cloud Pak for Data
project:
oc edit namespace ${PROJECT_CPD_INSTANCE}
- Change the following values to the original values from step 1:
openshift.io/sa.scc.supplemental-groups: <xxxxxxxxxx/xxxxx>
openshift.io/sa.scc.uid-range: <xxxxxxxxxx/xxxxx>
openshift.io/requester: <requester_id>
openshift.io/sa.scc.mcs: '<xx>:<xxx>,<xxx>'
Important: If you do not change these values, Cloud Pak for Data pods won't successfully initialize.
- Edit the Cloud Pak for Data
project:
- Repeat the previous step in the ${PROJECT_CPD_OPS} project.
- Restore Cloud Pak for Data control
plane
services:
cpd-cli oadp restore create <cpd_restore_name> \ --from-backup=<cpd_backup_name> \ --skip-hooks=true \ --include-resources='namespaces,zenservices,secrets,certificates.cert-manager.io,certificates.certmanager.k8s.io,issuers.cert-manager.io,issuers.certmanager.k8s.io' \ --log-level=debug \ --verbose
- View the status of the
restore:
cpd-cli oadp restore status <cpd_restore_name> \ --details
- Restore Cloud Pak for Data
services:
cpd-cli oadp restore create <cpd_restore_name> \ --from-backup=<cpd_backup_name> \ --exclude-resources='ImageTag,clients' \ --include-cluster-resources=true \ --scale-wait-timeout 30m \ --log-level=debug \ --verbose
In an environment that uses a private container registry, such as an air-gapped cluster, additionally specify the appropriate
--image-prefix
.
The cluster can pull images from the IBM Entitled Registry
Restriction: This option is available only if the cluster can connect to the internet.cpd-cli oadp restore create <cpd_restore_name> \ --from-backup=<cpd_backup_name> \ --exclude-resources='ImageTag,clients' \ --include-cluster-resources=true \ --image-prefix=registry.redhat.io/ubi8 \ --scale-wait-timeout 30m \ --log-level=debug \ --verbose
The cluster pulls images from a private container registry
Restriction: This option is available only if an administrator moved the backup and restore utility images to a private container registry.cpd-cli oadp restore create <cpd_restore_name> \ --from-backup=<cpd_backup_name> \ --exclude-resources='ImageTag,clients' \ --include-cluster-resources=true \ --image-prefix=${PRIVATE_REGISTRY_LOCATION} \ --scale-wait-timeout 30m \ --log-level=debug \ --verbose
- View the status of the
restore:
cpd-cli oadp restore status <cpd_restore_name> \ --details