IBM® Db2 Warehouse backup and restore with an LVM snapshot (SMP)

A logical volume manager (LVM) provides a fast and straightforward way to take a backup of your Db2® Warehouse instance. There is little downtime during the backup because the database operations are suspended only momentarily. Also, you do not need to allocate a lot of space for the backup because what’s going to be written are the changes made after that volume after the snapshot. Afterward, if you need to revert to that earlier point in time of the snapshot, you can quickly do so.

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.

  1. 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.

    1. Initialize your disk to create a physical volume. Any data on that disk is lost.
      pvcreate /dev/xvdc
    2. Create a volume group that contains the physical volumes:
      vgcreate vgdata0 /dev/xvdc
    3. Create a linear logical volume from the volume group:
      lvcreate -L 60G -n lvdata0 vgdata0 /dev/xvdc
    4. Format the logical volume and create an ext3 file system:
      mkfs.ext3 /dev/mapper/vgdata0-lvdata0 
    5. Create the file system directory where you want to mount the logical volume.
      mkdir /mnt/clusterfs 
    6. Mount the logical volume to the mount point:
      mount /dev/mapper/vgdata0-lvdata0 /mnt/clusterfs/
  2. 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.

    1. 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
    2. Take a snapshot, specifying the size, name, and volume:
      lvcreate -L 5G -s -n lvdatasnap1 /dev/vgdata0/lvdata0.
    3. 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.
    4. 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 
  3. 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.

    1. Stop the Db2 Warehouse services with the following Docker or Podman command:
      docker exec –it Db2wh stop
      podman exec –it Db2wh stop
    2. Stop the Db2 Warehouse container with the following Docker or Podman command:
      docker stop Db2wh
      podman stop Db2wh
    3. Unmount the logical volume:
      umount /mnt/clusterfs 
    4. Merge the snapshot backup to its origin volume:
      lvconvert --merge /dev/vgdata0/lvdatasnap1
      After you restore from the snapshot, the backup is deleted.
    5. Mount the logical volume:
      mount /dev/vgdata0/lvdata0 /mnt/clusterfs
    6. Start the Db2 Warehouse container with the following Docker or Podman command:
      docker start Db2wh
      podman start Db2wh