Modern Caveman

Modern Caveman

All caveman projects - Text File Version of this page - Printable

detect-renamed for rsync

I'm using a Raspberry Pi as a fileserver for family photos.

I use rsync to synchronize my laptop to the raspberrypi and have a samba share to allow family to view the pictures.

The problem is when I re-organize my images into new directories and sync them. My usual command was:

rsync -av --delete pics/ pi@raspberry:~/samba/pics/

But when I only move files around to new directories or rename them, rsync will re-send any of the changed files.

There are two patches to rsync that attempt to detect renames and moves.

detect-renamed

detect-renamed-lax

These patches are available in the rsync-3.0.9.tar.gz and rsync-patches.3.0.9.tar.gz file available here.

Bugzilla discussion for Detect renamed files and handle by renaming instead of delete/re-send.

There is a defect in the above patch where ".. the partial-dir cannot be created because the directory for it does not yet exist. This is the case when a directory is renamed or a file is moved to a new directory.". This 3rd patch fixes the shortfall.

I used the above patches and now rsync detects moves and renames when I synchronize.

Download and unzip rsync-3.0.9.tar.gz and rsync-patches-3.0.9.tar.gz from here.

Download the improved detect-renamed patch and replace patches/detect-renamed.diff.

Note change of patch -p1 to patch -p0 for the adjusted patch.

  $ patch -p0 <patches/detect-renamed.diff 
  patching file compat.c
  Hunk #2 succeeded at 124 (offset -1 lines).
  patching file flist.c
  Hunk #1 succeeded at 60 (offset -1 lines).
  Hunk #2 succeeded at 121 (offset -1 lines).
  Hunk #3 succeeded at 290 (offset -1 lines).
  Hunk #4 succeeded at 2469 (offset -24 lines).
  patching file generator.c
  Hunk #1 succeeded at 78 (offset -1 lines).
  Hunk #2 succeeded at 97 (offset -1 lines).
  Hunk #3 succeeded at 105 (offset -1 lines).
  Hunk #4 succeeded at 116 (offset -1 lines).
  Hunk #5 succeeded at 125 (offset -1 lines).
  Hunk #6 succeeded at 150 (offset -1 lines).
  Hunk #7 succeeded at 291 (offset -1 lines).
  Hunk #8 succeeded at 348 (offset -1 lines).
  Hunk #9 succeeded at 369 (offset -1 lines).
  Hunk #10 succeeded at 411 (offset -1 lines).
  Hunk #11 succeeded at 577 (offset -1 lines).
  Hunk #12 succeeded at 602 (offset -1 lines).
  Hunk #13 succeeded at 627 (offset -1 lines).
  Hunk #14 succeeded at 647 (offset -1 lines).
  Hunk #15 succeeded at 659 (offset -1 lines).
  Hunk #16 succeeded at 704 (offset -1 lines).
  Hunk #17 succeeded at 1417 (offset -9 lines).
  Hunk #18 succeeded at 1707 (offset -9 lines).
  Hunk #19 succeeded at 1996 (offset -9 lines).
  Hunk #20 succeeded at 2412 (offset -9 lines).
  Hunk #21 succeeded at 2428 (offset -9 lines).
  Hunk #22 succeeded at 2470 (offset -9 lines).
  Hunk #23 succeeded at 2517 (offset -9 lines).
  patching file options.c
  Hunk #1 succeeded at 81 (offset -1 lines).
  Hunk #2 succeeded at 391 (offset -2 lines).
  Hunk #3 succeeded at 579 (offset -5 lines).
  Hunk #4 succeeded at 1604 (offset -5 lines).
  Hunk #5 succeeded at 1613 (offset -5 lines).
  Hunk #6 succeeded at 1976 (offset -7 lines).
  patching file rsync.yo
  Hunk #1 succeeded at 402 (offset -1 lines).
  Hunk #2 succeeded at 1591 (offset -7 lines).
  patching file syscall.c
  patching file util.c
  Hunk #1 succeeded at 1168 (offset -4 lines).
  Hunk #2 succeeded at 1179 (offset -4 lines).
  patching file proto.h
  patching file rsync.1
  Hunk #1 succeeded at 478 (offset -1 lines).
  Hunk #2 succeeded at 1821 (offset -8 lines).

  $ patch -p1 <patches/detect-renamed-lax.diff 
  patching file generator.c
  patching file options.c
  patching file rsync.yo
  patching file rsync.1

  ./configure
  make
  sudo checkinstall
  sudo dpkg -i ./rsync_3.0.9.1-1_i386.deb 

I perfomed the same actions and compiled rsync on my raspberrypi (took about 15 minutes).

I can now rsync via this command:

    rsync -av --detect-renamed --delete-delay pics/ pi@raspberry:~/samba/pics/

If you turn on very verbose debugging with -avv you can see that files get renamed:

found renamed: patspeak2/SAM_4092.JPG => patspeak/SAM_4092.JPG
found renamed: patspeak2/SAM_4091.SRW => patspeak/SAM_4091.SRW
found renamed: patspeak2/SAM_4091.JPG => patspeak/SAM_4091.JPG
found renamed: patspeak2/SAM_4090.SRW => patspeak/SAM_4090.SRW
found renamed: patspeak2/SAM_4090.JPG => patspeak/SAM_4090.JPG

I used checkinstall to create .deb files from the above compiles. You can download them direct if you don't want to compile yourself. Note, I increased the version number from 3.0.9 to 3.0.9.1.

Index of my other projects