2

I copied my entire photo library from a Windows Samba share mounted in fstab, into a local directory on my Ubuntu Linux machine using the terminal.

cp /sambashare/photos /localdisk/photos

Sadly this reset the date modified field to the current date on all of my photos. I tested this again and copied some photos from the Windows Samba share over to the exact same Linux machine with Windows file explorer (I simply created a second samba share on the Linux system.) And I noticed that this method preserved all of the date modified metadata.

Therefore the issue must be that the Linux command cp does not even try to retain date modified data when copying files from Samba shares. Unfortunately, my original photo library is not available so now all my photos have missing date modified data.

My first question is, is there any way to get this data back? Perhaps it's still located in the file but Linux is just not displaying it properly?

My second question or future reference is, is there any way to make the cp command retain this metadata in these scenarios?

Thanks

3 Answers 3

2

Therefore the issue must be that the Linux command cp does not even try to retain date modified data when copying files from Samba shares.

No, the issue is that the Linux command cp doesn't try to preserve modification time in general. You always have to use the -p option (or -a) to make that happen, regardless of the source or destination.

is there any way to get this data back? Perhaps it's still located in the file but Linux is just not displaying it properly?

The modification time isn't located in the file, it's an "external" property that requires a separate call to look up and a separate call to change. If it wasn't copied explicitly, then it wasn't copied.

(There is a possibility that the Linux SMB client has bugs related to it not refreshing the timestamps after a program has changed them, but it's unlikely. If this was the case then the timestamps would still be visible through Windows or after a remount.)

However, what you often do have in the file is a bunch of EXIF photo timestamps such as "Date Picture Taken" (set by your camera), which always gets copied because it's part of the file content. There are scripts to assign date-modified timestamps from EXIF metadata.

Failing that, it's possible to just set rough date-only timestamps based on your photo album names and/or your own memory (e.g. if you remember that specific photos were from Feb 2003, you can touch them to 2003-02-09 00:00:00).

is there any way to make the cp command retain this metadata in these scenarios?

Use the -p option (or -a when appropriate).

1

I think a more apropriate tool would be rsync with -av switch.

To see what "metadata" is available: you could throw something like exiftool at the images.

And this is probably a timely reminder to you about backups. (Why is your original data "not available")

4
  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review Commented May 12, 2022 at 7:21
  • 1
    Thanks From Review – User552853. As it stands, I don't have sufficient reputation to comment. My answer does not require clarification from the asker. The question's a bit like asking how to put screws in with a hammer.
    – mitts
    Commented May 12, 2022 at 7:24
  • The question was asking is there a way to get this data back. I think the issue here is that your answer doesn't attempt to solve his problem. To use your analogy, the question has asked "I have hammered in screws with a hammer, how to I preserve the wood underneath?" and you have said "you should have used a screwdriver". It doesn't answer what the asker has asked
    – Randomhero
    Commented May 12, 2022 at 11:27
  • Aha. Mea culpa. I glossed over that bit. I answered to the second question, not the first.
    – mitts
    Commented May 14, 2022 at 14:00
0

In the end, I had to write up a couple of python scripts to fix this issue. You can find it here on GitHub, the readme file also explains a bit more about how I fixed the issue. Thanks for your help.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .