Linux logrotate deleted some day ago

Source: Internet
Author: User

Crontab

crontab -l01 */2 * * * /usr/sbin/logrotate -v /opt/shell_app/appengine >/tmp/logrotate.log 2>&1

Logrotate

$ cat /opt/shell_app/appengine compressdailysize 10Mmissingokrotate 7/ebs_data/opt/typhoonae/var/log/http*.log{    rotate 1    prerotate        /opt/shell_app/cut.sh ${1}.2.gz    endscript    postrotate        kill -USR1 $(/sbin/pidof nginx) > /dev/null 2>&1 || true    endscript    create 644 steve steve}/opt/proftpd/var/*.log/opt/gltfs/*.log/opt/redis/var/*.log{    copytruncate    prerotate        /opt/shell_app/cut.sh ${1}.8.gz    endscript}

Shell cut.sh

#!/bin/sh#usage:add this script to Logrotate's Prerotate/endscript#${1} is the absolute path to the log file#${1}.3.gz mea  ns which file to Bak and 3 are rotate ' s count add 1#e.g. #prerotate #/opt/shell_app/cut.sh ${1}.3.gz#endscriptset-xif [-F $];  Then filepath=${1} filedir=$ (DirName ${1}) filename=$ (basename ${1}) Else exit 0fic_date=$ (date +%y%m%d%h%m%s) y_date= ' date--date= ' 1 days ago ' +%y%m%d ' w_date= ' date--date= ' 3 days ago ' +%y%m%d ' function clean_and_bak_ Log () {if [[-D ${filedir}/bak]];then echo ' bak dir is exsited "Else mkdir-p ${filedir}/bak C Hmod a+w ${filedir}/bak fi #insert Current time-to-filename #${#filename}-3} means cut '. gz ' from filename #ex Ample cp/opt/shell_app/test.log.3.gz/opt/shell_app/bak/test.log.3.201703061814.gz cp-p ${filedir}/${filename} ${ filedir}/bak/${filename:0:${#filename}-3}.${c_date}.gz #rm-F ${filedir}/bak/*${w_date}*.gz Find ${filedir}/bak/-re Gextype Posix-exteNded-regex ' ^.*[0-9]{14,14}\.gz$ '-mtime +5-print0 | Xargs-0/bin/rm-f}

Note: If the log volume is large in one day, using the above strategy may create a pressure on disk space

Reference Links:
GNU Findutils

Linux logrotate deleted some day ago

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.