linux 备份日志文件

seo说要备份文件,然后自己搞不定,每天一份文件。写了个shell,加了个crontab -e任务。每天执行一次。

crontab:

59 23 * * * /root/sh/dumpApacheLog

shell:

#!/bin/sh
today=$(date +%Y%m%d)
newAccessLog="/usr/local/httpd/logs/"$today"access_log"
newErrorLog="/usr/local/httpd/logs/"$today"error_log"
mv /usr/local/httpd/logs/access_log $newAccessLog
mv /usr/local/httpd/logs/error_log $newErrorLog
touch /usr/local/httpd/logs/access_log
touch /usr/local/httpd/logs/error_log
chmod 777 /usr/local/httpd/logs/error_log
chmod 777 /usr/local/httpd/logs/access_log

如果感觉不错,请 一个!
by simpman
原文地址:https://www.cnblogs.com/simpman/p/3232413.html