Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 4 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


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.