3

I need to copy files and preserve all their metadata, including creation date.

I found ways to use rsync options to preserve modification date, but I also need the creation date to be the same, and not depending on when I copy the files.

Is there a way to do so? With a utility or any other way?

Maybe I could do it programmatically?

QDelage
  • 31
  • 3
  • 1
    Brith/creation time like change-status time on Linux is not meant to be tampered with. But then again, see [Change file creation date and time based off of file name](//unix.stackexchange.com/q/687217) for a way to trick your system. – Stéphane Chazelas Oct 03 '22 at 13:10
  • Also beware that that birth time is rarely useful as it doesn't tell you when the contents of the file was created nor even when a file with that name appeared in a directory. – Stéphane Chazelas Oct 03 '22 at 13:14

1 Answers1

2

If your destination filesystem supports creation (birth) time metadata, using an rsync version (3.1.1 or later) that supports the crtimes option achieves what you want.

--crtimes, -N

This tells rsync to set the create times (newness) of the destination files to the same value as the source files.

Update:

While this works flawlessly on macOS, with Linux this isn't supported. See here.

JRFerguson
  • 14,570
  • 3
  • 34
  • 40
  • Well, I don't know about the filesystems, but the outputs states my version does not support it "v3.2.6" (I tested it with Arch and with FreeBSD with the v3.2.5...) – QDelage Oct 03 '22 at 10:14
  • Related: https://unix.stackexchange.com/questions/636160/why-rsync-on-linux-does-not-preserve-all-timestamps-creation-time – JRFerguson Oct 03 '22 at 11:26