Link to home
Start Free TrialLog in
Avatar of rleyba828
rleyba828Flag for Australia

asked on

Need a PERL script to delete backup files dated exactly 7 days ago.

Hi Team,

   Just need help on a cronjob task i need to do for housekeeping my Centos file system.   I have an application that backups an app database twice a day and these backup files have started accummulating in our /root/backup directory like so.....

MYAPP.db.backup.14-May-2013-12-15AM.sql
MYAPP.db.backup.14-May-2013-12-35AM.sql
MYAPP.db.backup.15-May-2013-12-15AM.sql
MYAPP.db.backup.15-May-2013-12-35AM.sql
MYAPP.db.backup.16-May-2013-12-15AM.sql
MYAPP.db.backup.16-May-2013-12-53AM.sql
MYAPP.db.backup.17-May-2013-12-15AM.sql
MYAPP.db.backup.17-May-2013-12-35AM.sql
MYAPP.db.backup.18-May-2013-12-35AM.sq
MYAPP.db.backup.18-May-2013-12-35AM.sq

Open in new window


I just need help with a PERL script that I can include in a cron job so that it will automatically delete files with file names that have the date of exactly 7 days ago.   In the case of the example above, if today were 24 May 2013, I want the cron job to delete only files MYAPP.db.backup.17-May-2013*   but leave the other dates untouched.

Any help would be appreciated.
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rleyba828

ASKER

Hi woolmilkporc,

   Thanks for the solution.  It worked excellently and is the exact thing I was looking for.  My sysadmin just preferred to standardize on perl but bash will do in this case.

Hi rsaylor, your solution was helpful, but in our case, the date was part of the filename, so we had to work within those constraints, but thanks as well.