-
Notifications
You must be signed in to change notification settings - Fork 0
/
kvmbk.sh
64 lines (61 loc) · 1.25 KB
/
kvmbk.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env bash
green='\033[0;32m'
clear='\033[0m'
echo -e ${green}
cat <<'EOF'
.
.
. ;.
.;
;;.
;.;;
;;;;.
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
..;;;;;..
':::::'
':`
version 1
EOF
echo -e ${clear}
print_red (){
echo -e "\033[0;31m$1\033[0m"
}
if [[ $EUID -ne 0 ]]; then
print_red "This script must be run as root"
exit 1
fi
userid=$SUDO_USER
time=$(date | sed "s/ /_/g")
echo "current dir"
echo ""
pwd
ls -1
echo ""
read -p "Where are we backing up to? (absolute path only) " bkpath
test -d $bkpath&&echo 'Path already created'||mkdir -p $bkpath;
echo backing up to $bkpath
virsh list --all
echo "Which VM are we trying to backup? "
read -p "Notice this VM will be powered down. " vmname
virsh shutdown $vmname >> /dev/null 2>&1
drives=$(virsh domblklist $vmname | grep -o \/.*)
for drive in $drives; do
echo " "
echo VM $vmname drive $drive is being copied to $bkpath
rsync --info=progress2 $drive $bkpath
done
echo " "
echo copying xml to $bkpath
virsh dumpxml $vmname >> $bkpath/$vmname.xml
echo check files for accuracy
ls -lah $bkpath
read -p "Would you like to zip this? (y/N)" yn
case $yn in
[yY] ) echo compressing to $vmname.$time.bk ;
7z a $vmname.$time.bk $bkpath;;
* ) echo "Skipping compress ";;
esac