8

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

2 Answers2

6

Linux

crtime tells when the file was created in this filesystem. It was never intended to indicate when the content might have been created somewhere else.

MacOS

rsync can be "patched" on MacOS. If you compile rsync with the patches fileflags, crtimes, hfs-compression then rsync can handle OS X metadata and preserve the original file's birthtime on the new file. Note that st_birthtime is only available in the 64 bit inode variants. See man 2 stat.

It's possible there are patched versions of rsync for Linux around. Though I am not aware of any.

Pro Backup
  • 4,924
  • On my 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.

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

    Install rsync brew install rsync

    – Olea.2fmao Feb 24 '21 at 15:59
  • Then on macOS I can preserve all 3 timestamps (Access, Modify and Birth), on Linux only Birth does not work. – Olea.2fmao Feb 24 '21 at 16:02
3

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