-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-initial-snapshot.sh
More file actions
executable file
·64 lines (56 loc) · 1.47 KB
/
create-initial-snapshot.sh
File metadata and controls
executable file
·64 lines (56 loc) · 1.47 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
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
#
# This creates an initial snapshot of a installed VM
#
# gnd @ gnd.sk, 2017 - 2019
#
#############################################################
usage() {
printf "\n"
printf "Creates encrypted initial snapshot of a VM\n"
printf "Usage: \n"
printf "$0 <name>\n\n"
}
# Check if LIMA_ROOT set
if [ -z $LIMA_ROOT ]; then
echo "Cant find LIMA. Please check if the install finished correctly."
echo "Exiting. Reason: LIMA_ROOT not set."
exit
fi
# Define globals
source $LIMA_ROOT/vms/settings
DATUM=`/bin/date +%D|sed 's/\//_/g'`
# Check for inputs
if [[ -z $1 ]]; then
usage
exit
fi
# Identify machine
VM_NAME=$1
LINS=`cat $VM_LIST | awk {'print $2;'}|grep "^$VM_NAME$"|wc -l`
if [[ $LINS -lt 1 ]]; then
echo "No such name $VM_NAME found"
exit
fi
if [[ $LINS -gt 1 ]]; then
echo "More names found, please be specific:"
cat $VM_LIST | awk {'print $2;'}|grep "^$VM_NAME$"
exit
fi
# Identify VM type
VM_TYPE=`cat $VM_LIST | awk {'print $2" "$5;'}|grep "^$VM_NAME "|awk {'print $2;'}`
if [[ $VM_TYPE == "sta" ]]; then
VM_TYPE="static"
fi
if [[ $VM_TYPE == "dyn" ]]; then
VM_TYPE="dynamic"
fi
# Create initial snapshot
echo "Creating initial snapshot of the $VM_NAME VM.."
TARNAME=$BUP_DIR"/snapshots/"$VM_NAME"_initial_"$DATUM".tar"
GPGNAME=$BUP_DIR"/snapshots/"$VM_NAME"_initial_"$DATUM".gpg"
nice tar -cf $TARNAME $VM_DIR"/"$VM_TYPE"/"$VM_NAME
nice gpg -r "lima backup" --output $GPGNAME --encrypt $TARNAME
chmod 600 $GPGNAME
rm $TARNAME
echo "Initial snapshot done"