Did you know that you can navigate the posts by swiping left and right?

How to backup running virtual machine in Xenserver and move to Amazon S3

15 Feb 2017 . category: sysadmin . Comments
#sysadmin #xenserver #backup #aws #s3

How to backup running virtual machine in Xenserver and move to Amazon S3

To backup running virtual machine in xenserver, we can following below steps:

Find VM UUIDs


# xe vm-list is-control-domain=false is-a-snapshot=false
uuid ( RO)           : 8ac95696-94f3-83c1-bc89-8bb2603f832b
     name-label ( RW): test-vm
    power-state ( RO): running

Create VM snapshot


# xe vm-snapshot uuid=8ac95696-94f3-83c1-bc89-8bb2603f832b new-name-label=testvmsnapshot

Above command will return a UUID of snapshot, use the UUID to convert snapshot to a VM, so we can export it to file using below command


# xe template-param-set is-a-template=false ha-always-run=false uuid=b15c0531-88a5-98a4-e484-01bc89131561

Export snapshot to file


# xe vm-export vm=b15c0531-88a5-98a4-e484-01bc89131561 filename=vm-backup.xva

Copy snapshot to S3


aws s3 cp vm-backup.xva s3://your-bucket

Destroy snapshot


# xe vm-uninstall uuid=b15c0531-88a5-98a4-e484-01bc89131561 force=true

Below is the bash shellscript, it will help you schedule the job to backup. The script mounted NFS file system to store the snapshot, will umount once done.


#!/bin/bash
#
#

DATE=`date +%d%b%Y`
MOUNTPOINT=/xenmnt
NFS_SERVER_IP="x.x.x.x"
VMUUID='XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
### Create mount point

mkdir -p ${MOUNTPOINT}

### Mounting remote nfs share backup drive

mount -F ${NFS_SERVER_IP}:/backup/vm ${MOUNTPOINT}

### Get VM name

VMNAME=`xe vm-list uuid=$VMUUID | grep name-label | cut -d":" -f2 | sed 's/^ *//g'`

### Create VM snapshot
SNAPUUID=`xe vm-snapshot uuid=${VMUUID} new-name-label="SNAPSHOT-${VMUUID}-$DATE"`

xe template-param-set is-a-template=false ha-always-run=false uuid=${SNAPUUID}

### Export snapshot
    
xe vm-export vm=${SNAPUUID} filename="${MOUNTPOINT}/${VMNAME}-$DATE.xva"

### Copy to S3
aws s3 cp ${MOUNTPOINT}/${VMNAME}-$DATE.xva s3://your-bucket
### Destroy snapshot
xe vm-uninstall uuid=${SNAPUUID} force=true

### Unmount drive
umount ${MOUNTPOINT}


Me

Harry Nguyen is an awesome person. Abosolutely true!.