-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-post
executable file
·109 lines (93 loc) · 1.44 KB
/
backup-post
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
function wait () {
echo Sleeping for $1 seconds ...
sleep $1
}
function ismounted () {
MNTPT=${1}
mount | grep -q " $MNTPT "
RET=$?
if [ "$RET" = "0" ]
then
true
else
false
fi
}
function snapexist () {
SNAPSHOT=${1}
lvscan | grep -q "'$SNAPSHOT'"
RET=$?
if [ "$RET" = "0" ]
then
true
else
false
fi
}
function retry() {
CMD=$1
MAXRETRY=$2
MSG=$3
COUNT=1
while [ $COUNT -lt $MAXRETRY ]
do
echo "$MSG [try $COUNT]"
$CMD
if [[ $? = 0 ]]
then
SUCCESS=true
break
fi
COUNT=$(($COUNT+1))
sleep 1
done
if [ $SUCCESS = true ]
then
echo "$MSG succesfull [ $COUNT tries]"
else
echo "$MSG failed"
fi
}
function umountretry() {
MNTPT=${1}
if ( ismounted $MNTPT )
then
retry "umount $MNTPT" 10 "Umounting $MNTPT"
else
echo "$MNTPT not mounted"
fi
}
function snapremoveretry() {
SNAPSHOT=${1}
if ( snapexist $SNAPSHOT )
then
retry "snapremove $SNAPSHOT" 10 "Removing $SNAPSHOT"
else
echo "$SNAPSHOT not exist"
fi
}
function snapremove() {
SNAPSHOT=$1
lvremove -f $SNAPSHOT > /dev/null 2>&1
}
cd /
echo Starting post backup job
umountretry /mnt/backup/boot 10
for VOLUME in home root
do
LVSRC=$VOLUME
SNAPNAME="${LVSRC}sn"
ORIMNT=$(mount | grep "/dev/mapper/junovg0-${VOLUME} " | cut -f 3 --delimiter=' ')
ORIMNT=${ORIMNT%/}
ORIMNT=${ORIMNT#/}
MNTPT=/mnt/backup/${ORIMNT}
MNTPT=${MNTPT%/}
cd /
umountretry $MNTPT 10
snapremoveretry /dev/junovg0/$SNAPNAME 10
done
if [ "$1" != "nosuspend" ]
then
/home/diesis/local/bin/sospendi
fi