本篇文章介绍的内容是关于如何在xenserver中备份正在运行的虚拟机,并且可以逐步运行vm的备份过程,此外还有一个shell脚本,可以将所有vm备份或指定的vm备份,我们也可以通过crontab进行调度。
方法1:手动备份正在运行的虚拟机
以下步骤也可以通过xencenter执行,但linux用户喜欢使用命令行。
1、查找vms uuid
使用以下命令获取所有vms的uuid列表以及其他详细信息。此uuid将在下一步中使用
# 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
根据上述输出测试,vm uuid为“8ac95696-94f3-83c1-bc89-8bb2603f832b”。你可能是其他情况。
2、创建vms快照
现在使用下面的命令使用上面步骤中找到的uuid创建vm快照。确保使用正确的uuid。
# xe vm-snapshot uuid=8ac95696-94f3-83c1-bc89-8bb2603f832b new-name-label=testvmsnapshot
上面的命令将检索快照的uuid,使用该uuid将快照转换为vm,因此我们可以使用下面的命令将其导出到文件。
# xe template-param-set is-a-template=false ha-always-run=false uuid=b15c0531-88a5-98a4-e484-01bc89131561
3、将快照导出到文件
现在,我们可以将创建的快照导出到.xva文件,这可以很容易地从命令行或xencenter恢复。
# xe vm-export vm=b15c0531-88a5-98a4-e484-01bc89131561 filename=vm-backup.xva
4、销毁快照
最后,因为我们已经备份到xva文件,所以我们可以从xenserver销毁创建的快照。
# xe vm-uninstall uuid=b15c0531-88a5-98a4-e484-01bc89131561 force=true
方法2:使用脚本备份运行vms
为了备份xenserver上运行的所有虚拟机,我们还可以使用以下shell脚本。此脚本安装了通过nfs导出的远程文件系统。这个脚本非常适合这个例子,但对你可能不适用。所以使用这个脚本并不能保证你的可行。
#!/bin/bash## written by: mr rahul kumar# created date: jun 14, 2014# last updated: mar 08, 2017# version: 1.2.1# visit: https://tecadmin.net/backup-running-virtual-machine-in-xenserver/#date=`date +%d%b%y`xsname=`echo $hostname`uuidfile=/tmp/xen-uuids.txtnfs_server_ip="192.168.10.100"mountpoint=/xenmntfile_location_on_nfs="/backup/citrix/vms"### create mount pointmkdir -p ${mountpoint}### mounting remote nfs share backup drive[ ! -d ${mountpoint} ] && echo "no mount point found, kindly check"; exit 0mount -f nfs ${nfs_server_ip}:${file_location_on_nfs} ${mountpoint}backuppath=${mountpoint}/${xsname}/${date}mkdir -p ${backuppath}[ ! -d ${backuppath} ] && echo "no backup directory found"; exit 0# fetching list uuids of all vms running on xenserverxe vm-list is-control-domain=false is-a-snapshot=false | grep uuid | cut -d":" -f2 > ${uuidfile}[ ! -f ${uuidfile} ] && echo "no uuid list file found"; exit 0while read vmuuiddo vmname=`xe vm-list uuid=$vmuuid | grep name-label | cut -d":" -f2 | sed 's/^ *//g'` 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} xe vm-export vm=${snapuuid} filename="$backuppath/$vmname-$date.xva" xe vm-uninstall uuid=${snapuuid} force=truedone < ${uuidfile}umount ${mountpoint}
本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注的linux视频教程栏目!
以上就是如何在xenserver中备份正在运行的虚拟机的详细内容。