dealing with renamed files

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


Hello,

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:
#!/bin/sh
TO_DO='
- Secure shell script
  - Find out how to secure shell scripts
- Do filename escaping beforehand
- Provide Tar-like "-C" command line option
'
tmpfile=md5_rename_tmp
find -type f -print0 | xargs -0 md5sum > "$tmpfile"
for file in "$@" ; do
        old_IFS="$IFS"
        IFS='
'
        for new_line in `cat "$file"` ; do
                IFS="$old_IFS"
                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"
                fi
        done
done

-- 
Tom Goulet, tomg at em.ca, D8BAD3BC, http://web.em.ca/~tomg/contact.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.samba.org/archive/rsync/attachments/20030626/f1d5752a/attachment.bin


More information about the rsync mailing list