1

Minimal working example

  1. Let's suppose we have two directories a and b
  2. File 1.txt exists in a and it contains foo
  3. We copy a/1.txt to b using rsync
  4. File a/1.txt gets modified and now it contains bar
  5. In order to have the updated version of a/1.txt in b, we execute rsync again

At this point a/1.txt contains bar, while b/1.txt contains foo.

The scenario described above can be reproduced by executing the following commands.

mkdir a b
echo foo > a/1.txt
rsync -a a/ b
echo 'After first run'
cat a/1.txt
cat b/1.txt

echo bar > a/1.txt
rsync -a a/1.txt b/
echo 'After second run'
cat a/1.txt
cat b/1.txt
After first run
foo
foo
After second run
bar
foo

As you could see above, the content of b/1.txt was not updated with the content of a/1.txt in the second run.

The question

How to make rsync update the content of files that have been copied in a previous run?

System information

$ rsync --version
rsync  version 3.2.7  protocol version 31
Copyright (C) 1996-2022 by Andrew Tridgell, Wayne Davison, and others.
Web site: https://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, symlinks, symtimes, hardlinks, hardlink-specials,
    hardlink-symlinks, IPv6, atimes, batchfiles, inplace, append, ACLs,
    xattrs, optional secluded-args, iconv, prealloc, stop-at, no crtimes
Optimizations:
    SIMD-roll, no asm-roll, openssl-crypto, no asm-MD5
Checksum list:
    xxh128 xxh3 xxh64 (xxhash) md5 md4 sha1 none
Compress list:
    zstd lz4 zlibx zlib none
Daemon auth list:
    sha512 sha256 sha1 md5 md4

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
1
  • I can't reproduce this either on NTFS with Cygwin or native ext4 on Linux (Debian). For me, rsync works as expected and gives foo/foo then bar/bar. What filesystem are you using? Commented Sep 12, 2023 at 10:21

1 Answer 1

0

rsync normally compares the sizes & modification times of files in the source and target, and if they match it assumes the files are the same. In this example, the files have the same size (4 bytes) and b/1.txt was modified so closely after a/1.txt that the timestamps came out the same.

If you add a sleep 1 command between the two sections of the script, it should work (unless you're on a FAT volume -- it only has 2-second resolution in timestamps, so you'll have to delay 2 seconds to get consistent results).

Alternately, you could add the -I flag to rsync to make it ignore timestamps, and actually veryify that the files' contents match (or at least their checksums).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .