Tuesday, 31 May 2016

[Xen] Export snapshot to file shell script

1. Check Snapshot name




2. Run shell script







exportSnapshot.sh

 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
#!/bin/sh
#########################################################
#
# Export Xen Snapshot to File
#
#########################################################
# Created by  : dorbae
# Created Date : 2016-05-31
# Last Update   : 2016-05-31
# Version : 1.0.0
#########################################################
#
# * History
#
# 1.0.0  Initialize
#
#########################################################

if [ "$#" -ne 1 ]; then
 echo "Usage: $0 [SNAPSHOT_NAME]"
 exit 1
fi

SNAPNAME=$1
DATE=`date +%Y%m%d`
TIMESTAMP=`date +%Y-%m-%d' '%T`
mkdir -p ~/xenBackup
LOGFILE=~/xenBackup/log/${SNAPNAME}.log
PIDFILE=~/xenBackup/${SNAPNAME}.pid
BACKUPDIR=/bak

echo $$ > $PIDFILE
echo "[INFO ] `date +%Y-%m-%d' '%T`: Export Snapshot Start...[PID=$$]" >> $LOGFILE

SNAPUUID=`xe snapshot-list | grep -B 1 ${SNAPNAME} | grep uuid | cut -d":" -f2 | sed 's/^ *//g'`
echo "[INFO ] `date +%Y-%m-%d' '%T`: SNAPUUID=$SNAPUUID" >> $LOGFILE

echo "[INFO ] `date +%Y-%m-%d' '%T`: Exporting $SNAPNAME Start..." >> $LOGFILE
BAKFILE=$BACKUPDIR/${SNAPNAME}.xva
echo "[INFO ] `date +%Y-%m-%d' '%T`: BAKFILE=$BAKFILE" >> $LOGFILE
xe vm-export vm=$SNAPUUID filename="$BAKFILE"

echo "[INFO ] `date +%Y-%m-%d' '%T`: Exporting $SNAPNAME End..." >> $LOGFILE

echo "[INFO ] `date +%Y-%m-%d' '%T`: Export End..." >> $LOGFILE

exit 0

No comments:

Post a Comment