Unmount all partitions on a drive except ONE partition for backup by Carbon Copy Cloner

Unmount all partitions on a drive except ONE partition for backup by Carbon Copy Cloner

Background

I backup my MacBook (500gb) to a single external USB drive, which I connect as required.

My external backup drives first partitions are named
EXTU11AA, EXTU22AA, TOSH44AA, TOSH55AA etc. (ExternalUsb / TOSH=Toshiba)

On each drive there would be partitions for example.

EXTU11AA, EXTU11BB, EXTU11CC, EXTU11ARCH, EXTU11AVMEDIA etc (ARCH=General Archive)

TOSH77AA, TOSH77BB, TOSH77CC, TOSH77ARCH, TOSH77AVMEDIA etc

With a typical 2TB drive I would have four to five fixed partitions of about 500GB each

Today
I have migrated to APFS and I have many, many more partitions per drive.
I personally do not like to have drives mounted if I am not using them,
As something like Spotlight grabs them and will not let them go :frowning:

Some research of the forum shows that the macros referenced below could be modified.

Requirement
Let us say I know I am going to backup to EXTU33CC
And I have attached the EXTU33 external drive

I need a macro that unmounts all external (drives)/partitions starting with EXTU33,
But leaving EXTU33CC (passed as prompt/parameter) mounted

Any ideas?

References:

Also making them inaccessible to the system temporarily is a little extra data protection.

Unless there were more than a couple of dozen external drives, I would prefer to explicitly repeat the same simple action for each drive, for instance this in an Execute Shell Script action:

diskutil unmount "EXTU22AA"

The quotes around the drive name are just there as standard practice and are not needed unless the drive name contains spaces or other characters that would confuse the shell.

Cleverer solutions could match on regex, but why be clever (K.I.S.S. principle), unless there are unknown factors here, such as, perhaps, drive names being changed often.

Specifying the drive names explicitly means no chance of surprises or bugs, and you will have a list of your drives in the macro (one drive in each action) so you can enable and disable each action according to changing need, with no need to modify a regex string or revisit another solution which may be unnecessarily "general purpose".

Will think about your solution, but the reason I posted was I was expecting a regex solution, which would take me personally a very long time to work out.

I have also searched the internet and can find no macos parameter that "disables" automount when you attach a disk drive.

I also have the Jettison app, which was my idea/concept and subsequently developed by Jon Gotow of StClairSoftware. See Jettison .
Jettison unmounts all external drives, but I may have several attached and wanted only to unmount the partitions on a specific external drive,

In case you don't know of it: the Regex101 site is very useful for testing regular expression patterns.

I think this will be suitable:

EXTU33(?!CC[^\w]).*

That will match any string that begins with "EXTU33" unless that is followed by "CC"… unless that is followed by any character in the range A – Z, a – z or 0 – 9.

EXTU33CC on Regex101

Note: this solution, as it stands, would need work if you had drives with characters before the match, e.g. "FOO-EXTU33CC".

A bit route 1, but start with this

tell application "Finder" to eject (get every disk whose name starts with "EXTU33" and name does not end with "CC")

You can easily change those text strings to variables and pass them in as parameters.

In response to kevinb

Thank you , that will get me started.

I have not had to touch REGEX for sometime, but I did in
fact write a. tip on it here, which I had completely forgotten about.