-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathghetto-backup-mon.sh
executable file
·62 lines (55 loc) · 1.54 KB
/
ghetto-backup-mon.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
#!/bin/bash
# vim: set ts=4 sw=4 sts=4 :
# if you are reading this, I have some funny stories to tell about ghetto
###### Config Begin ######
backups_dir=/volume1/vol1/ghetto
days=45 #maximum age of files
exclude_dirs_array=( iso ghetto-master archive ) #ignore these directories located in $backups_dir
oldlist=/tmp/no-recent-ghetto-bkups
mailer=ssmtp #app to use for mailing out the report
[email protected] #who is to receive the report/list of old backups
####### Config End #######
cat /dev/null > /tmp/no-recent-ghetto-bkups
exclude_dirs_array=("${exclude_dirs_array[@]/#/$backups_dir/}")
ip_dirs_array=()
for d in "$backups_dir"/*
do
if [[ -d "$d" && ! -L "$d" && ! "${exclude_dirs_array[@]}" =~ "$d" ]]
then
#echo $d
for vm in "$d"/*
do
#echo $vm
# only work on directories
if [ -d "$vm" ]
then
#$echo $vm
for bkup in "$vm"/*
do
#echo $bkup
for file in "$bkup"/*
do
if [[ $(find "$file" -mtime +$days -print) ]]
then
#echo $file
echo $vm >> $oldlist
fi
done
done
fi
done
fi
done
oldbkups=$( cat $oldlist | wc -l )
if [ $oldbkups -gt 0 ]
then
#get rid of duplicate lines in /tmp/no-recent-ghetto-bkups
cat $oldlist | uniq > $oldlist-sorted
mv $oldlist-sorted $oldlist
cat $oldlist | $mailer $recipient
echo "$vm has backups older than $days days"
exit 1
else
echo "all ghetto backups are current"
exit 0
fi