Dirvish, Part 2
In my earlier post on dirvish I said I’d have to beat it to do the kind of expire rules I wanted… well I’ve finally found time to do that.
It’s a pretty simple approach, I’ve used the cron script to touch a dotfile if it’s the start of the week/month, and if that file exists then it determines the expire time, which is just passed as an argument to dirvish
This way, the first backup of the month should always be kept for a year, and the first of the week for a month, no matter when they occur.
#!/bin/bash
#
date=`date +%d`
day=`date +%a`
#
if [ "$date" -eq 1 ]; then
touch /home/backup/littlebrick/.monthly
fi
#
if [ $day == "Sun" ]; then
touch /home/backup/littlebrick/.weekly
fi
#
if [ -f /home/backup/littlebrick/.monthly ]; then
dirvish --vault littlebrick --expire 1year --image-time 00:00
elif [ -f /home/backup/littlebrick/.weekly ]; then
dirvish --vault littlebrick --expire 1month --image-time 00:00
else
dirvish --vault littlebrick --image-time 00:00
fi
#
dirvish-expire
With that done, all that’s left to do is to remove the dotfiles following a successful backup. I used the post-server options for this.
#/etc/dirvish/master.conf
...
post-server: ; /backup/dirvish/post_backup.sh $DIRVISH_DEST
...
And, this is the post_backup script
#!/bin/bash
#
# This script runs after backups, and if the backup was
# successful clears out the month/week flags
#
#$2 is the DIRVISH_DEST
cd $2
cd ..
#
#we're now in /home/backup/littlebrick/YYYYMMDD/
#
success=`grep -c "Status: success" summary`
#
if [ "$success" -gt 0 ]; then
if [ -f /home/backup/littlebrick/.monthly ]; then
rm /home/backup/littlebrick/.monthly
if [ -f /home/backup/littlebrick/.weekly ]; then
rm /home/backup/littlebrick/.monthly
fi
fi
[…] morning (or whenever I get a second to look over it) I’ll look into hooking in Andrew’s expiration script, it makes more sense then using dirvish’s regular expiration mechanisms for a […]
June 28th, 2010 at 12:17 am