dealing with renamed files

Tom Goulet tomg at
Fri Jun 27 02:18:14 EST 2003


If I rename a directory full of files, or a bunch of files, and I use
Rsync to update the directory tree, Rsync will upload all these files
again and delete the old ones.  This is suboptimal since all the data is
already there.

Rsync should be able to check for renamed files by scanning for files
with the same MD5 hashes, checksums, or delta signatures (is that what
you called them?).  Rsync could then rename the files remotely and then
do the normal update.

Here is a shellscript implementation:
- Secure shell script
  - Find out how to secure shell scripts
- Do filename escaping beforehand
- Provide Tar-like "-C" command line option
find -type f -print0 | xargs -0 md5sum > "$tmpfile"
for file in "$@" ; do
        for new_line in `cat "$file"` ; do
                new_md5=`echo "$new_line" | cut -d' ' -f1`
                new_pathname=`echo "$new_line" | cut -d' ' -f3-`
                old_pathname=`grep -m1 "$new_md5" "$tmpfile" | \
                        cut -d' ' -f3-`
                if [ "$old_pathname" ] ; then
                        mkdir -p `dirname "$new_pathname"`
                        mv "$old_pathname" "$new_pathname"

Tom Goulet, tomg at, D8BAD3BC,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url :

More information about the rsync mailing list