User Tools

Site Tools


virtualization:xenserver:xenserver_backup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
virtualization:xenserver:xenserver_backup [2014/08/21 11:14]
gcooper
— (current)
Line 1: Line 1:
-====== XenServer Backup ====== 
  
-**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 from a single XenServer host in a XenServer pool. 
- 
-:!: 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 ===== 
- 
-  - The local Dom0 on the XenServer runs cron 
-  - The ''cleanup.sh'' file runs and removes old data and emails regarding what happened previously 
-  - The ''audit.sh'' runs and outputs the info via e-mail to the backup admin 
-  - The ''meta-backup.sh'' runs and backs up Dom0 and the XenServer database and structure 
-  - The ''vm_backup.sh'' runs and backs up the VMs running on the host 
-    - enters the correct directory 
-    - sources the ''.lib'' and the ''.cfg'' files 
-    - determines what is to be backed up from the ''vm_backup.cfg'' file 
-    - calls for a backup (via live snapshot/export) 
-    - outputs to a log 
- 
-===== Prepare the NFS Mount and Test a Manual Backup ===== 
- 
-:!: Choose one of your XenServers to be the backup server.  This script runs in Dom0 on a XenServer. 
- 
-:!: Here we assume you have a XenServer pool named ''VA-Hosting-Pool'' on IP address ''10.10.1.9'' and a shared NFS folder ''/backup/xenserver-backup/VA-Hosting-Pool''. 
- 
-Mount the NFS share: 
- 
-<file> 
-mkdir /mnt/backup 
- 
-vi /etc/fstab 
-</file> 
- 
-Append: 
- 
-<file> 
-# 
-# Mount the backup share 
-10.10.1.9:/backup/xenserver-backup/VA-Hosting-Pool /mnt/backup nfs _netdev 0 0 
-</file> 
- 
-Mount the share, check it's mounted and test a manual backup: 
- 
-<file> 
-mount -a 
-mount 
-xe vm-export vm="<your-vm-name>" filename=/mnt/backup/"<your-vm-name>".xva 
-</file> 
- 
-===== Get Mail Working ===== 
- 
-see also **[[networking:linux:ssmtp|SSMTP]]** 
- 
-Modify ''ssmtp.conf'' as necessary: 
- 
-<file> 
-vi /etc/ssmtp/ssmtp.conf 
- 
-root=adminuser@yourdomain.com 
-mailhub=mail.yourdomain.com:465 
-RewriteDomain=yourdomain.com 
-FromLineOverride=YES 
-UseTLS=YES 
-AuthUser=smtpuser 
-AuthPass=smtppass 
-</file> 
- 
-===== Install the Scripts on the Backup Server ===== 
- 
-<file> 
-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 
-</file> 
- 
-===== 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: 
- 
-<file> 
-vi audit.sh 
- 
-vi cleanup.sh 
- 
-vi meta-backup.sh 
- 
-vi mailheader.txt 
- 
-vi vm_backup.cfg 
-</file> 
- 
- 
- 
- 
- 
- 
- 
- 
-====== Old Page Contents Below ====== 
- 
-Old but good list of XenServer backup options: 
-http://sysadminnotebook.blogspot.com/2011/05/xenserver-backup-solutions.html 
- 
-===== Local Backup Disk or CIFS Share ===== 
- 
-http://www.computerforums.org/forums/server-articles/how-setup-live-xenservers-backups-208663.html 
- 
-  * The ''CLEARDOWN.sh'' script reclaims disk space from deleted snapshots 
-  * ''startvmbackup.sh'' is the script that will start the live backups of our XenServer VMs 
- 
-==== Install on the XenServer Host ==== 
- 
-<file> 
-mkdir /home/backup 
-mkdir /VM_Backup 
- 
-# Use a command like this if you want to send backups to a CIFS share 
-#mount -t cifs "//192.168.0.20/VM_Backup" -o username=username,password=password /VM_Backup 
- 
-cd /VM_Backup 
-wget http://www.andy-burton.co.uk/files/xenserver_backup/xenserver_backup.tar.gz 
-tar -xzf xenserver_backup.tar.gz 
-chmod 777 v* 
-</file> 
- 
-=== startvmbackup.sh === 
- 
-<file> 
-vi /home/backup/startvmbackup.sh 
-</file> 
- 
-<file> 
-#!/bin/bash 
-set -x 
- 
-# Dismount then remount backup share to be sure it's mounted 
-umount -f /VM_Backup 
- 
-#mount -t cifs "//192.168.0.20/VM_Backup" -o username=username,password=password /VM_Backup 
- 
-/VM_Backup/CLEARDOWN.sh 
- 
-/VM_Backup/vm_backup.sh 
- 
-/VM_Backups/CLEARDOWN.sh 
- 
-sleep 120 
- 
-/VM_Backups/CLEARDOWN.sh 
-</file> 
- 
-<file> 
-chmod 777 /home/backup/startvmbackup.sh 
-</file> 
- 
-=== CLEARDOWN.sh === 
- 
-<file> 
-vi /VM_Backup/CLEARDOWN.sh 
-</file> 
- 
-<file> 
-#!/bin/bash 
- 
-coalesce-leaf -u $uuid 
-coalesce-leaf -u $uuid 
-coalesce-leaf -u $uuid 
- 
-xe host-call-plugin host-uuid=$VM_XENUUID plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=$uuid 
-xe host-call-plugin host-uuid=$VM_XENUUID plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=$uuid 
-xe host-call-plugin host-uuid=$VM_XENUUID plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=$uuid 
-</file> 
- 
-<file> 
-chmod 777 /VM_Backup/CLEARDOWN.sh 
-</file> 
- 
-==== Configure The Scripts ==== 
- 
-Edit the ''vm_backup.cfg'' file: 
- 
-<file> 
-vi /VM_Backup/vm_backup.cfg 
-</file> 
- 
-Insert these two lines in the ''Settings'' section: 
- 
-<file> 
-# 
-# Settings 
-# 
- 
-VM_XENHOST=$(xe vm-list | grep 'Control domain on host' | awk -F ': ' '{ print $3 }') 
- 
-VM_XENUUID=$(xe vm-list params uuid=$(xe vm-list | grep -B1 $VM_XENHOST | grep uuid | awk -F ': ' '{ print $2 }') | grep resident-on | awk -F ': ' '{ print $2 }') 
-</file> 
- 
-Set log path: 
- 
-<file> 
-log_path="/VM_Backup/"$VM_XENHOST"/"$date".log" 
-</file>  
- 
-Set the backup destination: 
- 
-<file> 
-backup_dir="/VM_Backup/"$VM_XENHOST"/" 
-</file> 
- 
-Ensure only running VMs are backed up: 
- 
-<file> 
-backup_vms="running"  
-</file> 
- 
-Edit the ''vm_backup.lib'' file: 
- 
-<file> 
-vi /VM_Backup/vm_backup.lib 
-</file> 
- 
-Search for this line and add below it in the same if/then stanza: 
- 
-<file> 
-log_message "VM $uuid backup failed" 
-</file> 
- 
-<file> 
-                                xe host-call-plugin host-uuid=$VM_XENUUID plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=$uuid 
-                                sleep 10 
-                                xe host-call-plugin host-uuid=$VM_XENUUID plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=$uuid 
-                                sleep 10 
-                                xe host-call-plugin host-uuid=$VM_XENUUID plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=$uuid 
-</file> 
- 
-Search for this line and add below it in the same if/then stanza: 
- 
-<file> 
-log_message "VM $uuid backup succeeded" 
-</file> 
- 
-<file> 
-                                xe host-call-plugin host-uuid=$VM_XENUUID plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=$uuid 
-                                sleep 10 
-                                xe host-call-plugin host-uuid=$VM_XENUUID plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=$uuid 
-                                sleep 10 
-                                xe host-call-plugin host-uuid=$VM_XENUUID plugin=coalesce-leaf fn=leaf-coalesce args:vm_uuid=$uuid 
-</file> 
virtualization/xenserver/xenserver_backup.1408641274.txt.gz · Last modified: 2014/08/21 11:14 by gcooper