-
Notifications
You must be signed in to change notification settings - Fork 0
/
virsh-save-xml
executable file
·36 lines (26 loc) · 959 Bytes
/
virsh-save-xml
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
#!/usr/bin/env bash
exdir="$(dirname "$(readlink -f "$0")")"
if [ "$2" == "" ]; then
echo "$0 <vmname> <outputfolder>"
echo
echo "create backup <vmname>.xml and <snap1>.xml ... in <outputfolder/<vmname> directory"
echo
echo "Specify vmname between follows:"
virsh list --all --name
exit 1
fi
domain="$1"
dstfolder="$2/$domain"
mkdir -p "$dstfolder"/snapshots
virsh dumpxml "$domain" > "$dstfolder/$domain".xml
echo "Created $dstfolder/$domain.xml"
# snapshots sorted by create timestamp reverse
snaps=$(virsh snapshot-list "$domain" | tail -n +3 | awk 'NF' | awk '{print $2 "_" $3 "_" $4 " " $1}' | sort | awk '{print $2}')
let i=0
for snap in $snaps; do
# snapshot with XXX digit prefix suitable for further ordering during restore
dstfilename="$dstfolder/snapshots/$(printf "%03d" $i)_$snap".xml
virsh snapshot-dumpxml "$domain" "$snap" > "$dstfilename"
echo "Created $dstfilename"
let i=$i+1
done