{"id":948,"date":"2016-08-19T20:47:28","date_gmt":"2016-08-20T01:47:28","guid":{"rendered":"http:\/\/xfloyd.net\/blog\/?p=948"},"modified":"2019-02-24T09:41:27","modified_gmt":"2019-02-24T14:41:27","slug":"citrix-xenserver-backup-without-downtime","status":"publish","type":"post","link":"https:\/\/xfloyd.net\/blog\/?p=948","title":{"rendered":"Citrix XenServer backup without downtime."},"content":{"rendered":"<div class=\"single-post-content\">\n<p>Backup running Virtual Machine in XenServer. I am working with Citrix XenServer for many years and managing all XenServers using XenCenter installed on a standalone windows machine. We regularly take backup of VMs manually until today, I always take backups after shutting down the VM. Most of VM owner getting disappointed due to server down for a long time. While searching for the Google I found a better way to back up VMs without shutdown them. It means we can take running VM backups and not downtime occurred.<\/p>\n<p><a href=\"https:\/\/tecadmin.net\/wp-content\/uploads\/2014\/06\/citrix-image.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5451\" src=\"https:\/\/tecadmin.net\/wp-content\/uploads\/2014\/06\/citrix-image.png\" alt=\"citrix-image\" width=\"580\" height=\"224\" \/><\/a><\/p>\n<p>This tutorial we will help you step by step backup process of running VM. Also here is a shell script which can take all VMs backup or specified VM backup, which we can schedule through crontab as well.<\/p>\n<h2 class=\"heading1\">Method 1 \u2013 Manual Backup of Running VM<\/h2>\n<p>Following steps also can be performed through XenCenter, But Linux lovers love the command line. So find commands to do it.<\/p>\n<h3 class=\"heading2\">1.1. Find VMs UUID<\/h3>\n<p>Use the following command to get list of UUIDs of all vms along with other details. this UUID will be used in next step<\/p>\n<pre>xe vm-list is-control-domain=false is-a-snapshot=false\n<\/pre>\n<p><em>Sample Output:<\/em><\/p>\n<pre class=\"pretty\">uuid ( RO)           : 8ac95696-94f3-83c1-bc89-8bb2603f832b\n     name-label ( RW): test-vm\n    power-state ( RO): running\n<\/pre>\n<p>As per above output test-vm uuid is \u201c<strong>8ac95696-94f3-83c1-bc89-8bb2603f832b<\/strong>\u201c. It can be different in your case.<\/p>\n<h3 class=\"heading2\">1.2. Create VMs Snapshot<\/h3>\n<p>Now use the following command to create snapshot of vm using uuid found in above step. Make sure you are using correct uuid.<\/p>\n<pre>xe vm-snapshot uuid=8ac95696-94f3-83c1-bc89-8bb2603f832b new-name-label=testvmsnapshot\n<\/pre>\n<p>Above command will retrun a UUID of snapshot, Use that UUID to convert snapshot to a vm, so we can export it to file using below command.<\/p>\n<pre>xe template-param-set is-a-template=false ha-always-run=false uuid=b15c0531-88a5-98a4-e484-01bc89131561\n<\/pre>\n<h3 class=\"heading2\">1.3. Export Snapshot to File<\/h3>\n<p>Now we can export created snapshot to .xva file, Which can be easily restored from command line or XenCenter.<\/p>\n<pre>xe vm-export vm=b15c0531-88a5-98a4-e484-01bc89131561 filename=vm-backup.xva\n<\/pre>\n<h3 class=\"heading2\">1.4. Destroy Snapshot<\/h3>\n<p>Finally as we have already taken backup to xva file, so we can destroy created snapshot from xenserver.<\/p>\n<pre>xe vm-uninstall uuid=b15c0531-88a5-98a4-e484-01bc89131561 force=true\n<\/pre>\n<h2 class=\"heading1\">Method 2 \u2013 Using Script for Backup Running VMs<\/h2>\n<p>To backup all VMs running on XenServer, we can use following shell script also. This script mounted remote file system exported through NFS. This script works for me perfectly, but it may not for you. So use this script at your own risk.<\/p>\n<pre>#!\/bin\/bash\n#\n# Written By: Mr Rahul Kumar\n# Created date: Jun 14, 2014\n# Last Updated: Mar 08, 2017\n# Version: 1.2.1\n# Visit: https:\/\/tecadmin.net\/backup-running-virtual-machine-in-xenserver\/\n#\n\nDATE=`date +%d%b%Y`\nXSNAME=`echo $HOSTNAME`\nUUIDFILE=\/tmp\/xen-uuids.txt\nNFS_SERVER_IP=\"192.168.10.100\"\nMOUNTPOINT=\/xenmnt\nFILE_LOCATION_ON_NFS=\"\/backup\/citrix\/vms\"\n\n### Create mount point\n\nmkdir -p ${MOUNTPOINT}\n\n### Mounting remote nfs share backup drive\n\n[ ! -d ${MOUNTPOINT} ]  &amp;&amp; echo \"No mount point found, kindly check\"; exit 0\nmount -F nfs ${NFS_SERVER_IP}:${FILE_LOCATION_ON_NFS} ${MOUNTPOINT}\n\nBACKUPPATH=${MOUNTPOINT}\/${XSNAME}\/${DATE}\nmkdir -p ${BACKUPPATH}\n[ ! -d ${BACKUPPATH} ]  &amp;&amp; echo \"No backup directory found\"; exit 0\n\n\n# Fetching list UUIDs of all VMs running on XenServer\nxe vm-list is-control-domain=false is-a-snapshot=false | grep uuid | cut -d\":\" -f2 &gt; ${UUIDFILE}\n\n[ ! -f ${UUIDFILE} ] &amp;&amp; echo \"No UUID list file found\"; exit 0\n\nwhile read VMUUID\ndo\n    VMNAME=`xe vm-list uuid=$VMUUID | grep name-label | cut -d\":\" -f2 | sed 's\/^ *\/\/g'`\n\n    SNAPUUID=`xe vm-snapshot uuid=$VMUUID new-name-label=\"SNAPSHOT-$VMUUID-$DATE\"`\n\n    xe template-param-set is-a-template=false ha-always-run=false uuid=${SNAPUUID}\n\n    xe vm-export vm=${SNAPUUID} filename=\"$BACKUPPATH\/$VMNAME-$DATE.xva\"\n\n    xe vm-uninstall uuid=${SNAPUUID} force=true\n\ndone &lt; ${UUIDFILE}\n\numount ${MOUNTPOINT}\n<\/pre>\n<p>Download this script directly from Github.com<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/tecrahul\/xenvmbackup\/blob\/master\/xenvmbackup.sh\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/tecrahul\/xenvmbackup\/blob\/master\/xenvmbackup.sh<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Backup running Virtual Machine in XenServer. I am working with Citrix XenServer for many years and managing all XenServers using XenCenter installed on a standalone windows machine. We regularly take backup of VMs manually until today, I always take backups after shutting down the VM. Most of VM owner getting disappointed due to server down [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,26,28],"tags":[],"_links":{"self":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/948"}],"collection":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=948"}],"version-history":[{"count":4,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/948\/revisions"}],"predecessor-version":[{"id":1138,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/948\/revisions\/1138"}],"wp:attachment":[{"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}