'cp -p' issues on MyCloud EX2 from MacOS Terminal

I plan to programatically copy hundreds of photo files and organize the files into different folders. The organized files must retain and preserve their original datetime stamps.

  1. I have a MyCloud EX2 Ultra NAS (firmware 5.11.112) which I access through a MacOS Terminal.

  2. On my Mac, the NAS folder is mounted on /volumes/Public with user-id ‘dad’. Mount was done via Finder/Connect-To-Server.

  3. I then execute the cp command with -p flag to preserve file datetime stamps

    cp -pv /volumes/Public/src/DSC06727.JPG /volumes/Public/src/tmp

    where:
    /volumes/Public/src/DSC06727.JPG and /volumes/Public/src/tmp
    are both on the NAS

Although the ‘cp -p’ flag was specified, I noticed that the file datetime stamps on the copied file is actually not preserved. Instead the current datetime is used on the newly copied file.

a. When I use Finder to copy files on the NAS, the original datetime stamps are preserved.
b. When I ssh to the MyCloud server, and do ‘cp -p’ within the ssh terminal session, the original datetime stamps are also preserved.

How can I copy files on MyCloud NAS from Terminal and at the same time preserve their original datetime stamps?

Thanks for any help.

on MacOS Terminal

$ echo $USER
dad

*** source file has Mar-23 date ***
$ ls -l /volumes/Public/src/DSC06727.JPG
-rwxrwxrwx 1 dad staff 4793883 24 Mar 19:13 /volumes/Public/src/DSC06727.JPG

*** cp -p ***
$ cp -pv /volumes/Public/src/DSC06727.JPG /volumes/Public/src/tmp
/volumes/Public/src/DSC06727.JPG → /volumes/Public/src/tmp/DSC06727.JPG

*** copied file has current date ***
$ ls -l /volumes/Public/src/tmp
-rwxrwxrwx 1 dad staff 4793883 29 Mar 2021 DSC06727.JPG
*** datetime stamp is current date :<( ***

There is a dedicated subforum for the EX2 series of devices which run OS5 here:

OS5 My Cloud EX Series
https://community.wd.com/c/os5/my-cloud-ex-series/255

This subforum, OS3 My Cloud, general deals with the single bay/single drive My Cloud running OS5…

As to the date/time issue that may possibly be due to the file being created in the new location and it’s creation date using the current date/time rather than the original file’s date/time. various methods of copying a file and trying to preserve it’s date and time.

cp -pr OldDir NewDir
sudo cp -rp <sourceDir> <destDir>
sudo rsync -auvh --progress <sourceDir>/ <destDir>

thank you @Bennor, should I post this query on the OS5 forum?

not sure I understood your response, to clarify:

the ‘-p’ (preserve) flag for cp command does not seem to work when cp is done on Terminal for files stored and mounted from the EX2 NAS

You may have better luck in the dedicated OS5 EX Series subforum where people more familiar with the EX2 may be able to assist.

How is the My Cloud Share mounted? Using SMB or AFP? Could be a specific issue with how the Share is mounted that is causing the file dates not to be preserved when copying on a mounted Share using MacOS Terminal. Or could be an issue specific to how MacOS Terminal works.

Does using the rsync -auvh <sourceDir> <destDir> command in the MacOS Terminal cause the same issue of date time stamp not being preserved?

Thanks for your help @Bennor. I will post my query on the OS5-EX subforum.
I executed the rsync command and it does retain the datetime stamps. Also, the MyCloud share was mounted thru Finder/Connect-To-Server.
I would like to pursue ‘cp -p’ functionality as I need individual photo files programmatically copied to other folders based on certain exif image attributes.