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

Jasiu
  • 113
  • 1
  • 4
  • How are you currently doing backups and what size of data ? – user9517 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: http://serverfault.com/questions/575163/how-to-keep-daily-backups-for-a-week-weekly-for-a-month-monthly-for-a-year-a – Florin Andrei Feb 12 '14 at 21:11

2 Answers2

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.

churnd
  • 4,077
  • 5
  • 34
  • 42
  • 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
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=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.

pincoded
  • 369
  • 2
  • 9
  • 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