使用crontab删除旧文件 [英] deleting old files using crontab
本文介绍了使用crontab删除旧文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下crontab记录来每天备份我的数据库:
I use the following crontab record in order to daily 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
我想添加另一个crontab记录,该记录将删除早于一个月的数据库转储.
I want to add another crontab record that will delete the DB dumps that are older then one month.
有什么想法吗?
推荐答案
只需创建另一个cron:
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
它将查找所有早于30天的备份并将其删除.
It will find all backups older than 30 days and delete them.
这篇关于使用crontab删除旧文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文