Thứ ba, 06/05/2014, 16:21
(Bài viết được chỉnh sửa lần cuối vào Thứ năm, 22/05/2014, 14:29 bởi xtdv.)
You need xe-cli package installed on your Linux machine. It comes with XenServer installation CD, named xe-cli....rpm.
Create a file named xe_snapshot_running.sh:
Fill in the file with contents below:
Make it executable and edit your crontab to run it automatically
Example crontab running the snapshot weekly:
Reference source:
- http://docs.vmd.citrix.com/
- http://run.tournament.org.il/xenserver-create-snapshots-for-all-machines/
Create a file named xe_snapshot_running.sh:
Mã:
touch ~/xe_snapshot_running.sh
Fill in the file with contents below:
Mã:
# Define variables and paths
DATE=`date +%Y%m%d`
XE_CLI=/usr/bin/xe
XE_ARG=""
# Index arguments
for VARIABLE in "$@"
do
ARGUMENT=("${ARGUMENT[@]}" "$VARIABLE")
done
INDEX=1
for VARIABLE in "$@"
do
# Find server address variable
if [[ $VARIABLE == "-s" ]]; then
#WARN_TIME="${ARGUMENT[$INDEX]}"
XE_ARG="$XE_ARG -s ${ARGUMENT[$INDEX]}"
fi
# Find server port variable
if [[ $VARIABLE == "-p" ]]; then
#CRIT_TIME="${ARGUMENT[$INDEX]}"
XE_ARG="$XE_ARG -p ${ARGUMENT[$INDEX]}"
fi
# Find login name variable
if [[ $VARIABLE == "-u" ]]; then
#WARN_SIZE="${ARGUMENT[$INDEX]}"
XE_ARG="$XE_ARG -u ${ARGUMENT[$INDEX]}"
fi
# Find password variable
if [[ $VARIABLE == "-pw" ]]; then
#CRIT_SIZE="${ARGUMENT[$INDEX]}"
XE_ARG="$XE_ARG -pw ${ARGUMENT[$INDEX]}"
fi
((INDEX++))
done
if [[ $XE_ARG == *-s* ]]; then
# List running VMs and get UUIDs
VM_UUID_RAW=(`$XE_CLI vm-list power-state=running is-control-domain=false params=uuid $XE_ARG |awk '{print $5}'`);
# Snapshot all VMs in the list
for VM_UUID in ${VM_UUID_RAW[@]}; do
eval $XE_CLI vm-snapshot vm=$VM_UUID new-name-label="AutoBackup $DATE" $XE_ARG
if [ $? == 0 ]; then
echo -e "Virtual Machine has been snapshoted successful.\n"
else
echo -e "Virtual Machine has not been snapshoted.\n"
fi
done
else
echo "Usage: xe_snapshot_running.sh [-s server] [-p port] ([-u username] [-pw password])"
fi
Make it executable and edit your crontab to run it automatically
Mã:
chmod +x ~/xe_snapshot_running.sh
crontab -e
Example crontab running the snapshot weekly:
Mã:
59 23 * * 5 /root/xe_snapshot_running.sh -s xen1.xtdv.local -u root -pw password
Reference source:
- http://docs.vmd.citrix.com/
- http://run.tournament.org.il/xenserver-create-snapshots-for-all-machines/