2015-06-26

Live Backup VM on XenServer 6.2

# BackUp Virtual Machine
# Citrix XenServer 6.2
# Manual
# Nuance 1: XenServer Tools are not needed on the VM

#########################################################################################################

mkdir /mnt/backup
mount -t cifs "//10.77.11.200/w4a" -o username=username,password=password /mnt/backup

#########################################################################################################

# First look for the uuid of the VMs to backup.
# We don’t want to backup the control domain itself,
# so we add is-control-domain=false to the vm-list command
# and we also don’t want backups of snapshots
# so we add is-a-snapshot=false

xe vm-list is-control-domain=false is-a-snapshot=false

uuid ( RO)           : 9814bca5-7cef-5b67-84a9-25b4ce078c86
     name-label ( RW): OpenMeetings
    power-state ( RO): halted


uuid ( RO)           : fb6f41cc-6051-96d8-ad88-6e93db6f873c
     name-label ( RW): xs62rectest
    power-state ( RO): running


uuid ( RO)           : befb8299-3e4b-cf21-db4d-117c46da7da5
     name-label ( RW): res-j-p
    power-state ( RO): running


uuid ( RO)           : 34f543c2-fc96-8271-770c-01c2a12db006
     name-label ( RW): stock03
    power-state ( RO): running


uuid ( RO)           : cee0d00c-977e-1bb0-83cb-477fac5f6f9c
     name-label ( RW): Xackup-portal
    power-state ( RO): running

#########################################################################################################

# Now we create a snapshot of the VMs we want to backup,
# replacing the vm(uuid) one by one with the ones we found
# with the previous command. Also replace the name of
# the snapshot if desired

#xe vm-snapshot uuid=fb6f41cc-6051-96d8-ad88-6e93db6f873c new-name-label=xs62rectest-snapshot-20150625001.snapshot
xe vm-snapshot vm=xs62rectest new-name-label=xs62rectest-snapshot-20150625002.snapshot

7a237b62-9c13-e579-c4f3-f4d71b4fafaa

xe snapshot-list

uuid ( RO)                : 7a237b62-9c13-e579-c4f3-f4d71b4fafaa
          name-label ( RW): xs62rectest-snapshot-20150625004.snapshot
    name-description ( RW): Test VM for backup&restore process
CentOS6.6

#########################################################################################################

# Previous command has a return value: the uuid of the created snapshot.
# Then we transform the snapshot into a VM to be able to save it to
# a file, replacing uuid with the return value of the previous command

xe template-param-set is-a-template=false ha-always-run=false uuid=7a237b62-9c13-e579-c4f3-f4d71b4fafaa

#########################################################################################################

# Now we can export created snapshot to .xva file,
# which can be easily restored from command line or XenCenter.
# .xva file is saved on a remote filesystem.

xe vm-export vm=7a237b62-9c13-e579-c4f3-f4d71b4fafaa filename=/mnt/backup/xs62rectest-20150625002.xva

#########################################################################################################

# Finally as we have already taken backup to xva file,
# so we can destroy created snapshot from xenserver

xe vm-uninstall uuid=7a237b62-9c13-e579-c4f3-f4d71b4fafaa force=true
#xe snapshot-uninstall uuid=7d4c20e1-8fd3-27c6-c79b-68cb258af952 force=true

#########################################################################################################
#########################################################################################################
#########################################################################################################

# Script

mkdir /mnt/backup
mount -t cifs "//10.77.11.200/w4a" -o username=username,password=password /mnt/backup
xe vm-list is-control-domain=false is-a-snapshot=false
xe vm-snapshot vm=xs62rectest new-name-label=xs62rectest-snapshot-20150625002.snapshot
xe template-param-set is-a-template=false ha-always-run=false uuid=7a237b62-9c13-e579-c4f3-f4d71b4fafaa
xe vm-export vm=7a237b62-9c13-e579-c4f3-f4d71b4fafaa filename=/mnt/backup/xs62rectest-20150625002.xva
xe vm-uninstall uuid=7a237b62-9c13-e579-c4f3-f4d71b4fafaa force=true
cd /mnt/backup
tar -cvzf xs62rectest-20150625002.xva.tar.gz xs62rectest-20150625002.xva
rm xs62rectest-20150625002.xva
cd ~
umount /mnt/backup

Комментариев нет: