Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

At my company we create daily backups (full, not incremental) of our various stuff. We'd like to rotate them in the following way:

  • keep daily backups for the past week
  • keep only weekly backups for the past month (or 3 months or so)
  • keep only monthly backups for the last year

So basically, recent backups should be fine-grained, not so recent - more coarse grained.

And we're lazy :) Can this be done with logrotate? Or some other tool?

Regards,

Mike

share|improve this question
    
How are you currently doing backups and what size of data ? –  Iain Jan 27 '11 at 11:31
    
What Iain said. If you're already doing these backups to local online storage (HDD) then rotating the backup files with logrotate should be pretty easy. If the backups will be going to some other medium, then it's probably not such a good tool. –  MadHatter Jan 27 '11 at 11:59
    
You have to be careful in situations where the rotate will start when the backup is still running. I just replaced a backup scenario where backups were rsync'ed to a machine, which were then rotated later in the day. This, of course, is very prone to faults in case it starts rotating while the backup is still running (because of some error like slow network), or vice versa. I replaced this with rdiff-backup and my life is a lot easier now. –  Halfgaar Jan 27 '11 at 12:57
    
Take a look at my script: serverfault.com/questions/575163/… –  Florin Andrei Feb 12 at 21:11
add comment

2 Answers

up vote 2 down vote accepted

You can schedule one or more scripts like the one below with cron.

#!/bin/bash

BULOG=/srv/backup/savelog
BULST="/etc /srv/www /var/lib/named"
EMAIL=me@example.com

today=`date +%d%m%y`
deldate=`date +%d%m%y --date '7 day ago'`
echo "Backup started: "`date`> $BULOG
echo "Backup "`date`         >>/srv/backup/ErrorLog

cd /srv/backup
rm -f backup$deldate.tar.gz

tar czf /srv/backup/backup$today.tar.gz $BULST 2>>/srv/backup/ErrorLog
if [ $? -eq 0 ];then
        echo "Backup $BULST success" >> $BULOG
else
        echo "Backup $BULST NOT processed" >> $BULOG
fi

echo "-------" >>/srv/backup/ErrorLog

echo "Backup finished: " `date` >> $BULOG

cat $BULOG | mail -s MyBacukp_$today $EMAIL

This needs just a little bit of tweaking to server your requests.

share|improve this answer
    
Yeah, so I spent so much time looking for a tool that would do that for me that it turned out it will be faster to just write my own one. –  Jasiu Jan 29 '11 at 15:16
add comment

I highly recommend rdiff-backup. It's as easy as set it & forget it (but don't really forget it). Another alternative would be rsnapshot.

share|improve this answer
    
I would second rdiff-backup. We use it to, a lot, and it negates the need for rotation, and you can just keep several months of daily backups without worrying much about space. –  Halfgaar Jan 27 '11 at 12:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.