Tuesday, August 4, 2009

Script for deleting files older than X days


A much covered web topic for linux admin scripts is finding and deleting files that are older than X days. Google-foo returns about 5 million hits on the topic so I thought I'd join the Army of the Redundant and post my own. There are several different methods and discussions upon each method, pros and cons, etc. My purpose for this is to cover deleting old files that I am keeping in a mini-disaster recovery scenario where two Debian rsync boxes are each connected to a respective EMC AX150i SAN. The source SAN gets SQL dumps sent to it daily and these are replicated to the DR site. After a couple of weeks this will amount to nearly a terabyte of data that is really not neccesary and I would like to auto-prune these files to keep only 10 days available. Here is what I've done:

find /path/to/prune/directory -type f -mtime +10 -exec rm {} \;

No comments:

Post a Comment