Home > Blockchain >  How to maintain ctime, mtime and atime of file when copying file on NFS v3 drive
How to maintain ctime, mtime and atime of file when copying file on NFS v3 drive

Time:12-17

I am customizing NFS v3 server. When I copy files from other location to NFS Drive on Linux, the copied file times are set to current time. I think, when copy is done, at least, create, modify are same as source file, but it does not work. I am using NFS v3 protocol.

For example: cp ./i686-linux-gnu-ar /mnt/nfs

/mnt/nfs : mount point

enter image description here

As you can see above screenshot, source file and copied file's time attribute are different.

enter image description here

In NFS server, I know SETATTR is used to set file attribute including time properties, but when I debug it, I couldn't get timestamp "Feb 20 2021" from SETATTR argument. Actually, The copied file time can be updated only if can get the timestamp ("Feb 20 2021"), I think.

Does anyone know about this? Thanks!

CodePudding user response:

Have you tried the --archive aka -a option to the cp command?

-a, --archive
same as -dR --preserve=all

--preserve[=ATTR_LIST]
preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: context, links, xattr, all

  • Related