• Home
  • Store
  • Forum
  • Blog

XTDV Forum
Đăng nhập Đăng ký
Đăng nhập XTDV Forum

XTDV Forum › International zone (English only) › SERVER
Automatic backup XenServer VM by creating snapshot

Thread tools
Automatic backup XenServer VM by creating snapshot
xtdv
Điều hành cao cấp
Bài viết: 504
5 Likes
   
#1
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:
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/




Tập tin đính kèm
.zip   xe_snapshot_running.zip (Kích thước: 1,15 KB / Tải xuống: 52)
Trả lời
Send thread to a friend
Send thread to a friend
Send thread to a friend
Send thread to a friend



Những người đang xem chủ đề này:   1 khách


  •  Trở lên trên
  •  Liên hệ
  •   XTDV Group
  • Bản thu gọn (Lưu trữ)
© Rush Crafted with ❤ by iAndrew
Chạy trên nền tảng MyBB, © 2002-2021 MyBB Group.
Chế độ thứ tự
Chế độ đề tài
Xem phiên bản để in
Theo dõi đề tài này
Thêm bình chọn
Send thread to a friend