-
Notifications
You must be signed in to change notification settings - Fork 1
/
keepxdays
executable file
·64 lines (49 loc) · 1.45 KB
/
keepxdays
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
#!/usr/local/bin/bash
currentdate=`date +%Y%m%d`
archivedate=`echo $(($currentdate - $daystokeep))`
myhostname=$(hostname)
#logfile=/root/script/keepXdays.log
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/$filepattern* | 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" [email protected] < $logfile
daystokeep=90
logsDir=/web
filepattern=access
for logDir in $(find $logsDir -type d -iname $filepattern);
do
keeponly $logDir $filepattern $days
done
filepattern=error
for logDir in $(find $logsDir -type d -iname $filepattern);
do
keeponly $logDir $filepattern $days
done