01 October 2024

How to solve the "volume doesn't distinguish between upper- and lowercase letters" with an Apple Photos library?

Preface

Although this article's title focuses on the problem I had with the Photos library, I will start with the initial problem statement of restoring files from a Time Machine backup that was created on a really old MacBook Pro 2016 to the latest MacBook Air M3 2024. So bear with me, as I will start with the time machine backup/restore issues first.

Help - I Can't Restore My Machine from Time Machine

This August, I replaced my good old MacBook Pro which I had bought in 2016, with a brand new MacBook Air. I thought it will be a smooth backup/restore ride as usual. I was wrong. It took me roughly a week to get the Air to the roughly same state as before. Here's my story, for the ones that find similar issues.

Before starting with the details, I have to say, in all fairness, 8 years for a laptop is a long time these days. I knew there could be issues because my MBP 2016 didn't run the latest MacOS version Sonoma anymore, it could only be updated with the latest patches of Monterey. So I should have switched to the more manual migration in the first place.

First, I simply tried to restore the Air from my latest Time Machine. Ok, many of you will start laughing already here. Right, that was pretty naive of me to believe that this would work (Monterey based backup for a Sonoma based target machine). But Apple does not even warn you for such cases. I called Apple support and they were also clueless, and they didn't tell me to do it totally different. It may work for you, but it failed with me because having multiple files with the same name in the same directory, with the only difference being case-sensitive differences. You can try. If you get an obscure error,  I failed a couple of times with that, the reason being that the backup contained files from a case-sensitive Monterey setup, and by default a fresh installation of Sonoma comes with a case-insensitive APFS formatted disk.

I also tried to freshly install Sonoma with the case-sensitive disk format. This also failed, because for whatever reason, when trying to restore this Sonoma setup from the TM backup, the disk format switched back to case-insensitive during the process - it didn't tell me anything but when I looked at the disk format, it was back to case-insensitive. I tried that a couple of times. Dead end.

So here's the trick with which I was finally successful: I reinstalled Sonoma from scratch with all default settings, then opened the time machine bundle manually, and picked all files I wanted to have back.

In order to do that, you have to select the backup file (in my case it was called "Zelos.sparsebundle" as my previous MBP's name was Zelos), right click and choose "Open with... DiskImageMounter". This will mount the content of the backup file into your file system. Opening this up will look like this:

 

You can then select the latest date here and you will find your files in there, in my case:

 

File Transfer Performance

I had my original time machine backup file on a NAS. In order to speed up the process of picking files manually and copying them to my new laptop's disk, I copied this NAS based backup file to an external disk. Remember, the disk format has to be case-sensitive in order for that to work!

All Solved? No, Wait, Photos Library Issues Ahead!

Now you probably think "Wow, cool, that was helpful! All problems solved", right? Unfortunately not. Now it came to bring back my Photos library. Happy as I was, I started to copy the file to my new computer. The process starts, but in my case, it stopped after roughly 15 minutes (!) with the following error message:

 

Again, the root cause is having files with the same name in the same directory, the only difference is case sensitivity - files only differentiate in their upper or lower case names. 

In order to fix this problem, you need to do some manual work, including some Terminal, command line voodoo magic ;-):

  • Open a terminal window (Cmd+Space, terminal)
  • Switch to the directory where your Photos library package is located - with me, it is on the external drive named "APFS Backup Samsung HDD":

> cd /Volumes/APFS\ Backup\ Samsung\ HDD

  • Note: The backslash "escapes" the space in a file name on the command line
  • Note: By using the "Tab" key on the command line, you get all available options as directories provided
  • Now switch "into" the Photos library, e.g. when the name of the library is "Bernd.photoslibrary":

> cd Bernd.photoslibrary 

  • Run the following command:
> find . -type f -exec ls -A {} \; > ..\filenames.txt
  •  This creates the file "filenames.txt" in the directory above (or below, however you look at the directory structure)
  • In order to identify the duplicates, run the following command:

> awk '{print tolower($0)}' filenames.txt | sort | uniq -d

This will print out all files that are in a certain directory multiple times. E.g.

bernd@ExternalDiskName % awk '{print tolower($0)}' filenames.txt | sort | uniq -d
./originals/3/3d63362a-ff0f-4cc1-a05b-af4a6cd476bc.png
./originals/6/67b350bf-841d-460c-bbcd-9a6bd4dc4bf5.png
./originals/7/78906462-a8c1-4a0f-b564-ffb15b040b5a.png

  • Now go back to a Finder window, right click the Photos library, and select "Show Package Contents", navigate to the directory that the previous command printed, and deleted the duplicates, depending on which one you want to keep

Repeat the whole process until there are no duplicate files found anymore.

I hope this was of any help for some of you lost souls out there that tried the same as I did, so you don't waste so much time as I did. Good luck!

How to solve the "volume doesn't distinguish between upper- and lowercase letters" with an Apple Photos library?

Preface Although this article's title focuses on the problem I had with the Photos library, I will start with the initial problem statem...