-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnfsbckpscript.sh
More file actions
executable file
·54 lines (50 loc) · 1.63 KB
/
nfsbckpscript.sh
File metadata and controls
executable file
·54 lines (50 loc) · 1.63 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
#!/bin/bash
#You can leave these as comments if you wish to implement logrotate for the output of this script.
#truncate -s 0 *errors.log
#truncate -s 0 *output.log
mount_checker () {
if mountpoint -q "$1";
then
return 0
else
mount "$1"
if mountpoint -q "$1";
then
echo "NFS $1 succesfully mounted." >> "$current_date"_errors.log
return 0
fi
echo "NFS $1 is not mounted." >> "$current_date"_errors.log
return 1
fi
}
current_date=$(date +%d-%m-%Y)
#nfs_var=( $(mount -l | grep nfs | awk '{print $3}') )
nfs_var=("/dba" "/dba2" "/backup")
#declare -p nfs_var
excluded_nfs=/backup
#If the backup mountpoint is mounted we can start the rsync process
if mount_checker $excluded_nfs;
then
#Iterating over the mount points in the list provided.
for value in "${nfs_var[@]}"
do
if [[ $value != "$excluded_nfs" ]]
then
if mount_checker "$value";
then
rsync -auvPq "$value"/ $excluded_nfs/"$value" --dry-run &>> "$current_date"_output.log
#if the last exit code was not eq to 0 then try again the rsync process
if [ "$?" -ne "0" ]
then
rsync -auvPq "$value"/ $excluded_nfs/"$value" --dry-run 2>> "$current_date"_errors.log
echo "Script ran once more for $value" >> "$current_date"_errors.log
fi
fi
fi
done
fi
#Size is > 0 bytes
if [[ -s "$current_date"_errors.log ]]
then
echo "Take a look at the attached." | mail -s "$current_date" user@example.com -A "$current_date"_errors.log
fi