6.10.2.3 Method 3: Back Up a Guest Internally

You can take a snapshot-based backup of a guest from inside the guest.

All steps are performed from inside the guest.

Note:

This backup method is performed internally within the guest and uses logical volume snapshots. Compared with other backup methods, this method provides more limited recovery options because the backup is only useful when the guest is bootable and allows root user login.

This procedure backs up the contents of all currently active file systems in the guest. Before starting, ensure that all of the file systems that you want to back up are mounted.

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.

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

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

  3. Gather information about the currently active file systems and logical volumes.

    In this step, you must gather information from your guest to use later in the commands that create the logical volume snapshots and backup files.

    Run the following command:

    # df -hT | grep VGExa

    For every entry in your command output, determine the following information and create a table of values to use later:

    • The volume group (VG) name and logical volume (LV) name are contained in the file system name as follows:

      /dev/mapper/VG-name-LV-name

      For example, in /dev/mapper/VGExaDb-LVDbHome, the VG name is VGExaDb and the LV name is LVDbHome.

    • The backup label is a string that identifies the file system and its backup file. Use root for the root (/) file system. Otherwise, you can use a string that concatenates the directories in the mount point. For example, you can use varlogaudit for /var/log/audit.
    • Define a short label, which contains 12 or fewer characters. You will use the short label to label the snapshot file system.

    For example:

    # df -hT | grep VGExa
    /dev/mapper/VGExaDb-LVDbSys1                              xfs   15G  4.2G   11G  28% /
    /dev/mapper/VGExaDb-LVDbHome                              xfs  4.0G   45M  4.0G   2% /home
    /dev/mapper/VGExaDb-LVDbVar1                              xfs  2.0G   90M  2.0G   5% /var
    /dev/mapper/VGExaDb-LVDbVarLog                            xfs   18G  135M   18G   1% /var/log
    /dev/mapper/VGExaDb-LVDbVarLogAudit                       xfs 1014M   89M  926M   9% /var/log/audit
    /dev/mapper/VGExaDb-LVDbTmp                               xfs  3.0G   33M  3.0G   2% /tmp
    /dev/mapper/VGExaDb-LVDbKdump                             xfs   20G   33M   20G   1% /crashfiles
    /dev/mapper/VGExaDbDisk.u01.5.img-LVDBDisk                xfs  5.0G   33M  5.0G   1% /u01
    /dev/mapper/VGExaDbDisk.u02.10.img-LVDBDisk               xfs   10G   33M   10G   1% /u02
    /dev/mapper/VGExaDbDisk.u03.15.img-LVDBDisk               xfs   15G   33M   15G   1% /u03
    /dev/mapper/VGExaDbDisk.grid19.7.0.0.200414.img-LVDBDisk  xfs   20G  6.0G   15G  30% /u01/app/19.0.0.0/grid

    From the above output, you could derive the following table of information to use later in the commands that create the logical volume snapshots and backup files.

    File system VG Name LV Name Backup Label Short Label

    /dev/mapper/VGExaDb-LVDbSys1

    VGExaDb

    LVDbSys1

    root

    root_snap

    /dev/mapper/VGExaDb-LVDbHome

    VGExaDb

    LVDbHome

    home

    home_snap

    /dev/mapper/VGExaDb-LVDbVar1

    VGExaDb

    LVDbVar1

    var

    var_snap

    /dev/mapper/VGExaDb-LVDbVarLog

    VGExaDb

    LVDbVarLog

    varlog

    varlog_snap

    /dev/mapper/VGExaDb-LVDbVarLogAudit

    VGExaDb

    LVDbVarLogAudit

    varlogaudit

    audit_snap

    /dev/mapper/VGExaDb-LVDbTmp

    VGExaDb

    LVDbTmp

    tmp

    tmp_snap

    /dev/mapper/VGExaDb-LVDbKdump

    VGExaDb

    LVDbKdump

    crashfiles

    crash_snap

    /dev/mapper/VGExaDbDisk.u01.5.img-LVDBDisk

    VGExaDbDisk.u01.5.img

    LVDBDisk

    u01

    u01_snap

    /dev/mapper/VGExaDbDisk.u02.10.img-LVDBDisk

    VGExaDbDisk.u02.10.img

    LVDBDisk

    u02

    u02_snap

    /dev/mapper/VGExaDbDisk.u03.15.img-LVDBDisk

    VGExaDbDisk.u03.15.img

    LVDBDisk

    u03

    u03_snap

    /dev/mapper/VGExaDbDisk.grid19.7.0.0.200414.img-LVDBDisk

    VGExaDbDisk.grid19.7.0.0.200414.img

    LVDBDisk

    u01app19000grid

    grid_snap

    Note:

    • The information gathered from your guest may be significantly different from this example. Ensure that you gather the required information directly from your guest and only use current information.

    • Depending on the currently active system volume, the logical volume for the root (/) file system is LVDbSys1 or LVDbSys2. Likewise, the logical volume for the /var file system is either LVDbVar1 or LVDbVar2.
  4. Create the file system snapshots and backup files.

    Use the table of information for your guest, which you gathered in the previous step.

    Perform the following for each row in your table, substituting the appropriate values in each command.

    1. Create the snapshot.
      # lvcreate -L1G -s -n LV-Name_snap /dev/VG-Name/LV-Name
    2. Label the snapshot.
      # xfs_admin -L Short-Label /dev/VG-Name/LV-Name_snap
    3. Mount the snapshot.
      # mkdir -p /root/mnt/Backup-Label
      # mount -o nouuid /dev/VG-Name/LV-Name_snap /root/mnt/Backup-Label
    4. Change to the directory for the backup.
      # cd /root/mnt/Backup-Label
    5. Create the backup file.
      • For the root (/) file system only, use the following command to include the contents of /boot in the backup file:

        # tar --acls --xattrs --xattrs-include=* --format=pax -pjcvf /root/remote_FS/rootfs-boot.tar.bz2 * /boot > /tmp/backup_tar.stdout 2> /tmp/backup_tar.stderr
      • Otherwise, use the following command template:

        # tar --acls --xattrs --xattrs-include=* --format=pax -pjcvf /root/remote_FS/Backup-Label.tar.bz2 * > /tmp/backup_tar.stdout 2> /tmp/backup_tar.stderr
    6. Check the /tmp/backup_tar.stderr file for any significant errors.

      You can ignore errors about failing to archive open sockets, and other similar errors.

    7. Unmount and remove the snapshot.
      # cd /
      # umount /root/mnt/Backup-Label
      # /bin/rmdir /root/mnt/Backup-Label
      # lvremove -f /dev/VG-Name/LV-Name_snap
  5. Unmount the NFS share.
    # umount /root/remote_FS
  6. Recreate the /dev/VGExaDb/LVDoNotRemoveOrUse logical volume.
    # lvm lvcreate -n LVDoNotRemoveOrUse -L2G VGExaDb -y