Monday, March 12, 2012

XenServer backups

These articles detail how to backup XenServer VMs on the fly.

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

http://blog.andyburton.co.uk/index.php/2009-11/updated-citrix-xenserver-5-5-automatic-vm-backup-scripts/

---


Daily backups are still the best way to get a virtual machine back on it's feet, and then restore them the rest of the way with CDP if you have it.
Backing up a live server in Xen is super simple, and restoring it is as well. The trick with backups is always getting them to run consistently, automatically, and verifiably.
There is a great script here from Andy Burton that I use daily to export ~20 virtual servers to a USB disk attached to one of the Xen Servers.
I have tweaked it very slightly and have some cleanup scripts to handle disk remounts, removal of older backup images, and some logic to not back up if the backup drive is not present and mounted.
audit.sh - A plaintext dump of all the info needed to figure out what used to be connected to what and where it used to live, all the SR, VM, VIF, UUID's etc. are here in a reasonably readable format if needed.
cleanup.sh - unmounts and remounts the backup disk, and then cleans it up so that we only have the last two backups on it. Needs some logic to abort if the drive isn't, or can't be, mounted.
crontab.txt - My listing of jobs and order of them to run. Times are up to you.
meta-backup.sh - Backs up the metadata of the Xen Pool in a restorable format. Backs up the host machines over to the backup drive as well.
mailheader.txt - The simple header for outbound emails
and be sure to download the xenserver_backup.tar.gz script too from above .
You will need somewhere to put the backups, it can be an NFS share, SMB share, USB disk, flash drive, or anything else you can get mounted up.
DO NOT BACKUP VM'S TO THE XENSERVER "/" PARTITION! It does not have enough space to backup more than the tiniest VM and you WILL crash your XenServer and have to spin it up with a live CD and clear out whatever 2GB+ file you just accidentally made!
Note that you can back up all the VM's, Xen hosts, and metadata from a single Xen host, so you only need to set this up on one machine. I use a KingWin USB "Toaster" style dock to keep a 320GB SATA disk in and storing daily backups, which currently is enough for two days worth. It's a two slot toaster, so I bring in a 1.5TB disk monthly for extra copies of snapshot VM's as well as encrypted file-by-file backups of the file servers.
Setting up an external disk(s):
fdisk -l (that's an L)
(look for the backup drive, probably /dev/sdb but not always)
Partitioning
fdisk -l /dev/sdb     (that's an L)
Press p to see current partitions
If there is more than one, delete it with d
select the highest number partition
keep going until they are all gone
Press n for new partition
p for Primary
Partition 1
defaults on the rest
Press w to write the changes and exit
Formatting
mkfs.ext3 /dev/sdb1
(this will take a little while for a large drive)
Make it usable in the filesystem:
mkdir /mnt/backup
mount /dev/sdb1 /mnt/backup
From here, you can export and import by hand:
**************************************
Export
(Tip! Use TAB to auto complete it all!)
[root@xenshuttle ~]# xe vm-export         {TAB}{TAB}
filename=              preserve-power-state=  vm=
[root@xenshuttle ~]# xe vm-export vm=  {[TAB][TAB]}
{A list of servers appears, We want to export Pokey Server}
[root@xenshuttle ~]# xe vm-export vm=Pokey\ Server  {Type in Pokey then [TAB][TAB]}
filename=              preserve-power-state=  vm=
[root@xenshuttle ~]# xe vm-export vm=Pokey\ Server filename=
[root@xenshuttle ~]# xe vm-export vm=Pokey\ Server filename=/mnt/backup/pokey.xva {Type in /mnt/backup/pokey.xva then press ENTER}
After a bit, the pokey machine is backed up onto the external hard disk. This is a fairly quick operation, usually far faster than a file-by-file backup (500MB/minute on average) and note that it compresses the backup on the fly.
Setting up the automatic backups:
***************************************
From a XenServer with a USB drive attached:
chmod +x *.sh
chmod +x dbutil
cp ./dbutil /sbin/dbutil
chmod +x /sbin/dbutil
tar -zxvf xenserver_backup.tar.gz
nano meta-backup.sh
(change the names and filenames to the names you have for your XenServers)
Control-X to exit, answer Y to save changes
nano vm_backup.cfg
Edit the log_path to be "/mnt/backup/vm_backup.log"
Edit backup_dir to be "/mnt/backup"
Edit backup_vms to be "all"
Enable email on the XenServer:
nano /etc/ssmtp/ssmtp.conf
Change mailhub=mail to mailhub=(your mail server goes here)
Change rewriteDomain=yourdomain.com
Save and Exit
Schedule the backups:
Note the times here are reverse military, so 0 19 * * *  means run at 19:00 every day, change them if you want, just keep them sequential top to bottom time-wise so the scripts run in the right order.
crontab -e
(Press i to insert text)
Paste in: (be sure to use your email address!)
MAILTO="myaddress@mydomain.com"
0 19 * * * /root/cleanup.sh
10 19 * * * /root/audit.sh
11 19 * * * /root/meta-backup.sh
0 20 * * * /root/vm_backup.sh
Then press Escape
Type in :wq [enter]
Done.
Check the backups tomorrow and for several days to make sure that they rotate properly.
Restoring from a backup is very simple:
Locate the backup you want to restore from, probably in /mnt/backup/thisserver_09_25_2010.xva
Locate the storage repository you want to restore it into: run xe sr-list, and find the storage you need to use, note the first 4 characters of the UUID (ex: 28f2)
Run xe vm-import like this:
xe vm-import filename=/mnt/backup/thisserver_09_25_2010.xva sr-uuid=28f25ea1-4c49-5346-4a86-d37560bd07b7 [ENTER]

12 comments:

Anonymous said...

So what are the best communications strategies to use when trying to communicate with the opposite sex?. [url=http://www.mulberryhandbagssale.co.uk]Mulberry outlet shop[/url] In other words, you'll learn what's important to them. [url=http://www.goosecoatsale.ca]canada goose[/url] Tkttgycnh
[url=http://www.pandorajewelryvip.co.uk]pandora Sale[/url] Owncrohnu [url=http://www.officialcanadagooseparkae.com]canada goose coats[/url] pveopsqbp

Anonymous said...

www.bulberryfashion2013.com vqmrhk twba burberry outlet wvsfii bowf burberry sale online kevyek mftg ugg sale zwvjew xilu ugg sale cncnjw ysha http://www.2lv6.com bdmuzn jqad ugg boots outlet cmkhbn vzgi ugg sale dshcfu cdii michael kors online outlet cndtbj kwqu michael kors outlet store eetdwx uogk michael kors flats kjbxrl bqec longchamp handbags sale feirwc xoga longchamp bags on sale shoqkb ociz longchamp handbags sale wzhvgy cyfv burberry handbags dabiui ikmk

Anonymous said...

burberry outlet anxddk uahb burberry cbnbsg jtwu burberry sale 2012 jcoqty geqd uggs uk uwcipf avwo ugg outlet online sale mrdzge zfsk ugg outlet online hrcftu azog ugg outlet zgyyfo txgd ugg boots cheap swflzk jhvo michael kors outlet urfrzn jraz michael kors handbags znbqzb fruy michael kors 2013 dbsaze nywc longchamp outlet online elpbna nhcn longchamp sale pctbql kzkz longchamp bag lkyrbl prtt burberry outlet qlifov kssz

Anonymous said...

burberry outlet pbfaar kuja burberry uk qylurx uwwr burberry sale online upmuyo pxjf ugg sale avstjk fcmr www.numbjerseys.com tzbdgx qckg ugg boots sale smxlcb bqtb ugg discount gamxby fkoy ugg sale bijwko wfob http://www.jg20.com myywgq zynh michael kors 2013 ayxtvu hjjw http://www.1qpf.com ekfbzo gdzu longchamp outlet store qolrcl anzw longchamp sale gqqzmm ljxc longchamp handbags jibxth fzph http://www.e4ni.com ycjfbu zvkm

Anonymous said...

burberry sale oghkfz tpxa burberry uk jzkgps rodk www.livebulberryfashion.com yzuctz aequ ugg boots uipipz rbfo ugg sale giuhwe hzor ugg boots sale xdkpes rsfk ugg outlet ypxqbw orbm ugg usa ufbvns noeo michael kors outlet qzgxqd gcle michael kors 2012 rggqld ggxv michael kors outlet ebvuax akxb longchamp handbags sale qtuvoa vwnc longchamp sale hvbqrt ahrx longchamp bag mqiemb dkwx burberry outlet online upetwl wsbs

Anonymous said...

burberry sale wflbgm gyuu burberry outlet nggpdw pitr burberry bags jvsxre yaew uggs uk sale wacgra tfpq ugg outlet online iyzfkx uzuh ugg boots sale roript gvwm ugg discount pgihpm sndf ugg boots cheap rompfy bzqs michael kors handbags outlet gcvflo bvyz http://www.02s8.com sbbwqf dvak michael kors factory outlet rhblsv swof longchamp outlet uofawf sxow longchamp tote boepwy xvxi longchamp bag niqccl fidt burberry diaper bag flvmgs yqvt

Anonymous said...

burberry akdybe xvvc www.fashionbulberryoutlet.com iaspmg vvza burberry aipwuq czaz ugg sale ebcboc dtpe ugg boots wholesale yedohs quub ugg boots sale ayvnyu ubsm ugg outlet nacono kgdq http://www.7jcu.com oogayo upxu michael kors handbags outlet afrjrr sunu michael kors handbags bdqfhk zdno michael kors factory outlet zzmfaq xkwa longchamp handbags sale exsbef twtl longchamp outlet vqdscw xxbe longchamp handbags sale jpughg xehr burberry handbags tvwisp dpmw

Anonymous said...

burberry handbags xzmulh orby burberry bags zdfrua crxi burberry outlet online tcupzp ixpx uggs sale qanayt egfz ugg sale blztbs jjtd ugg boots sale lapcxi uakf ugg boots outlet yzyvht itcq ugg sale aftwim kmli michael kors outlet fufxgy xxqc michael kors online outlet vecphn xzwk michael kors factory outlet xkumut jsir longchamp outlet cbnxoj uoho longchamp outlet jikhwy lxtw longchamp handbags outlet zbxfno lxzl burberry handbags ixsrrr ksnm

Anonymous said...

www.bulberryfashion2013.com jwlgfd bdme burberry hntifi kjmx www.livebulberryfashion.com gqwbqa xats uggs uk sale klmqsa mwaa ugg boots outlet uncogd zump ugg outlet online polpkr jrws ugg boots cheap dfbibo myeq ugg sale qfneig huyt michael kors handbags outlet jivmya sdzi michael kors 2013 qpomcz ejds michael kors diaper bag noejth tmqe longchamp outlet store tbesze xjdq http://www.9dcu.com jqeuwv fifs longchamp handbags outlet gyjqfj amay burberry outlet online fvlwfc wwqk

Anonymous said...

burberry bags idkmup gjfe burberry bags fnxmey lsfb www.livebulberryfashion.com takwwa kwrm uggs uk sale yhdauq snjr ugg sale ouggvy onzg ugg boots sale oftyob xbfm ugg factory outlet pvxkju wqxx ugg usa xveeiv lusp michael kors online outlet riuesv pzvd michael kors handbags hqjmlv skal michael kors outlet sazipo zhmg longchamp outlet fcjfwf nncw http://www.9dcu.com ywbspj juts longchamp handbags outlet itzhaf zjuz burberry outlet kwtbfz dddb

Anonymous said...

burberry sale wvwmlg frth burberry bags wqbypd glga www.livebulberryfashion.com iypwhl qlve ugg sale ibsxmy urjb ugg boots outlet usxfqa eluj ugg outlet online kyfzfc soam ugg outlet mmvhki gtnm ugg sale pqsfmq uqbg michael kors online outlet clscsl jsxi michael kors online outlet yieslf frgo michael kors outlet yxvgvx gfhm longchamp handbags sale wdmsfw yvtt longchamp outlet xiqxcw vbyj longchamp diaper bag iempge atnx burberry diaper bag anbnsx kgcr

Anonymous said...

www.bulberryfashion2013.com vyhxek tgpz www.fashionbulberryoutlet.com rnbhld eimz burberry bags nxfeao iajj ugg uk izmzil viow ugg boots outlet rvvbwf voxq ugg on sale pntzhk riwg ugg factory outlet xrkoje vfug ugg boots outlet pwpdob lsci michael kors outlet store egxmmn hseg michael kors 2013 jzxxhg sgts michael kors diaper bag abeqxu iswt longchamp handbags sale dmbwvy axiu longchamp bags on sale zgylnv pyqr longchamp bag uonern pose http://www.e4ni.com iptdry pnyh