Keith Smith - Think Ahead. Learn More. Solve Now!

XenServer VM Backups

Tuesday, June 02, 2015 - by Keith A. Smith

I've been trying to conjure up some way to backup the guests that reside in a xenserver virtualized environment. I started off by looking at what i would call my usual suspects (e.g. unitrends, alike, etc.) unfortunately in this situation they all let me down for one reason or another, so i did what most creative minds do when they can't find a solution "Make my own". I figured i start by jumping on to the cli at the host, i know most hypervisors reference the guest by UUID's. I spent sometime looking through the variables and commands on the host, i eventually came up with

# xe vm-list
 which produces the following output for all guests

uuid ( RO)           : 15b96001-84c6-83d1-ef11-8gh6509i122j
     name-label ( RW): nameoftheguest
    power-state ( RO): running

Another command i saw that was available was #vm-snapshot, so i figured I'd try and string it together by doing a xe vm-snapshot uuid=15b96001-84c6-83d1-ef11-8gh6509i122j or tab which display all uuid's. And the tale of the command i place name-label=snapshot, so the whole thing would look like 

xe vm-snapshot uuid=15b96001-84c6-83d1-ef11-8gh6509i122j name-label=vmsnapshot

Now that i saw that worked i figured i would develop a crontab task using the #crontab -e command that would run a shell script (which i will post at another time) to handle this redundant task which was version1 of this solution. Once I uploaded the shell script i needed to make it executable, which i did by running the chmod +x command. I attempted to execute it and got a error bad interpreter - No such file or directory, some times when you move files from DOS/windows to linux or nix system you run into the ^M charater problem. The way i have solved this so many times is simply to open the file in the vim editor using the following command
vi -b once the file is open you will see ^M at the end of each line, the quickest way to remove this is to run :1,$s/^M//g the trick to this command that you don't really type a ^ character and then a M character 
to generate that command. You actually type a [Control][v] and then a [Control][m] to create the necessary character then do a :wq to write and quit the editor. I figure it must be punishment for not developing the script in the vim editor in the first place. 

So far this has been working for the xenserver environment, in version2 of this i included retention elements and frequency of backups for individual guests. In my last version3 i added more comments to the script because the code was pretty extensive at this point (over 100 lines of code). The next item i have on my dev to-do list would be to add some mail functionality, so i can be notified of the out come of the backup job.

Note: this files used to perform the backups should copied from the hypervisor prior to any upgrades.
  Share Post   

View Comments Comments

Leave a Comment