使用 crontab 删除旧文件 [英] deleting old files using crontab

查看:25
本文介绍了使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆