RsyncProject / rsync

An open source utility that provides fast incremental file transfer. It also has useful features for backup and restore operations among many other use cases.
https://rsync.samba.org
Other
2.75k stars 328 forks source link

Timestamp not preserved when rsyncing to SMB share on macOS #479

Open iceboundflame opened 1 year ago

iceboundflame commented 1 year ago

I am using rsync 3.2.7, installed via Homebrew on macOS Ventura 13.2.1. Apple Silicon, if it matters (Apple M1 Pro).

rsync --archive does not set the timestamp correctly when the destination is a mounted SMB share.

When syncing to a local filesystem directory, the timestamp is copied correctly.

Also when I switch to the builtin macOS version 2.6.9, it does work correctly as well.

Repro steps

Create test file:

$ echo helloworld > test/asdf
$ touch -t 202301010000 test/asdf
$ ls -l test
total 8
-rw-r--r--  1 dliu  staff  11 Jan  1 00:00 asdf

Sync to mount, timestamp not preserved:

$ /opt/homebrew/Cellar/rsync/3.2.7_1/bin/rsync -avr --itemize-changes test /Volumes/home/
sending incremental file list
.d...p...... test/
>f..tp...... test/asdf

sent 145 bytes  received 39 bytes  368.00 bytes/sec
total size is 11  speedup is 0.06

$ ls -l /Volumes/home/test
total 8
-rwx------  1 dliu  staff  11 May  7 16:47 asdf

Broken version details:

$ /opt/homebrew/Cellar/rsync/3.2.7_1/bin/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, no prealloc, stop-at, crtimes,
    file-flags
Optimizations:
    no 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.
botsmack commented 1 year ago

I think I'm running into this issue as well. I noticed it while syncing data from my iMac using rsync 3.2.7 (installed via Homebrew) on macOS Ventura 13.2.1. I am mounting an smb share and running the following command:

rsync -rltvzhP ~/folder/data/ /Volumes/tank/differentfolder/olddata

Running the above command successively will re-sync everything I've just transferred. The modified date is not being being honored or carried over, but rather being updated to the datetime that the current rsync command is carried out. The details of my SMB connection as reported from my Mac to an Unraid share:

SMB_NEGOTIATE                 SMBV_NEG_SMB1_ENABLED
SMB_NEGOTIATE                 SMBV_NEG_SMB2_ENABLED
SMB_NEGOTIATE                 SMBV_NEG_SMB3_ENABLED
SMB_VERSION                   SMB_3.1.1
SMB_ENCRYPT_ALGORITHMS        AES_128_CCM_ENABLED
SMB_ENCRYPT_ALGORITHMS        AES_128_GCM_ENABLED
SMB_ENCRYPT_ALGORITHMS        AES_256_CCM_ENABLED
SMB_ENCRYPT_ALGORITHMS        AES_256_GCM_ENABLED
SMB_CURR_ENCRYPT_ALGORITHM    AES-128-GCM
SMB_SHARE_TYPE                DISK
SIGNING_SUPPORTED             TRUE
EXTENDED_SECURITY_SUPPORTED   TRUE
UNIX_SUPPORT                  TRUE
LARGE_FILE_SUPPORTED          TRUE
OS_X_SERVER                   TRUE
DFS_SUPPORTED                 TRUE
FILE_LEASING_SUPPORTED        TRUE
MULTI_CREDIT_SUPPORTED        TRUE
ENCRYPTION_REQUIRED           TRUE

Edited to add new information. If I run rsync with -vvv it looks like it is setting atime to the current datetime. It seems to me that both modtime and atime should be the same as the original file, yes?

15:31 richard:~ % rsync -avr --itemize-changes -vvv ~/test /Volumes/tank/media/
cmd=<NULL> machine=<NULL> user=<NULL> path=/Volumes/tank/media/
cmd[0]=. cmd[1]=/Volumes/tank/media/
msg checking charset: UTF-8
(Server) Protocol versions: remote=31, negotiated=31
(Client) Protocol versions: remote=31, negotiated=31
sending incremental file list
[sender] make_file(test,*,0)
[sender] flist start=1, used=1, low=0, high=0
[sender] i=1 /Users/richard test/ mode=040755 len=96 uid=501 gid=20 flags=1005
send_file_list done
[sender] pushing local filters for /Users/richard/test/
[sender] make_file(test/asdf,*,2)
[sender] flist start=3, used=1, low=0, high=0
[sender] i=3 /Users/richard test/asdf mode=0100644 len=11 uid=501 gid=20 flags=0
[sender] flist_eof=1
file list sent
send_files starting
server_recv(2) starting pid=70707
uid 501(richard) maps to 501
process has 16 gids:  20 501 12 61 79 80 81 98 399 701 33 100 204 250 395 398
gid 20(staff) maps to 20
recv_file_name(test)
received 1 names
[Receiver] flist start=1, used=1, low=0, high=0
[Receiver] i=1 1 test/ mode=040755 len=96 gid=20 flags=1005
recv_file_list done
[Receiver] receiving flist for dir 0
recv_file_name(test/asdf)
received 1 names
[Receiver] flist start=3, used=1, low=0, high=0
[Receiver] i=3 2 test/asdf mode=0100644 len=11 gid=20 flags=0
recv_file_list done
get_local_name count=2 /Volumes/tank/media/
generator starting pid=70707
delta-transmission disabled for local transfer or --whole-file
recv_generator(test,1)
recv_generator(test,2)
set modtime, atime of test to (1683577882) 2023/05/08 15:31:22, (1683575413) 2023/05/08 14:50:13
recv_generator(test/asdf,3)
recv_files(1) starting
[receiver] flist_eof=1
[generator] flist_eof=1
generate_files phase=1
send_files(2, /Users/richard/test)
.d..tp...... test/
send_files(3, /Users/richard/test/asdf)
count=0 n=0 rem=0
send_files mapped /Users/richard/test/asdf of size 11
calling match_sums /Users/richard/test/asdf
>f..tp...... test/asdf
sending file_sum
false_alarms=0 hash_hits=0 matches=0
sender finished /Users/richard/test/asdf
recv_files(test)
recv_files(test/asdf)
recv mapped test/asdf of size 11
data recv 11 at 0
got file_sum
set modtime, atime of test/.asdf.8ywJ7X to (1672552800) 2023/01/01 00:00:00, (1683577900) 2023/05/08 15:31:40
renaming test/.asdf.8ywJ7X to test/asdf
touch_up_dirs: test (0)
set modtime, atime of test to (1683577882) 2023/05/08 15:31:22, (1683575413) 2023/05/08 14:50:13
send_files phase=1
recv_files phase=1
generate_files phase=2
send_files phase=2
send files finished
total: matches=0  hash_hits=0  false_alarms=0 data=11
recv_files phase=2
recv_files finished
generate_files phase=3
generate_files finished
client_run waiting on 70707

sent 148 bytes  received 1,545 bytes  3,386.00 bytes/sec
total size is 11  speedup is 0.01
[sender] _exit_cleanup(code=0, file=main.c, line=1356): entered
[sender] _exit_cleanup(code=0, file=main.c, line=1356): about to call exit(0)

Source file datetime Remote file datetime