Thanks so much everyone for your quick replies. To see if could replicate the problem, I wrote a quick batch script which writes to a file on my iCloud drive ~5 times per second. I did not succeed. iCloud handled and synced it flawlessly. So, I guess there’s more to it and that my test setup didn’t replicate Obsidian’s file handling specifically.
I kept investigating and tinkering and I was able to find a solution to decouple my local vault from the vault on the iCloud drive, and to keep them in sync. So far it has worked well for me. I’ll keep on testing it to see if it is reliable in the long run, but this is what I did.
Solution
- I set up two separate directories: One main directory on my local drive to keep the vault for the Obsidian desktop app and which isn’t synced to the iCloud drive. And one “remote” directory on my iCloud drive to keep a copy for my iOS apps:
C:\Users\bobbieeray\Documents\04 Research\obsidian\Notebook
C:\Users\bobbieeray\iCloudDrive\iCloud~md~obsidian\Notebook
- I installed Unison File Synchronizer for Windows. Unison is a file-synchronization tool for POSIX-compliant systems, macOS and Windows. I extracted it to a local directory and I also added the
../unison/bin/
directory to the PATH variable to make it more easily accessible from the command line (the latter is optional though).
- I added a new task to the Windows Task Scheduler, calling Unison every 2 minutes as a
SYSTEM
user so that it runs in the background. To create the task, I opened my PowerShell as an administrator and ran
SCHTASKS /Create /RU "SYSTEM" /SC MINUTE /MO 2 /TN "ObsidianNotebookICloudSync" /TR "C:\SDK\Unison\bin\unison.exe -batch -confirmbigdel=false 'C:\Users\bobbieeray\Documents\04 Research\obsidian\Notebook' 'C:\Users\bobbieeray\iCloudDrive\iCloud~md~obsidian\Notebook'"
Result
Unison allows two replicas of a collection of files and directories to be stored on different hosts (or different disks on the same host), modified separately, and then brought up to date by propagating the changes in each replica to the other.
So, running Unison every 2 minutes ensures that both directories are synchronized both ways, without running into the sync issues and duplicate files, when storing the vault for the desktop app on the iCloud drive directory directly.
This will only work for a single user setup though. It can handle changes that happen either on the local machine, or in iOS. It isn’t capable to handle multiple users, working on the same note, simultaneously, i.e. it offers no (automatic) merging and/or conflict management capabilities.