开发者

deleting old files using crontab

开发者 https://www.devze.com 2023-02-18 12:34 出处:网络
I use the following crontab record in order to dail开发者_StackOverflow中文版y backup my DB: 0 2 * * * MYSQL_PWD=password mysqldump -u user db_name > $HOME/db_backups/db_name-$(date +\\%Y-\\%m-\\%

I use the following crontab record in order to dail开发者_StackOverflow中文版y backup my DB:

0 2 * * * MYSQL_PWD=password mysqldump -u user db_name > $HOME/db_backups/db_name-$(date +\%Y-\%m-\%d-\%H-\%M).sql 2>> $HOME/db_backups/cron.log

I want to add another crontab record that will delete the DB dumps that are older then one month.

Any thoughts?


find /db_backups/ -mtime +30 -delete

This command would delete DB backups older than 30 days.


Just create another cron:

0 3 * * * find $HOME/db_backups -name "db_name*.sql" -mtime +30 -exec rm {} \; >> $HOME/db_backups/purge.log 2>&1

It will find all backups older than 30 days and delete them.


There is a tool called tmpreaper that securely deletes files matching certain criteria, such as an access or modification date n days in the past.

0

精彩评论

暂无评论...
验证码 换一张
取 消