-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeepXdaysV2
executable file
·71 lines (55 loc) · 1.54 KB
/
keepXdaysV2
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
#!/usr/local/bin/bash
if test "$1" = ""
then
echo "usage: $0 directory-of-backup-files number-of-days-to-keep"
exit 1
fi
if test "$2" = ""
then
echo "usage: $0 directory-of-backup-files number-of-days-to-keep"
exit 1
fi
if test "$3" != ""
then
echo "usage: $0 directory-of-backup-files number-of-days-to-keep"
exit 1
fi
# backupdir=/mail/backup
backupdir=$1
daystokeep=$2
currentdate=`date +%Y%m%d`
archivedate=`echo $(($currentdate - $daystokeep))`
myhostname=$(hostname)
logfile=$0.log
count=1
echo -e >> $logfile
echo -e >> $logfile
echo -e >> $logfile
echo -e >> $logfile
echo -e >> $logfile
echo " ----- $currentdate ----- " >> $logfile
echo "list of directories BEFORE script run, are :" >> $logfile
ls $backupdir >> $logfile
echo -e >> $logfile
for i in $(ls -rld $backupdir/20* | awk '{print $9}');
do
list[$count]=$i >> $logfile
let "count += 1" >> $logfile
done
echo "$daystokeep days of backup will be kept and the rest deleted, see below : " >> $logfile
while (($count > $daystokeep));
do
echo "${list[$count]} will be DELETED !!!" >> $logfile
rm -rf ${list[$count]} >> $logfile
let "count -= 1"
done
echo -e >> $logfile
echo -e >> $logfile
echo "list of directories AFTER script runned, are : " >> $logfile
ls $backupdir >> $logfile
echo -e >> $logfile
echo -e >> $logfile
df -h >> $logfile
echo " ----- $currentdate ----- " >> $logfile
mail -s "list of backup directories in $backupdir of $myhostname" ${NOTIFYEMAIL} < $logfile