Linux – Why rsync on Linux does not preserve all timestamps (creation time)

file-copylinuxmacosrsynctimestamps

I am using the current rsync 3.2.3 version and when I run stat command it shows me this info for my file.

stat '/test.txt'
File: /test.txt
Size: 0     Blocks: 0
IO Block: 4096   regular empty file
Device: fd00h/64768d    Inode: 11949
Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/liveuser)   Gid: ( 1000/liveuser)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2021-02-24 03:17:27.142676494 +0100
Modify: 2021-02-24 03:17:27.142676494 +0100
Change: 2021-02-24 03:17:27.142676494 +0100
Birth: 2021-02-24 03:17:27.142676494 +0100

I want to preserve Access, Modify and Birth timestamps. Use this command in rsync

rsync --atimes --times --crtimes 

or

rsync -UtN

The problem creation time (–crtimes) is not preserved on Linux. It automatically sets to the current transfer time.

How can I change the behaviour on Linux? I want to preserve all 3 timestamps for my copied files and folders.

If I do the same on macOS it works without problems.

EDIT

On macOS 10.13 and macOS 11 I just need to install homebrew and then I can get the latest rsync 3.2.3. By default, macOS has a very outdated rsync version 2.6.9 integrated.

  1. Open Terminal

  2. Install Homebrew

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

  3. Install rsync

    brew install rsync

Best Answer

The problem creation time (--crtimes) is not preserved on Linux. It automatically sets to the current transfer time.

While you can perfectly query crtime, there's no API to set it in Linux unfortunately: https://linux.die.net/man/2/utimes .

How can I change the behaviour on Linux? I want to preserve all 3 timestamps for my copied files and folders.

Check this question: Copying or restoring crtime for files/directories on ext4fs filesystem

Related Question