6.10.1 Backing up the KVM host Using Snapshot-Based Backup
This procedure describes how to take a snapshot-based backup of the KVM host.
The values shown in the following steps are examples and you may need to substitute different values to match your situation.
All steps must be performed as the root
user.
- Prepare a destination to hold the backup.
The destination should reside outside of the local machine, such as a writable NFS location, and be large enough to hold the backup. For non-customized partitions, the space needed for holding the backup is approximately 50 GB.
You can use the following commands to prepare a backup destination using NFS.
# mkdir -p /root/remote_FS # mount -t nfs -o rw,intr,soft,proto=tcp,nolock ip_address:/nfs_location/ /root/remote_FS
In the
mount
command, ip_address is the IP address of the NFS server, and nfs_location is the NFS location holding the backups. - Remove the
LVDoNotRemoveOrUse
logical volume.The logical volume
/dev/VGExaDb/LVDoNotRemoveOrUse
is a placeholder to make sure there is always free space available to create a snapshot.Use the following script to check for the existence of the
LVDoNotRemoveOrUse
logical volume and remove it if present.lvm lvdisplay --ignorelockingfailure /dev/VGExaDb/LVDoNotRemoveOrUse if [ $? -eq 0 ]; then # LVDoNotRemoveOrUse logical volume exists. lvm lvremove -f /dev/VGExaDb/LVDoNotRemoveOrUse if [ $? -ne 0 ]; then echo "Unable to remove logical volume: LVDoNotRemoveOrUse. Do not proceed with backup." fi fi
If the
LVDoNotRemoveOrUse
logical volume does not exist, then do not proceed with the remaining steps and determine the reason. - Determine the active system volume.You can use the
imageinfo
command and examine the device hosting the active system partition.# imageinfo Kernel version: 4.14.35-1902.5.1.4.el7uek.x86_64 #2 SMP Wed Oct 9 19:29:16 PDT 2019 x86_64 Image kernel version: 4.14.35-1902.5.1.4.el7uek Image version: 19.3.1.0.0.191018 Image activated: 2019-11-04 19:18:32 -0800 Image status: success Node type: KVMHOST System partition on device: /dev/mapper/VGExaDb-LVDbSys1
In the
imageinfo
output, the system partition device ends with the name of the logical volume supports the active root (/
) file system. Depending on the system image that is in use, the logical volume name isLVDbSys1
orLVDbSys2
. Likewise, the logical volume for the/var
file system is eitherLVDbVar1
orLVDbVar2
.You can also confirm the active devices by using the
df -hT
command and examining the output associated with the root (/
) and/var
file systems. For example:# df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 378G 0 378G 0% /dev tmpfs tmpfs 755G 1.0G 754G 1% /dev/shm tmpfs tmpfs 378G 4.8M 378G 1% /run tmpfs tmpfs 378G 0 378G 0% /sys/fs/cgroup /dev/mapper/VGExaDb-LVDbSys1 xfs 15G 7.7G 7.4G 52% / /dev/sda1 xfs 510M 112M 398M 22% /boot /dev/sda2 vfat 254M 8.5M 246M 4% /boot/efi /dev/mapper/VGExaDb-LVDbHome xfs 4.0G 33M 4.0G 1% /home /dev/mapper/VGExaDb-LVDbVar1 xfs 2.0G 139M 1.9G 7% /var /dev/mapper/VGExaDb-LVDbVarLog xfs 18G 403M 18G 3% /var/log /dev/mapper/VGExaDb-LVDbVarLogAudit xfs 1014M 143M 872M 15% /var/log/audit /dev/mapper/VGExaDb-LVDbTmp xfs 3.0G 148M 2.9G 5% /tmp /dev/mapper/VGExaDb-LVDbOra1 xfs 100G 32G 69G 32% /u01 tmpfs tmpfs 76G 0 76G 0% /run/user/0
The remaining examples in the procedure use
LVDbSys1
andLVDbVar1
, which is consistent with the aboveimageinfo
anddf
output. However, if the active image is usingLVDbSys2
, then modify the examples in the following steps to useLVDbSys2
instead ofLVDbSys1
, andLVDbVar2
instead ofLVDbVar1
. - Take snapshots of the logical volumes on the server.
Depending on the active system partition identified in the previous step, remember to use either
LVDbSys1
orLVDbSys2
to identify the logical volume for the root (/
) file system, and likewise use eitherLVDbVar1
orLVDbVar2
to identify the logical volume for the/var
file system.# lvcreate -L1G -s -c 32K -n root_snap /dev/VGExaDb/LVDbSys1 # lvcreate -L1G -s -c 32K -n home_snap /dev/VGExaDb/LVDbHome # lvcreate -L1G -s -c 32K -n var_snap /dev/VGExaDb/LVDbVar1 # lvcreate -L1G -s -c 32K -n varlog_snap /dev/VGExaDb/LVDbVarLog # lvcreate -L1G -s -c 32K -n audit_snap /dev/VGExaDb/LVDbVarLogAudit # lvcreate -L1G -s -c 32K -n tmp_snap /dev/VGExaDb/LVDbTmp
- Label the snapshots.
# xfs_admin -L DBSYS_SNAP /dev/VGExaDb/root_snap # xfs_admin -L HOME_SNAP /dev/VGExaDb/home_snap # xfs_admin -L VAR_SNAP /dev/VGExaDb/var_snap # xfs_admin -L VARLOG_SNAP /dev/VGExaDb/varlog_snap # xfs_admin -L AUDIT_SNAP /dev/VGExaDb/audit_snap # xfs_admin -L TMP_SNAP /dev/VGExaDb/tmp_snap
- Mount the snapshots.Mount all of the snapshots under a common directory location; for example,
/root/mnt
.# mkdir -p /root/mnt # mount -t xfs -o nouuid /dev/VGExaDb/root_snap /root/mnt # mkdir -p /root/mnt/home # mount -t xfs -o nouuid /dev/VGExaDb/home_snap /root/mnt/home # mkdir -p /root/mnt/var # mount -t xfs -o nouuid /dev/VGExaDb/var_snap /root/mnt/var # mkdir -p /root/mnt/var/log # mount -t xfs -o nouuid /dev/VGExaDb/varlog_snap /root/mnt/var/log # mkdir -p /root/mnt/var/log/audit # mount -t xfs -o nouuid /dev/VGExaDb/audit_snap /root/mnt/var/log/audit # mkdir -p /root/mnt/tmp # mount -t xfs -o nouuid /dev/VGExaDb/tmp_snap /root/mnt/tmp
- Back up the snapshots.Use the following commands to write a backup to your prepared NFS backup destination as a compressed archive file.
# cd /root/mnt # tar --acls --xattrs --xattrs-include=* --format=pax -pjcvf /root/remote_FS/myKVMbackup.tar.bz2 * /boot > /tmp/backup_tar.stdout 2> /tmp/backup_tar.stderr
- Check the
/tmp/backup_tar.stderr
file for any significant errors.Errors about failing to archive open sockets, and other similar errors, can be ignored. - Unmount and remove all of the snapshots.
# cd / # umount /root/mnt/tmp # umount /root/mnt/var/log/audit # umount /root/mnt/var/log # umount /root/mnt/var # umount /root/mnt/home # umount /root/mnt # lvremove /dev/VGExaDb/tmp_snap # lvremove /dev/VGExaDb/audit_snap # lvremove /dev/VGExaDb/varlog_snap # lvremove /dev/VGExaDb/var_snap # lvremove /dev/VGExaDb/home_snap # lvremove /dev/VGExaDb/root_snap
- Unmount the NFS backup destination.
# umount /root/remote_FS
- Remove the mount point directories that you created during this procedure.
# rm -r /root/mnt # rmdir /root/remote_FS
- Recreate the
/dev/VGExaDb/LVDoNotRemoveOrUse
logical volume.# lvm lvcreate -n LVDoNotRemoveOrUse -L2G VGExaDb -y
Parent topic: Backing up the KVM host and Guests