Is there a way to auto-rename an existing file on the receiver? For example: if filename already exists, it auto-rename filename to something like filename_001, filename_002 and so on....

So far all I have is this:

$ rsync -rh --progress --stats --exclude '.thumb' \
    --update --perms /origin /destination

By the way, I know rsync has --ignore-existing to "skip updating files that exist on receiver", but I guess what I need would be something like --rename-existing.


If you are looking to keep incremental versions of a data set (without using version control such as the git suggestion which would be the other alternate way to do this) consider using rsnap instead of rsync.

It will allow you to take snapshots of a folder or set of files so that you could restore what the whole thing as it was at any given point in time. Instead of saving multiple copies of whole files it should only save the differences between them, saving you the space of having all those duplicates around.

Since it uses rsync to copy the files behind the scenes, you can append rsync options to the end of the command. For example in your situation to keep ten backup copies you could do something like this:

$ rsnap 10 /origin /destination -- --progress --stats \
    --exclude '.thumb' --update --perms
  • This is far beyond my expectations... I know I'll have to dive deep into this but, if you have any experience on this, would you give me an example of how to use this tool to achieve my question? Thanks a lot!
    – Roger
    Jul 1 '11 at 15:18
  • Using just rsync I can only think of how to keep ONE set of backup files not a whole series like you are suggesting. That led me to think of this which is a whole different kind of solution. It setups up folders and keeps however many sets of data you want. You use it much like rsync with a source folder and a target location for the backups to end up, but you also specify how many increments of things to keep.
    – Caleb
    Jul 1 '11 at 15:28
  • I'm sorry my post had the wrong link, try the new link for the homepage that has usage and example and explanation. I also tried to guess what a command might look like for you.
    – Caleb
    Jul 1 '11 at 15:31

There are the --backup and --suffix options (at least in v3.0.8) but they don't quite accomplish what you want because --suffix is fixed and not auto-incrementing (cp has a nice auto-incrementing backup suffix option). The best I could come up with was using a datetimestamp as the suffix like so:

SUFFIX=`date '+%Y-%m-%d-%H:%M:%S'`
rsync -rh --progress --stats --exclude '.thumb' \
  --backup --suffix="$SUFFIX" \
  --update --perms /origin /destination
  • Sound great. I'll give a try and post the results.
    – Roger
    Jul 1 '11 at 19:05

I would also look into using git which is an open-source version control software. There's a bit of a learning curve to it, but it sounds like it would be appropriate for what you're trying to do. It also uses ssh, ftp and some other transfer protocols. A good tool for mirroring repositories, tracking changes, etc. It also has great documentation and a very active irc channel (webchat.freenode.net #git)if you get stuck.

Good luck!

  • Just a stupid question. Unlike svn, git doesn't works locally, does it?
    – Roger
    Jul 1 '11 at 19:06
  • @roger - not exactly sure what you're asking, but I use git in my local development environment to keep track of stuff. Jul 1 '11 at 20:54
  • @Roger I think you got that backwards. Subversion requires everything to talk to a single central server. Git is distributed so every copy can work independently including interacting with the repository, doing commits etc without having network access to talk to other repositories. Later they can be synced/merged.
    – Caleb
    Jul 1 '11 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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