LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Removing obsolete backup files and containing directory (https://www.linuxquestions.org/questions/linux-newbie-8/removing-obsolete-backup-files-and-containing-directory-714821/)

franjo124 03-27-2009 06:46 AM

Removing obsolete backup files and containing directory
 
Hi, This is my first post in LQ

I'm an Oracle DBA. My database writes backup files to ../Backup area. After writing those file to tape i would like to remove them from disk. That would be simple for me. But I want to keep last five (5) sets of files on disk for faster restore (please All mighty never force me to need and use it).
I need a script that would do the chore for me.
Directory structure is something like this
../Backup/db1/before_today/20090310
../Backup/db1/before_today/20090311
../Backup/db1/before_today/20090312
../Backup/db2/before_today/20090310
../Backup/db2/before_today/20090311
../Backup/db2/before_today/20090312

I want to delete (rm -r) directory ../20090312 for db1 and db2 every day at 7:00

I would appreciate help from linux expert

Regards Franjo
:)

openSauce 03-27-2009 12:13 PM

It looks like you want

Code:

rm -r /path/db{1,2}/before_today/$(date --date='3 days ago' +%Y%M%d)
Be sure to test it with
Code:

echo rm -r /path/db{1,2}/before_today/$(date --date='3 days ago' +%Y%M%d)
to make sure it's doing the right thing.

Put the above command in your crontab - see man crontab for details.

franjo124 03-30-2009 07:05 AM

Thanks, I just needed what I got.
I applied solution, it works and is small and beautiful.

Regards
Franjo


All times are GMT -5. The time now is 03:49 PM.