服务器: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
享受! :)