1

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

4
  • How are you currently doing backups and what size of data ?
    – user9517
    Jan 27, 2011 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, 2011 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, 2011 at 12:57
  • Take a look at my script: serverfault.com/questions/575163/… Feb 12, 2014 at 21:11

2 Answers 2

2

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 protected]

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.

1
  • 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, 2011 at 15:16
5

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.

1
  • 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, 2011 at 12:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .