IBM® Db2 Warehouse backup and restore with an LVM snapshot (SMP)
This topic provides a sample procedure for performing a snapshot backup and restore operation by using an LVM. This example does not apply to MPP because LVM is not cluster aware.
For more information, see the snapshot and restore using LVM video.
- Creating your physical and logical volumes
You can use the LVM to combine your physical hard disk drives into a virtual disk. To do this, you must create a physical volume from each of your disks (or partitions) as a user with root authority. You must do this step before you deploy Db2 Warehouse.
- Initialize your disk to create a physical volume. Any data on that disk is lost.
pvcreate /dev/xvdc
- Create a volume group that contains the physical
volumes:
vgcreate vgdata0 /dev/xvdc
- Create a linear logical volume from the volume
group:
lvcreate -L 60G -n lvdata0 vgdata0 /dev/xvdc
- Format the logical volume and create an ext3 file
system:
mkfs.ext3 /dev/mapper/vgdata0-lvdata0
- Create the file system directory where you want to mount the logical volume.
mkdir /mnt/clusterfs
- Mount the logical volume to the mount
point:
mount /dev/mapper/vgdata0-lvdata0 /mnt/clusterfs/
- Initialize your disk to create a physical volume. Any data on that disk is lost.
- Taking a snapshot backup
To back up your Db2 Warehouse instance, you must suspend I/O (to ensure a consistent database) and issue the lvcreate command, as a user with root authority.
- Suspend the database by running the Docker or Podman write-suspend.sh
script:
docker exec -it Db2wh write-suspend
podman exec -it Db2wh write-suspend
- Take a snapshot, specifying the size, name, and
volume:
lvcreate -L 5G -s -n lvdatasnap1 /dev/vgdata0/lvdata0.
- Verify that the snapshot was created by issuing the lvs command and checking
the output for the snapshot that you specified (lvdatasnap1 in the example):Tip: Use the lvs command to monitor the size of the snapshot because it will grow as its delta from the original volume increases. If the snapshot exceeds the allocated space, it is unusable.
- Take the database out of write-suspend state by running the Docker or Podman
write-resume.sh
script:
docker exec -it Db2wh write-resume
podman exec -it Db2wh write-resume
- Suspend the database by running the Docker or Podman write-suspend.sh
script:
- Restoring from a snapshot backup
To restore from a snapshot backup, you use the lvconvert command to roll back your logical volume to its state at the time of the backup, as a user with root authority.
- Stop the Db2 Warehouse services with the following
Docker or Podman
command:
docker exec –it Db2wh stop
podman exec –it Db2wh stop
- Stop the Db2 Warehouse container with the following
Docker or Podman
command:
docker stop Db2wh
podman stop Db2wh
- Unmount the logical volume:
umount /mnt/clusterfs
- Merge the snapshot backup to its origin
volume:
After you restore from the snapshot, the backup is deleted.lvconvert --merge /dev/vgdata0/lvdatasnap1
- Mount the logical volume:
mount /dev/vgdata0/lvdata0 /mnt/clusterfs
- Start the Db2 Warehouse container with the following
Docker or Podman
command:
docker start Db2wh
podman start Db2wh
- Stop the Db2 Warehouse services with the following
Docker or Podman
command: