Hello,
I am working on a backup process on macOS. Before copying files, the script needs to check that it is looking at the correct mounted backup volume.
A fictional example
A user opens an encrypted disk image called ExampleBackup.sparsebundle and enters the password themselves. The volume then appears in Finder as ExampleBackup.
Before copying anything, the script needs to confirm:
- This mounted volume actually belongs to the intended disk image.
- The volume is mounted read/write.
- File ownership is being enforced.
- The destination has not been replaced or changed since the previous check.
Simply checking the volume name or its path does not seem sufficient: another volume could have the same name, or a device name could be reused after ejecting and reconnecting an image.
My questions
- What supported macOS API or command should a script use to establish this relationship reliably?
- Can we rely on specific fields from
hdiutil info -plistanddiskutil info -plist <device>? If so, where are their meanings and limitations documented? - How should the script distinguish “no” from “unknown” when information is missing or a check fails?
- What should it check again immediately before copying, since the volume could change between separate checks?
The checks themselves should only read information. They should not unlock or mount images, change permissions, or disable any security protections. If the script cannot confirm the destination safely, it should stop.
A recommended approach or small example would be very helpful.
Thank you.