Handling renamed files or directories in rsync
You may want to look at -y | --fuzzy
rsync option. Other than that, rsync has no way of tracking renames, so you'll end up transferring renamed file.
From rsync manpage:
-y, --fuzzy
This option tells rsync that it should look for a basis file for
any destination file that is missing. The current algorithm
looks in the same directory as the destination file for either a
file that has an identical size and modified-time, or a simi-
larly-named file. If found, rsync uses the fuzzy basis file to
try to speed up the transfer.
You can handle moved and renamed files with rsync
if the filesystems on the source and target directory have support for hard links. The idea is to let rsync reconstruct hard links before real transfer. You can find a brilliant explanation here.
We ended up with a simple solution that create an hidden tree of hard links inside the source/target directory, the basic script could be like this:
# Name of hidden directory
Shadow=".rsync_shadow"
# do real sync
rsync -ahHv --stats --no-inc-recursive --delete --delete-after "$Source"/ "$Target"
# update/create hidden dir of hard links in source
rsync -a --delete --link-dest="$Source" --exclude="/$Shadow" "$Source"/ "$Source/$Shadow"
# update/create hidden dir of hard links in target
rsync -a --delete --link-dest="$Target" --exclude="/$Shadow" "$Target"/ "$Target/$Shadow"
I have an example script on GitHub. But I advise you to do a large amount of testing before use this method on production.
While this is an old post, these were the first discussion I found when searching, so I thought I'd share a solution. Since about 2010, there's been patches to rsync that detect renames. One patch that worked for me is here.
So, if you can patch your rsync in your environment, you can use rsync --detect-renamed
or --detect-renamed-lax
.