Capture directory & contents, Rotate for only the last three days

1

Our current backup approach requires us to capture a Tomcat directory, and all it's contents. The rationale is the backup makes redeployment easier in the event of a disaster.

It was rotating based on the day number, so we'd have a rolling week of backups. Problem is that these are eating too much diskspace, and we really don't need that much history.

I looked at logrotate, but it seems to be set for specific log files. Is there some way of making logrotate capture a directory & contents, providing three rolling days history? Or is there a better alternative?

OMG Ponies

Posted 2010-09-21T18:42:08.463

Reputation: 163

+1 for being the SQL guru :) Glad to see you on SU! – JNK – 2010-09-21T18:55:31.570

sorry about the typo in my command, fixed. – Rich Homolka – 2010-09-21T21:25:30.623

Answers

1

I've had similar requirements. My solution was backup a daily backup to a dir, then prune based on date.

find /path/to/backups/ -name 'tomcat*.tar.bz2' -atime +3 -mtime +3 -exec rm {} \;
DATE=$(date '+%Y-%m-%d')
tar -C /path/to/tomcat/root -cjvf /path/to/backups/tomcat-${DATE}.tar.bz2 .

Obviously, put this in cron. Run once daily.

Rich Homolka

Posted 2010-09-21T18:42:08.463

Reputation: 27 121

+1: I'm getting a "tar: Cowardly refusing to create an empty archive" – OMG Ponies – 2010-09-21T20:06:49.723

@OMG: you must specify the files you want to backup at the end of the tar command line.. – lorenzog – 2010-09-21T20:26:27.687

@lorenzog: I want the contents of the entire directory. – OMG Ponies – 2010-09-21T20:40:05.517

@OMG then just put . (the current directory) or the name of the directory if you're one level up. – lorenzog – 2010-09-22T07:13:08.590

0

What about using the -u option of tar (updates only newer files), and compressing the file every week?

Also think about this: is really disk space such a big issue? Given how little hard drives cost lately, is an hour of your time worth doing this compared to the cost of buying a TB of space and forgetting about it?

lorenzog

Posted 2010-09-21T18:42:08.463

Reputation: 1 962

It's a co-located server, this is a VM. I can't throw in the drive, has to go through channels. The reality is that after a day, the data is out of sync with the database anyway. – OMG Ponies – 2010-09-21T20:39:37.137