XenServer Virtual Machine Backup script

Source: Internet
Author: User
Tags exit uuid backup

Recently busy with the virtual machine, what data need to be backed up, even if the virtual machine is no exception, the following is my own written backup script to use according to the actual situation,:

First do an NFS server, this server requires a large disk, and then need to back up the virtual server host on the shared directory

Then you can implement a script to make a scheduled task do a backup

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

# # To create a snapshot of all virtual machines and export to a template delete a snapshot #

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

#全部 Test OK

#!/bin/bash

#Version: V.2

#Date: 2012.07.20

#Auther: Andylhz

#Propose: Create All VM ' s snapshot on XenServer and export snapshot to template and delete the snapshot.

#Script name:A_vm_export_shapshot_to_template.sh, example:./a_vm_export_shapshot_to_template.sh

# #Get System Date

dt=$ (Date +%y%m%d%h%m%s)

# #Seting Backup dir

Backup_dir=/root/vmbk

# #Get VM UUID List

echo "VM snapshot is createing ...."

For Vmname in ' Xe vm-list Params=name-label |awk ' {print $} ' |grep-v ^c ' |sed ';

Do echo ' Xe vm-snapshot vm= $vmname new-name-label= $vmname ' >> $backup _dir/snapshot_uuid;

If [$?-eq 0]; Then

echo "VM snapshot $vmname is created .... ok! "

Else

echo "VM snapshot $vmname is created .... failse! "

Exit 1

Fi

Done

# #Export snapshots as a template

#Get Snapshot uuid

Xe snapshot-list params=uuid,name-label|sed '/^$/d ' |awk ' {print $4,$5} ' |sed ' s/://g ' |sed-e ' N; s/\n//g ' > $backup _dir/vmname_sanpuid

echo "Templates are exporting please waite ..."

For Snap_uuid in ' cat $backup _dir/vmname_snapuid|awk ' {print} ';

Do XE snapshot-export-to-template snapshot-uuid= $snap _uuid filename= $backup _dir/$snap _uuid$dt.xva;

If [$?-eq 0]; Then

echo "VM template $snap _uuid$dt is created .... ok! "

Else

echo "VM template $snap _uuid$dt is created .... failse! "

Exit 1

Fi

Done

# #Compressed Export file.

CD $backup _dir

echo "VM templates are being compressed ..."

Gzip *.xva

If [$?-eq 0]; Then

echo "VM template is compressed .... ok! "

Else

echo "VM template is compressed .... failse! "

Exit 1

Fi

# #Delete Snapshot

echo "Deleteing snapshot ..."

For Snap_uuid in ' cat $backup _dir/snapshot_uuid ';

Do XE Snapshot-uninstall snapshot-uuid= $snap _uuid force=true;

If [$?-eq 0]; Then

echo "Snapshot $snap _uuid deleted ..... ok! "

Else

echo "Snapshot $snap _uuid deleted ..... failse! "

Exit 1

Fi

Done

MV Snapshot_uuid SNAPSHOT_UUID$DT

MV Vmname_sanpuid VMNAME_SANPUID$DT

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

To take a snapshot of a virtual machine and export it as a template

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.