![如何将计划的 XenServer VM 备份保存到外部驱动器](https://linux22.com/image/728362/%E5%A6%82%E4%BD%95%E5%B0%86%E8%AE%A1%E5%88%92%E7%9A%84%20XenServer%20VM%20%E5%A4%87%E4%BB%BD%E4%BF%9D%E5%AD%98%E5%88%B0%E5%A4%96%E9%83%A8%E9%A9%B1%E5%8A%A8%E5%99%A8.png)
服务器:XenServer 7.1
管理:思杰中心
目标:将计划快照保存到通过 USB 连接到服务器的外部驱动器
问题:服务器将外部驱动器识别为可移动存储库,但我无法找到将其设置为快照的默认位置。
答案1
这是我创建的代码。它每天凌晨 4 点通过 SUDO 的 cron 运行
#!/bin/bash
datum=`date +%Y%b%d`
xsname=`hostname`
uuidfile=/root/xenuuids.txt
mountpoint=/var/removable
backuppath=$mountpoint/vms/$xsname/$datum
if [ ! -d $mountpoint/vms ]; then
mount /dev/sdb1 $mountpoint
mkdir $mountpoint/vms
fi
if [ ! -d $mountpoint/vms ]; then
echo "No mountpoint found. Please check!"
exit 0
fi
mkdir -p $backuppath
if [ ! -d $backuppath ]; then
echo "No backup path found. Please check!"
exit 0
fi
xe vm-list is-control-domain=false is-a-snapshot=false | grep uuid | cut -d":" -f2 > $uuidfile
if [ ! -f $uuidfile ]; then
echo "No UUID file found. Please check!"
exit 0
fi
while read VMUUID
do
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-$VMNAME-$datum"`
xe template-param-set is-a-template=false ha-always-run=false uuid=$SNAPUUID
xe vm-export vm=$SNAPUUID filename=$backuppath/SNAPSHOT-$VMNAME-$datum.xva
xe vm-uninstall uuid=$SNAPUUID force=true
done <$uuidfile
umount $mountpoint
exit
享受! :)