-
Notifications
You must be signed in to change notification settings - Fork 0
/
zarafaBackupUsers.sh
79 lines (64 loc) · 1.9 KB
/
zarafaBackupUsers.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#######################################
# Backup Script for users #
# Written by Tom Van Humbeeck #
#######################################
CONFIGFILE="/usr/local/sbin/backup-wrapper.cfg"
. $CONFIGFILE
while getopts ":c:" opt; do
case $opt in
c)
if [ -f $OPTARG ]; then CONFIGFILE=$OPTARG; else echo "File not found"; fi
;;
esac
done
function increase_error_count {
ERRORCOUNT=$((${ERRORCOUNT}+1))
}
function not_found {
echo "${1} not found!" >&2
exit 1
}
for soft in zarafa-backup mail
do
which $soft &>/dev/null || not_found $soft
done
if [ ! -s ${USERS} ]; then
exit 1;
fi
(
### CONTROLE MOUNT ###
if grep -qs "$MOUNT" /proc/mounts; then
echo "It's mounted."
else
echo "It's not mounted."
mount -t ${MOUNTTYPE} -o username=${MOUNTUSER},password=${MOUNTPASS} ${HOST} ${MOUNT}
if [ $? -eq 0 ]; then
echo "Mount success!"
else
echo "Something went wrong with the mount..."
fi
fi
### Run Backup ###
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for i in `cat ${USERS}`
do
if ${BACKUP} -u $i -o ${ARCHIVE}; then
echo "Zarafa Backup for user $i succeeded"
else
echo "Zarafa Backup for user $i failed"
increase_error_count
echo $ERRORCOUNT
fi
done
echo "Gelieve removeusers.txt terug leeg te maken!"
### Logging ###
if [[ $ERRORCOUNT -gt 0 ]]; then exit $ERRORCOUNT; fi
) > ${LOGS}/backup-custom-${DATE}.log 2>&1
if [ $? -eq 0 ]
then
${MAIL} -s "Zarafa Backup Specific Users [OK]" -r $SENDER $RCPT < ${LOGS}/backup-custom-${DATE}.log
else
${MAIL} -s "Zarafa Backup Specific Users [FAILED]" -r $SENDER $RCPT < ${LOGS}/backup-custom-${DATE}.log
fi