The website log is regularly cleaned and backed up every day, and the log script is retained for 10 days

Lao Yang one hundred and fifty-eight zero

The website log is regularly cleaned every day, and the log script is retained for 10 days. The daily log is backed up to an independent folder, and only 10 days of log records are retained. Log records over 10 days are automatically deleted.

The following code is saved as log.sh, and the pagoda plan task can be visited once a day at 0:00.

The 10 days in the code can change the number of days you want to keep.

 #!/ bin/bash #echo "/www/wwwlogs" #0 0 * * * /www/log.sh >/dev/null 2>&1 Dir=/www/wwwlogs time=`date +%Y%m%d%H%M%S` mkdir -p $Dir/${time}/ mv $Dir/*.log $Dir/${time}/ time=`date +%Y%m%d%H%M%S -d "10 day ago"` for subdir in `ls $Dir`; do     if [ "${subdir}" \< "${time}" ]; then         rm -rf $Dir/$subdir >/dev/null     fi done



Export Document
Reward the author
Regular Daily Cleaning and Backup of Website Logs Retention of 10 Day Log Script.doc
Download and save this article for collection and printing
Export Document