Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm using for the first time rsync to create daily backups of my websites and I was wondering if I should overwrite the previous copy or should I create multiple copies and overwrite only the oldest one ? (I might not have enough space for that, though).

I actually have also this question. Let's suppose most of files are accidentally erases.. does rsync delete all these files from the backup space because they don't exist anymore ? How does exactly work in this case ?

thanks

share|improve this question

3 Answers 3

up vote 2 down vote accepted

You definitely need to have a backup strategy that includes keeping a number of older backups. If you keep only one mirror of your live system, then, should the files on your live system become corrupted, your backup process will dutifully mirror the corrupted files, and your backup will become useless.

A good strategy is to keep a number of timestamped (or at least datestamped) backups available, so that if you find that files in your latest backups are copies of corrupted files, you can refer back to older versions that are known to be good.

rsnapshot, mentioned by Alastair, is a very nice tool, based on rsync, that creates and keeps a configurable number of versioned mirrors (or "snapshots") of your sources on a configurable schedule. You can tell rsnapshot how many hourly, daily, weekly, and/or monthly snapshots to keep, and it will automatically take care of deleting the oldest snapshots when your chosen maximum number of snapshots to retain is reached. As also mentioned, rsnapshot is quite efficient with disk space, since it uses hard links to represent files that don't change between snapshots.

share|improve this answer

If you are on a system that supports hard links (e.g. Linux, Unix, OSX etc), something like rsnapshot might be a good solution. This automates daily, weekly etc. snapshots and rotation. Disk space used is minimal over time because file system hard links are used.

rsnapshot http://rsnapshot.org/

share|improve this answer
    
That's cool! It definitely sounds like it might help the OP. +1 from me! –  MadHatter Jan 6 '11 at 16:09

Unless you're doing something fairly odd, you won't overwrite in the traditional sense. rsync is designed to bring a file system tree on a remote server into sync with a file system tree locally (or vice-versa). The first day you run it, it'll take a while and copy the whole tree; the following day, you'll copy only the files that have changed.

If you want historical information, but are short of space, then instead of keeping multiple copies of the tree, you may find it more satisfactory to run a cron job that tars up the directory on the remote server, compressing as hard as it can, and keep as many of those tarfiles as you can afford.

As derfk has noted, you get to choose whether rsync (eg) deletes files on the remote side that have vanished locally, as well as much other behaviour - but it's your job to catch it before it syncs the tree, if someone has changed all your local files to say "I HATE PIE".

That's one of the reasons why I don't think of rsync as a proper backup solution. But if you have only another server to do the backups do, and you don't have much space on that server, then rsync + aggressive tar is probably about as good as you can do without getting into funky union FS tricks, and it's definitely better than no backups at all.

share|improve this answer
    
@MadHatter Let's suppose most of files are accidentally erases.. does rsync delete all these files from the backup space because they don't exist anymore ? How does exactly work in this case ? –  Patrick Jan 6 '11 at 16:02
    
By default rsync will not erase files in the destination, that's what --delete is for. But if a hacker breaks in and changes all the files to say "I like pie" then unless you catch it and fix it before rsync runs, your backup will read "I like pie" too. –  DerfK Jan 6 '11 at 16:05
    
@DerfK So, let's suppose the content is almost completely replaced everyday, my backup will become bigger and bigger because the old content is still there ? –  Patrick Jan 6 '11 at 16:11
1  
If you configure it to do that, yes, it will. If you don't, then it won't. You can either have protection from deleted files at the cost of having to manually clean them up, or you can have automatic cleanup of deleted files at the cost of losing the protection - but not both. Unless you look at rsnapshot, as another poster has suggested. If you can use that, it really does look like the best of all worlds. If that won't do you, and you don't like the choice in rsync, then you'll need to find budget for a better backup solution. –  MadHatter Jan 6 '11 at 16:18
    
@MadHatter Cool thanks, I will give a look at rsnapshot. Just one last thing, what's the parameter to keep / delete previous versions and which is the default behavior ? –  Patrick Jan 6 '11 at 16:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.