I'm using several of Amazon's EC2 linux instances for a Deploy & Live MongoDB environment, and have been working on my backup strategy for a few days.
I've narrowed it down to using LVM snapshots to obtain a consistent data volume which I rsync to my backup server.
I do this on an hourly basis from the backup server itself, using the following script:
Code:
#!/bin/bash
# ... some config stuff before this ...
cd /backup
#Rotate all existing backups back 1 hour, and entirely delete the oldest one.
rm -fr 24h
for i in {23..1}
do
mv ${i}h $(($i + 1))h
done
#Make a copy of the current backup into the 1h bucket, using hard links to avoid duplicating data.
cp -la current 1h
# Rsync
echo "Created on `date`" | tee -a /backup/current/DATETIME
rsync -e "ssh -i ***.pem" --verbose --recursive --times --perms --links --delete ***@***:~/backup/ /backup/current
Then, once a day at midnight, I run the following script:
Code:
#!/bin/bash
mv 6d 7d
mv 5d 6d
mv 4d 5d
mv 3d 4d
mv 2d 3d
mv 1d 2d
mv 24h 1d
rm -fr 24h/*
The idea being to have daily backups for a weekly as well as hourly backups for a day.
Finally, I run the following script once a week on a Saturday morning:
Code:
#!/bin/bash
cd /backup
mv current weekly
rm -fr current/*
The idea being to have a weekly backup, and by deleting my /backup/current folder to force rsync to do a completely fresh copy once a week to ensure consistency.
Any input on this backup strategy?
Any input on my scripts? Are they doing what I expect them to do?
Just looking for general feedback....
Thanks!