12

I have a source directory on a machine with a bunch of files, all with the same permissions, that I want to copy to another directory, that is mounted via SMB.

[tmark@dexter JR09141045 roche_454_transfer]$ ls -l /source_dir
total 71348
-rwxrwxrwx 1 adminrig lifelabs 19768377 Mar 25 23:29 1.TCA.454Reads.fna
-rwxrwxrwx 1 adminrig lifelabs 53093396 Mar 25 23:29 1.TCA.454Reads.qual
-rwxrwxrwx 1 adminrig lifelabs     1035 Mar 25 23:29 454AllControlMetrics.csv
-rwxrwxrwx 1 adminrig lifelabs     2657 Mar 25 23:29 454AllControlMetrics.txt
-rwxrwxrwx 1 adminrig lifelabs     4607 Mar 25 23:29 454BaseCallerMetrics.csv
-rwxrwxrwx 1 adminrig lifelabs    14518 Mar 25 23:29 454BaseCallerMetrics.txt
-rwxrwxrwx 1 adminrig lifelabs      351 Mar 25 23:23 454DataProcessingDir.xml
-rwxrwxrwx 1 adminrig lifelabs      702 Mar 25 23:29 454QualityFilterMetrics.csv
-rwxrwxrwx 1 adminrig lifelabs     1609 Mar 25 23:29 454QualityFilterMetrics.txt
-rwxrwxrwx 1 adminrig lifelabs    13496 Mar 25 23:29 454RuntimeMetricsAll.csv
-rwxrwxrwx 1 adminrig lifelabs    26967 Mar 25 23:29 454RuntimeMetricsAll.txt
-rwxrwxrwx 1 adminrig lifelabs     1675 Mar 25 14:48 dataRunParams.xml
-rwxrwxrwx 1 adminrig lifelabs     7134 Mar 25 23:29 gsRunProcessor.log

The target directory is mounted via SMB and I'm trying to copy the set of files all at once.

[tmark@dexter JR09141045 target_dir]$ cd /target_dir
[tmark@dexter JR09141045 target_dir]$ cp -p /source_dir/* ./
cp: preserving times for `./454AllControlMetrics.csv': Operation not permitted
cp: preserving times for `./454AllControlMetrics.txt': Operation not permitted
cp: preserving times for `./454BaseCallerMetrics.csv': Operation not permitted
cp: preserving times for `./454BaseCallerMetrics.txt': Operation not permitted
cp: preserving times for `./454DataProcessingDir.xml': Operation not permitted
cp: preserving times for `./454QualityFilterMetrics.csv': Operation not permitted
cp: preserving times for `./454QualityFilterMetrics.txt': Operation not permitted
cp: preserving times for `./454RuntimeMetricsAll.csv': Operation not permitted
cp: preserving times for `./454RuntimeMetricsAll.txt': Operation not permitted
cp: preserving times for `./dataRunParams.xml': Operation not permitted
cp: preserving times for `./gsRunProcessor.log': Operation not permitted

[tmark@dexter JR09141045 target_dir]$ ls -l
total 71264

-rwxrwxrwx 1 tmark 1008 19768377 Mar 25 23:29 1.TCA.454Reads.fna
-rwxrwxrwx 1 tmark 1008 53093396 Mar 25 23:29 1.TCA.454Reads.qual
-rwxr-xr-x 1 tmark 1008     1035 Apr  1  2015 454AllControlMetrics.csv
-rwxr-xr-x 1 tmark 1008     2657 Apr  1  2015 454AllControlMetrics.txt
-rwxr-xr-x 1 tmark 1008     4607 Apr  1  2015 454BaseCallerMetrics.csv
-rwxr-xr-x 1 tmark 1008    14518 Apr  1  2015 454BaseCallerMetrics.txt
-rwxr-xr-x 1 tmark 1008      351 Apr  1  2015 454DataProcessingDir.xml
-rwxr-xr-x 1 tmark 1008      702 Apr  1  2015 454QualityFilterMetrics.csv
-rwxr-xr-x 1 tmark 1008     1609 Apr  1  2015 454QualityFilterMetrics.txt
-rwxr-xr-x 1 tmark 1008    13496 Apr  1  2015 454RuntimeMetricsAll.csv
-rwxr-xr-x 1 tmark 1008    26967 Apr  1  2015 454RuntimeMetricsAll.txt
-rwxr-xr-x 1 tmark 1008     1675 Apr  1  2015 dataRunParams.xml
-rwxr-xr-x 1 tmark 1008     7134 Apr  1  2015 gsRunProcessor.log

Note that the times and permissions on the first two files are the same as in the source directory, but differ for the remaining files.

So, it seems that I can copy some files and preserve their permissions and times, but not with other files, even though all the source files come from the same place and have the same permissions and (more or less) times, and I'm copying them all to the same directory at the same time - and hence with the same umask, etc.

So, why can I preserve the times for some, but not all files ?

I'd be happy to provide more details (umask, Linux version, smb.conf, etc etc.) except I can't understand how any of those details could explain what I'm seeing - as they ought to be constant here.

tmark
  • 121
  • 1
  • 1
  • 6
  • You mentioned SMB. Is this a CIFS share form a windows server? From a NetApp? This can matter too. NetApp for example has different share/mixed modes. In fact, there are many possibilities depending on what you are sharing from; and as you eluded to, the kernel version and mount options you are using on the client. – Aaron Dec 31 '15 at 17:35
  • can you share the mount detail for this samba share how did mount it? just wanted to check did u use "noatime" while mounting – PKumar Dec 31 '15 at 17:37
  • preferable to use rsync insead of cp. – PKumar Dec 31 '15 at 17:38

2 Answers2

11

On Unix the timestamps cannot be preserved on the files the user does not own.

This is why the following command fails if file1 and file2 are owned by different users in case file2 already exists:

cp -p file1 file2

Seems it is your case because source files are owned by adminrig and target files are owned by tmark.

Not sure if there is a workaround as forcing with -f does not solve the issue.

If you can, try changing ownership of target files...

krisFR
  • 12,830
  • 3
  • 31
  • 40
  • 2
    thanks krisFR. However, the source files which *were* copied with the right permissions and timestamps, have the same ownership as the ones which generate the errors. In fact, all the source files have the same apparent permissions, and they are all owned by adminrig, so it doesn't seem like ownership could explain what I'm seeing completely - else *none* of the files should copy with permissions and timestamps. – tmark Apr 02 '15 at 14:34
  • Consider [using `cp -a` instead](https://unix.stackexchange.com/a/235961/209677). – Pablo A Nov 16 '17 at 02:19
1

I know this is old, but I was having the same issue of trying to copy over cifs shares. I have several commands set up in sudoers with the NOPASSWD option and one is cp. If I do sudo cp -r from.file to.file it seems to work. If you have the ability to do sudo, this may be an option.

user999684
  • 145
  • 1
  • 1
  • 8