Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mirror rsnapshot backup directory

Tags:

ssh

backup

rsync

I would like to mirror a backup directory used by rsnapshot to a second location for more security. Ideally the solution would use rsync with ssh. What arguments do I need to provide to rsync to preserve the hardlinks (created by rsnapshot) and symlinks, to delete files, copy recursively, to delete files in the target, etc? The files are all on ext3 file systems. Furthermore what can I do to avoid the possibility that if the source is corrupted the defects are rsynced to the mirror?

like image 926
highsciguy Avatar asked May 21 '12 19:05

highsciguy


2 Answers

To prevent the copy of corrupt data you could keep a weekly backup and hope that you would notice the corruption at the source before you lost all of your backups. The best way would be to use -c and then it will compare check sums of both source and destination to determine whether to copy the file. The only down side is that it must read the whole file making the backup a slower process.

#!/bin/sh
# Create a Backup of Today
# Definitions
sevendaysago=$(date --date='6 days ago' +%Y-%m-%d-%A)
# Delete backups from 7 days ago
rm -rf /storage/backups/$sevendaysago
mkdir -p /storage/backups/`date +\%Y-\%m-\%d`-`date +\%A`/$host/$username

rsync -aHvz /storage/`date --date=yesterday +\%Y-\%m-\%d`-`date --date=yesterday +\%A`/$host/$user/ /storage/`date +\%Y-\%m-\%d`-`date +\%A`/$host/$user/

rsync -acHvz -e ssh --delete --exclude='logs' [email protected]:/home/tim/ /storage/`date +\%Y-\%m-\%d`-`date +\%A`/$host/$user/
like image 41
Paperghost Avatar answered Oct 28 '22 00:10

Paperghost


I think the options to do what you want are largely documented in the rsync man page. In particular, the -H option (--hard-links) enables hard-link detection, and --delete will cause rsync to delete things on the destination that do not exist on the source. So maybe something like:

rsync -aH --delete /path/to/src/ /path/to/destination

Furthermore what can I do to avoid the possibility that if the source is corrupted the defects are rsynced to the mirror?

Well, that's tricky. How do you detect corruption? I think the only real solution is to stagger the backup of your backup (that is, perform you actual backups to your primary destination, and then rsync that to your secondary destination immediately prior to your next backup run). This way if you detect a problem you have until the next backup run to bring things back.

A different solution would be to have rsnapshot back up to multiple destinations, so that you're actually generating backups from your original source in two distinct locations. This way if one becomes damaged the second should be unaffected.

like image 97
larsks Avatar answered Oct 28 '22 01:10

larsks