deleting old files using crontab

后端 未结 3 583
难免孤独
难免孤独 2020-12-09 20:12

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-$(dat         


        
相关标签:
3条回答
  • 2020-12-09 20:46
    find /db_backups/ -mtime +30 -delete
    

    This command would delete DB backups older than 30 days.

    0 讨论(0)
  • 2020-12-09 20:50

    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.

    0 讨论(0)
  • 2020-12-09 21:00

    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 讨论(0)
提交回复
热议问题