User Tools

Site Tools


virtualization:xenserver:xenserver_backup_system

Free XenServer Backup System

See also XenServer Backup

See also XenServer VSS Provider

Main Reference Article: http://www.charleslabri.com/back-up-xenserver-6-to-network-share-with-fancy-scripting-and-lots-of-fun-and-no-downtime/

Backup: http://www.8layer8.com/?p=260

Restore: http://www.8layer8.com/?p=200

:!: You can back up all the VM's, XenServer hosts, and metadata for a XenServer pool from a single XenServer host.

:!: Consider this a disaster recovery backup. Use a file-by-file backup such as Ahsay for daily needs.

:!: Here we use an NFS mount for backup storage.

:!: XVA backups are compressed on the fly.

:!: This is a no-downtime script set; it backs up the VM “live” by taking a snapshot, and then exporting that snapshot to a mount point on Dom0.

The Basic Idea

  1. The local Dom0 on the XenServer pool master runs cron
  2. The cleanup.sh file runs and removes old data and emails regarding what happened previously
  3. The audit.sh runs and outputs the info via e-mail to the backup admin
  4. The meta-backup.sh runs and backs up Dom0 and the XenServer database and structure
  5. The vm_backup.sh runs and backs up the VMs running on the host
    1. enters the correct directory
    2. sources the .lib and the .cfg files
    3. determines what is to be backed up from the vm_backup.cfg file
    4. calls for a backup (via live snapshot/export)
    5. outputs to a log

Prepare the NFS Mount and Test a Manual Backup

:!: Choose one of your XenServers to be the backup server, generally the pool master. This script runs in Dom0 on a XenServer.

:!: Here we assume you have a shared NFS folder /backup/xenserver-backup/VA-Hosting-Pool on IP address 10.10.1.9 and a XenServer pool named VA-Hosting-Pool.

Mount the NFS share:

mkdir /mnt/backup

vi /etc/fstab

Append:

# Mount the backup share
ip.of.nfs.svr:/path/to/backup/share  /mnt/backup   nfs   _netdev   0 0

Mount the share, check it's mounted and test a manual backup:

mount -a
mount
xe vm-export vm="<your-vm-name>" filename=/mnt/backup/"<your-vm-name>".xva

Get Mail Working

see also SSMTP

Modify ssmtp.conf as necessary:

vi /etc/ssmtp/ssmtp.conf

root=adminuser@yourdomain.com
mailhub=mail.yourdomain.com:465
RewriteDomain=yourdomain.com
#hostname=_HOSTNAME_
FromLineOverride=YES
UseTLS=YES
AuthUser=smtpuser
AuthPass=smtppass

:!: If you don't specify a hostname, the local hostname will me used.

Install the Scripts on the Backup Server

mkdir -p /opt/backup && cd /opt/backup
wget https://www.dropbox.com/s/0fyijjlv30mc413/XenServerBackup.zip?dl=1 -O XenServerBackup.zip
unzip XenServerBackup.zip
rm -rf __MACOSX/
chmod +x *.sh
chmod +x dbtool
cp -a ./dbtool /sbin/dbtool

Configure the Scripts on the Backup Server

:!: You might want to use IP addresses to control which network interfaces are used for the backups.

Change the names and filenames to the names you have for your XenServers according to the article:

cd /opt/backup

vi cleanup.sh

vi audit.sh

vi meta-backup.sh

vi mailheader.txt

vi vm_backup.cfg

vi vm_backup.sh

Testing

Run the cleanup script and check for an e-mail message:

./cleanup.sh

Run the audit script and check for an e-mail message:

./audit.sh

Then run the metadata backup script. This will take longer, so let it run.

./meta-backup.sh

Now, make sure you have vm_backup.cfg set to only back up a limited set of VMs and try:

./vm_backup.sh

Configure Scheduling

:!: There must be a newline at the end of the line or cron won't run the job.

:!: Some systems wont run the cron job if the filename has a '.' (dot) in the name.

This will add a cron job to run backups every day at 10:30pm:

cat << EOF > /etc/cron.d/backup
30 22 * * * root /opt/backup/cleanup.sh && /opt/backup/audit.sh && /opt/backup/meta-backup.sh && /opt/backup/vm_backup.sh
EOF

chmod 644 /etc/cron.d/backup

Backup Your Backup Scripts

Do this on each XenServer backup host (pool master) to back up your backup scripts and configuration to a Scripts folder on the backup share:

# This assumes the backup share is mountable via ''/etc/fstab''
mount /mnt/backup
mkdir -p /mnt/backup/Scripts/
/bin/cp -af /sbin/dbtool /mnt/backup/Scripts/
/bin/cp -af /etc/fstab /mnt/backup/Scripts/
/bin/cp -af /opt/backup/* /mnt/backup/Scripts/
/bin/cp -af /etc/ssmtp/ssmtp.conf /mnt/backup/Scripts/
/bin/cp -af /etc/cron.d/backup /mnt/backup/Scripts/
rm -f /mnt/backup/Scripts/message.tmp
#umount /mnt/backup
virtualization/xenserver/xenserver_backup_system.txt · Last modified: 2017/03/25 11:03 by gcooper