-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathxenvmbackup.sh
More file actions
54 lines (42 loc) · 1.54 KB
/
xenvmbackup.sh
File metadata and controls
54 lines (42 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Script for backing up running Virtual Machines in XenServer
# Written by: Mr. Rahul Kumar
# Creation date: Jun 14, 2014
# Last updated: Mar 14, 2024
# Version: 1.3
# More information at: https://tecadmin.net/backup-running-virtual-machine-in-xenserver/
DATE=$(date +%d%b%Y)
XS_HOSTNAME=$(hostname)
UUIDFILE="/tmp/xen-uuids.txt"
NFS_SERVER_IP="192.168.10.100"
MOUNTPOINT="/xenmnt"
FILE_LOCATION_ON_NFS="/backup/citrix/vms"
# Create mount point
mkdir -p "${MOUNTPOINT}"
# Mounting remote NFS share backup drive
if [ ! -d "${MOUNTPOINT}" ]; then
echo "No mount point found, kindly check"
exit 1
fi
mount -F nfs "${NFS_SERVER_IP}:${FILE_LOCATION_ON_NFS}" "${MOUNTPOINT}"
BACKUPPATH="${MOUNTPOINT}/${XS_HOSTNAME}/${DATE}"
mkdir -p "${BACKUPPATH}"
if [ ! -d "${BACKUPPATH}" ]; then
echo "No backup directory found"
exit 1
fi
# Fetching list UUIDs of all VMs running on XenServer
xe vm-list is-control-domain=false is-a-snapshot=false | grep uuid | cut -d":" -f2 | tr -d ' ' > "${UUIDFILE}"
if [ ! -f "${UUIDFILE}" ]; then
echo "No UUID list file found"
exit 1
fi
while IFS= read -r 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-$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=true
done < "${UUIDFILE}"
# Unmount the mount point
umount "${MOUNTPOINT}"