forked from mfens98/heprc-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrotate_archives.sh
executable file
·38 lines (29 loc) · 1.03 KB
/
rotate_archives.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
#!/bin/bash
thisMonth=$(date +%m%y)
lastMonth=$(date -d "1 month ago" +%m%y)
twoMonths=$(date -d "2 months ago" +%m%y)
oneYearAgo=$(date -d "13 months ago" +%m%y)
wkdir="/home/mfens98/apel/archive"
logFile=$wkdir/../logs/archiveRotate$thisMonth.log
archives=($wkdir/*)
echo "$(date) Rotating Record Archives..." >> $logFile
for arch in ${archives[@]}
do
case $arch in
*"$oneYearAgo"*) #delete records older than 1 year
rm -f $arch
;;
*"$twoMonths"*) #compress records at 2 months old
gzip -9 -S .gz $arch
;;
*"$lastMonth"*) #make new record files for this month
echo "APEL-individual-job-message: v0.3" > ${arch::-4}$thisMonth
;;
esac
done >> $logFile 2>&1
echo "Compressing Old accounting logs and deleting even older ones..." >> $logFile
rm -f $wkdir/../logs/accountingLog.log.archive.old.gz
gzip -9 -S .old.gz $wkdir/../logs/accountingLog.log.archive >> $logFile 2>&1
rm -f $wkdir/../logs/ssmsend.log.old.gz
gzip -9 -S .old.gz $wkdir/../logs/ssmsend.log >> $logFile 2>&1
echo "Done!" >> $logFile