Online backup of virtual XEN machines

From SEPsesam
Jump to: navigation, search

Copyright © SEP AG 1999-2018. All rights reserved.

Any form of reproduction of the contents or parts of this manual is allowed only with the express written permission from SEP AG. When compiling and designing user documentation SEP AG uses great diligence and attempts to deliver accurate and correct information. However, SEP AG cannot issue a guarantee for the contents of this manual.


Introduction

Currently XEN does not have a backup API. That means, that Xen virtual machines can not be backed up online with using the existing XEN tools. An effective way to perform a useful backup is to use LVM (Logical Volume Manager) as an intermediate layer between physical disk and the file system. Using the LVM presents the opportunity to back up a virtual XEN machine with an LVM snapshot. This LVM snapshot can be mounted into the file system and then written to disk or tape with SEP sesam as a path-backup.

Note, you should also backup the VM configuration files in the directory /etc/xen. On Linux systems it makes generally sense to backup the complete /etc directory.

Attention

Please note that neither Xen nor LVM are part of SEP sesam software. Further information can be found in the literary references at the end of the document or generally on the Internet.


Better Solution in Sesam version 4.2:

From SEP sesam version 4.2 on, there is a possibility to define a LVM snapshot based backup. For that, the checkbox Backup with LVM has to be activated in the backup task properties. If a backup source points onto a point in the filesystem which is inside a LVM volume, SEP sesam creates automatically a LVM snapshot, backup this snapshot source and release the snapshot after backup.

System Requirements

  • A working XEN environment on LVM (Logical Volume Manager)
  • An installed SEP sesam client on the XEN host system
  • The XEN host systems must be added as a client to the SEP sesam server

Basic approach

Backup

  1. Create an LVM snapshot of the logical volume where the VM is stored
  2. Mount this snapshot into the filesystem
  3. Perform a pathbackup with SEP sesam from the mountpoint of the LVM snapshot
  4. Dismount the snapshot from the filesystem after backup
  5. Delete the snapshot

Recovery

  1. Shut down the XEN VM to be recovered
  2. Restore the savesets of the VM backup to the original destination of the VM with option overwrite
  3. Start the VM

Procedure

Attention

This scenario presents one example. The dimensioning of the size of the Logical Volumes (LVs)depends on the virtual machine and the applications that run on this system environment.

In this example the virtual machine VM1 on the XEN host astronomix is stored on the logical volume (LV) /dev/system/xenvm. This partition is mounted to /srv/xenvm. The files of the VM vm1 are stored in the directory /srv/xenvm/vm1.


Backup of the XEN VM

Create an LVM snapshot

A snapshot volume must have at a minimum the size to handle all the changes performed by the virtual machine during the time of the backup. In this case the snapshot is created with the size of 1 GB.

# lvcreate -L1G -s -n vmbackup /dev/system/xenvm
    Logical volume "vmbackup" created

The snapshot is introduced via the device file /dev/system/vmbackup to the XEN hostsystem.

Attention


Overflowing snapshots are automatically disabled within the LVM configuration. When this occurs it is highly probable that the backup will be inconsistent and therefore unusable. The size of 1 GB here is ONLY to used as an example. Please test before live operations, how much data updates your virtual machines generates during the backup and adjust the size of your snapshot accordingly.


Mount snapshot

Now the snapshot is mounted into the filesystem to /mnt/vmbackup:

# mount /dev/system/vmbackup /mnt/vmbackup


Set up and execute a backup with sesam

  1. Define a backup task "Backup_XEN_vm1" with:
    • the backup source /mnt/vmbackup and
    • backup type Pathbackup
  2. Following this the backup can be tested with "immediate start". For a time controlled job a schedule can be specified (for example daily 20:00 o'clock).


Dismount and delete the snapshot

After the backup is finished, the snapshot can be dismounted with:

# umount /mnt/vmbackup

...and deleted with:

# lvremove -f /dev/system/vmbackup
  Logical volume "vmbackup" successfully removed


System Recovery of a VM

For the restore of a virtual machine its...

  1. ...necessary, that the existing VM is powered off, so that the data associated to this VM can be overwritten.
  2. A restore is started via the SEP sesam Restore Wizard.
    • as restore target the original path of the virtual machine vm1is specified, in this case /srv/xenvm/vm1.
    • Because all the data of the VM are stored in the same directory, the option original tree structure must be disabled. This allows the storing of all the data in the defined directory.
    • If data still exists in the restore path, select the option overwrite existing files.
  3. After successful restore the VM can be started normally.

Extended sesam configuration using Command Line Pre- and Post- Options

For better automation the points "create snapshot" and "mount snapshot" are embedded in a pre-process before backup and the "unmount snapshot" and "delete snapshot" after backup in a post-process. For details, see Using Pre and Post Scripts

Set up the pre- and post-interface

The definition of the pre- and post-process are done via script on the sesam client which performs the backups. In this case it is the XEN host. Therefore the interface-templates sbc_pre and sbc_post from directory /opt/sesam/skel/templates have to be copied to /opt/sesam/bin/sesam and edited accordingly .
Here are the summaries of the data are shown as an example. The error correction is rudimentary and can be adapted as required.

sbc_pre

...
#=== Please insert your specific actions here=====================================

if [ $task == Backup_XEN_vm1 ]; then
  echo "Create a LVM snapshot for backup of virtual machine vm1..."
  lvcreate -L1G -s -n vmbackup /dev/system/xenvm
  rc=$?
  if [ $rc -eq 0 ]; then
    echo "...successful"
    echo
    echo "Mount LVM snapshot for backup..."
    mount /dev/system/vmbackup /mnt/vmbackup
    rc=$?
    if [ $rc -ne 0 ]; then         # if error clean up
      lvremove -f /dev/system/vmbackup
      echo STATUS:ERROR {Error on mounting LVM snapshot}
      exit
    fi
    echo "...successful"
  else
    echo STATUS:ERROR {Error on creating LVM snapshot}
    exit
  fi
fi
echo STATUS:OK
exit


sbc_post

...
#=== Please insert your specific actions here =====================================

if [ $task == Backup_XEN_vm1 ]; then
  echo "Unmount LVM snapshot after backup..."
  umount /mnt/vmbackup
  rc=$?
  if [ $rc -ne 0 ]; then
    echo STATUS:ERROR {Error on unmounting LVM snapshot}
    echo "Please unmount and remove LVM snapshot manually!"
    exit
  fi
  echo "...successful"
  echo
  echo "Delete LVM snapshot for virtual machine vm1..."
  lvremove -f /dev/system/vmbackup
  rc=$?
  if [ $rc -ne 0 ]; then         # if error clean up
    echo STATUS:ERROR {Error on deleting LVM snapshot}
    echo "Please delete LVM snapshot manually"
    exit
  fi
  echo "...successful"
fi
echo STATUS:OK
exit


Definition of the backup task using sesam

Create a backup task via the SEP sesam GUI. As backup source the mountpoint is specified on which the snapshot is mounted at this moment (/mnt/vmbackup).

Define Backup Task

On the tab Options 1 the check boxes for the pre- and post-processing before and after the backup have to be set. The options are so chosen, that the backup terminates if a failure occurs during the pre-process because of the possibility that either the snapshot is not created or was not mounted. The post-processing (post) in contrast, will also be performed if the backup itself returns an error. This ensures that after the backup the cleanup task works, i.e. dismount snapshot and delete snapshot, are properly executed.

Pre/Post aktivieren

Selective backup of the VM

The scenario above describes the backup of the entire virtual machine, that means the VM is backed up as a container. For a selective backup of parts of the virtual machine (from inside), the virtual machine is handled like a physical machine. This means that every VM is its own IP host and, therefore, a sesam client has to be installed on this machine and configured in the SEP sesam environment. Afterward a selective backup can be performed for that virtual machine.

Technical References