본문 바로가기

스크립트

액세스 로그 백업 스크립트

반응형

액세스 로그 백업 스크립트

vim web_log_backup.sh
#!/bin/bash

# Script Name: web_log_backup.sh
# Description: Backup script for web logs

logDirectory=/svc/idp/web/apache/logs
yesterday=$(date --date '1 days ago' +%Y%m%d)
today=$(date +%d)
yyyymm=$(date --date '28 days ago' +%Y%m)

# daily backup accesslog & errorlog
cd ${logDirectory}

tar zcvf access-${yesterday}.log.tgz access-${yesterday}*.log
tar zcvf error-${yesterday}.log.tgz error-${yesterday}*.log
rm -f *-${yesterday}*.log

# monthly backup accesslog & errorlog
if [ "${today}" = "01" ]; then
    tar zcvf access-${yyyymm}.log.tgz access-${yyyymm}??.log.tgz
    tar zcvf error-${yyyymm}.log.tgz error-${yyyymm}??.log.tgz
    rm -f *-${yyyymm}??.log.tgz

    find ./ -name "*.tgz" -mtime +180 -delete
fi

 

728x90
반응형