|
|
#1 | |||||||||||||||||||
|
Site Team
Join Date: Oct 2004
Posts: 1,294
|
In this guide I will show you how to setup live xenserver backups and schedule them to run automatically. You can use the below script to backup vms when they are live (turned on), the backup will also be a full backup of the xenservers vm (Exports to a .xva file) so you can import the vm on to another xenserver if you wish.
Introduction To : How to Setup Live Xenservers Backups The below script below was written by Andy Burton Andy Burton - PHP & MySQL Development, Servers and Virtualisation I will show you how to install and configure the script which will backup your live xenserver vms to an external cif share as well as how to configure the script for Xenserver versions 5.5 and 5.6. I have found a bug in xenserver 5.5 and 5.6 where if you take a snapshot of a VM the snapshot will take up diskspace on the storage, But when you delete the snapshot the diskspace it was using was not free'd up. To get the free disk space back you need to run a command on the xenservers console. I will show you how you can add this command to the backup script. What Does this Xenserver Live Backups Script Do? The script can be run manually or automatically via a linux cronjob. The first thing it will do is to take a snapshot of the live vm, The snapshot will put the live vm in to suspended state which means the vm will be down for 5-10 seconds, as soon as the snapshot has finished the vm will be returned to the running / live state. This snapshot will then be combined with the vms core metadata and exported to your backups folder. Another command will then be run to delete the snapshot and reclaim the disk space it was using. How to Setup Live Xenservers Backups Connect to the console of the xenserver you want to configure live backups for, and log on to the command prompt. Now run the following commands Code:
>> mkdir /home/backup >> mkdir /VM_Backup >> 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* >> cd /home/backup >> vi vmbackups.sh ** ** This file is used to easily start the live backups of your xenserver vms. Simply run the above command and then put the following in to the file. Code:
#!/bin/bash set -x 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 How To Configure The Scripts For Live Xenserver Backups We are now going to edit the script in a way that any xenserver can run this script and it will place the backups in to a folder with the xenservers name. While you are still connected to the consoles command prompt run the following Code:
>> cd /VM_Backup >> ls Code:
>> vi vm_backup.cfg Quote:
Quote:
Find Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
Now we need to edit the vm_backup.lib file, type the following Code:
>> vi vm_backup.lib Quote:
If Xenserver version is 5.5 add Quote:
Quote:
Quote:
If Xenserver version is 5.5 add Quote:
Quote:
Code:
>> chmod 777 CLEARDOWN.sh Create the CLEARDOWN.sh Script For Xenserver Live Backups We need to create a script that can be run on our xenserver hosts that will reclaim disk space from deleted snapshots. I then run this script before I backup my live xenserver vms just to make sure that free disk space will not be an issue when I run my backups. To create this script log on to the xenservers console and go to the command prompt and type the following Code:
>> cd /VM_Backup >> vi CLEARDOWN.sh Quote:
Running Live Xenservers Backups We are now ready to run a backup on our live xenserver vms We can do this either manually or schedule them to run automatically. Manually Run The Backups To run the backups manually run the following commands Code:
>> cd /home/backup >> ./vmbackups.sh I schedule my xenservers to backup once a month on a particular day and time (Out of hours) To do this type in the following at the command prompt. Code:
>> crontab -e Quote:
How To Zip Up The Live Xenserver Backups When a xenservers vm has been backuped the file will be a minimium size of 8gb. When the backup has finished we can then zip all the backup files which usually saves us 50% - 70% of disk space. I have written a batch file that will automatically zip all the *.xva files in a directory and then delete the .xva file once it has been zipped. You need to log on to the windows box. I then use windows scheduled tasks to run the below batch file. We need to create 2 batch files Create a file called zip.bat and enter the following line in to the file Quote:
Quote:
How To Automatically Delete Old Xenserver VM Backups I use another script to delete old xenserver vm backups that are 99 days old, In the script below it looks in the "E:\VM_Backups" folder for any *.zip files that are 99 days or older, If these files exist they will be deleted. Create a file called cleardown.bat and enter the following line in to the file, change as needed Quote:
General Tips For : How to Setup Live Xenservers Backups 1. Make sure your default SR has enough free space to take snapshops of your VMs. Only one snapshot will run at a time as they get deleted after the backup has run. Look at the VM which uses the most storage and esitmate how big the snapshot will be and make sure there is enough free space. 2. Run the backups out of hours, There is a small amount of downtime per vm that gets backuped. When the snapshot is run the vm will be put in to suspended state, the snapshot usually takes 5-15 seconds to run, on vms with larger storage it should take longer to run 3. I would advise you backup the vms on to remote storage, this way if the xenserver does have a problem you can restore the VMs on to another xenserver Frequently Asked Questions : How to Setup Live Xenservers Backups Q:
__________________
My Info :Ex-Owner of Computer Forums .org -- CCA in Citrix Presentation Server 4 + 5 + Xenserver 5.5 Site Info : Free Boot Disk Download - Latest Articles - Latest Posts - Site Rules More Info : If you have any Questions Send Me A PM |
|||||||||||||||||||
|
|
|
|
|
#2 |
|
Fully Optimized
Join Date: Jan 2010
Location: United Kingdom
Posts: 1,926
|
wow thats alot to take in.
nice one, JCB.
__________________
Customer Service Technician @ Fujitsu Services (UK) Du Bist Hier In Mein Land!
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|