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

I have to backup a set of userdata with rsync. There is just one little thing I cant figure out how to do. When a user deletes a file it is kept on the server. This is fine since it might have been deleted by mistake, but it would be nice if it did not stay there forever.

So how do I make rsync delete files on DEST when they have not been precent on SRC for a certain amount of time (say, 7 days)

I know that I could just write a script that manually uses rsync on each file in the folder and then determines if the file on DEST should be deleted, but it would be kind of dumb to do this just to learn later on that rsync has this feature already. I cant find it though.

Many thanks for you time

share|improve this question

4 Answers 4

up vote 3 down vote accepted

Rsync won't do this on its own. Something like rsnapshot will let you maintain multiple generations of rsync-based backups (hourly, daily, monthly, etc) such that you can retrieve an accidently-deleted file. By using hard links, rsnapshot lets you keep a number of snapshots laying around without using a lot more space than the "cost" of a full backup.

There are other solutions out there that do the same thing-- rsnapshot just happens to be one I have personal experience with. (I highly recommend using the "sync_first" option if you do decide to use it...)

share|improve this answer
    
Many thanks, will look into it, seems to be just the thing I need. –  Mathias Nielsen Dec 5 '09 at 1:43

Have you done a "man rsync"? The --delete switch does what you want, but use it carefully.

If you really want to have that seven-day delay, consider using rsnapshot. It uses hard-links to conserve space for all identical files.

share|improve this answer

Look into rsnapshot. It uses rsync to do the transfer but on top of that it manages point in time snapshots using hardlinks. It will let you determine how often and how many snapshots to hold onto as well.

share|improve this answer

Once a week, I use the --delete option of rsync

RSYNC_OPT="--stats --delete --delete-excluded -avvzpogte  ssh --exclude-from /root/etc/exclude.txt"

Rest of the time, I do incremental backup

RSYNC_OPT="--stats -avvzpogte ssh --exclude-from /root/etc/exclude.txt"

Both scripts are called by cron

share|improve this answer
    
I actually considered this, but just wanted to know if there was a more "elegant" solution. But thanks none the less :) –  Mathias Nielsen Dec 5 '09 at 1:42

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.