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 use rsync to do backups of files and folder\

 rsync -avqz --stats --delete /media/server/ /media/Server2/

Now this deletes files while are not present on source and makes source exact copy of derstination

but my boss wants that i should delete the files only which are not present on source and are 1 week old something like

rsync -avqz --stats --delete(1 week old) /media/server/ /media/Server2/

Any ideas

share|improve this question
add comment

3 Answers 3

i would recommend to you and your boss to set up rsnapshot instead. it will give you snapshots as often and going back as far as you like.

share|improve this answer
    
+1 - I use a similar method (using rsync with a couple of scripts of my own based on the technique described in mikerubel.org/computers/rsync_snapshots) to maintain my backups and it works well. I keep weekly snapshots going back almost a year (and daily ones for a month) which take up surprisingly little space. I'd probably use rsnapshot but my scripts were started, some years ago, before that existed in a stable form. –  David Spillett Oct 19 '10 at 10:47
add comment

Rsync does not support this behavior out of the box. You might find another tool such as rsnapshot such as Jaylen suggested to be a good move.

If you really do want to do exactly as you describe, here is what you can do.

  • First, run your rsync WITHOUT a delete. This will just copy everything over from your live data to your backup.
  • Next run the rsync again with the delete, but this time in TEST mode (-n). This will generate a list of files to BE deleted based on what has been deleted in your live data but not yet in your backups. Save this output to a file with the date.
  • Now keep those list of things to delete, but only process them a week later. Keep a queue and only process the deletion suggestions that have been in the queue for at least a week.

Alternatively, use the output of the rsync --delete -n but instead of queuing, use some other check such as the last modified date in the backup to make sure you only delete things that have not otherwise been edited inside of a week. This is not quite the behavior you asked for but would be easier to program and might suffice.

share|improve this answer
add comment

An alternative tool is rdiff-backup: http://www.nongnu.org/rdiff-backup/, which keeps both a mirror and a configurable by date, incremental backup.

share|improve this answer
add comment

Your Answer

 
discard

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