Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to unmount cloned backup volumes at login System
With counsel from Bramley in the MacOSXHints.com System forum, I developed an application that automatically unmounts my backup internal hard drive's 10.3.4 volume on startup. This prevents alias confusion in opening files on the wrong internal hard drive after Retrospect 6 Duplication cloning. My hunch is that the clone's files initially look more recent than the working drive's files to the OS and/or applications used to open the files.

There may have been other causal factors, but after adding the second internal hard drive and duplicating to it periodically, Office X and then Office 2004 Entourage opened the cloned database rather than automatically opening the one on its own drive.

Now, when I wish to duplicate/clone the working hard drive to the backup drive, I just run another script that mounts my destination volume, runs the customized duplication script, and then unmounts the volume. On the next login after duplication, I am secure in the knowledge that the backup volumes will be unmounted without having to rely on human memory. Here's how: Open AppleScript editor and enter:
tell application "Finder"
  if exists (disk "Name of Backup Volume") then
    eject "Name of Backup Volume"
  else
    display dialog "volume not found or is unmounted already"
  end if
end tell 
"Save as" and then scroll in the format pop-up menu to "Application." Uncheck the default "startup screen" box in the save-as dialogue. Make sure saved in Applications folder. Then open System Preferences/Accounts/Start Up Items and add it.
    •    
  • Currently 3.00 / 5
  You rated: 4 / 5 (6 votes cast)
 
[17,957 views]  

A script to unmount cloned backup volumes at login | 6 comments | Create New Account
Click here to return to the 'A script to unmount cloned backup volumes at login' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to unmount cloned backup volumes at login
Authored by: sjk on Jun 25, '04 10:34:55PM
My hunch is that the clone's files initially look more recent than the working drive's files to the OS and/or applications used to open the files.

Hopefully someone can confirm (or deny) that hunch since it would be useful to understand what's really happening to cause the "wrong volume" behavior you've described. Any idea if that might happen with cloned volumes on external FireWire drives?

Thanks for the heads-up with this hint.

[ Reply to This | # ]
A script to unmount cloned backup volumes at login
Authored by: Han Solo on Jun 25, '04 10:57:35PM
I have seen the described behavior on a MDD G4 tower: some apps (including, on occasion, the Finder) get confused and access files from the clone drive (internal) than the original source. The classic example was a service from a long uninstalled program that would not disappear.... Turned out the program still existed on the clone, and the Finder was loading it from there.

In any event, this clue isn't really as helpful in my case as I might have hoped. I don't log out but either use the screensaver or FUS, so the proposed startup script won't run. What I'd prefer is a script that does the following:

  1. Mounts the internal clone drive
  2. Updates the clone image from the source (runs CCC)
  3. Unmounts the internal clone drive until next time
Unfortunately, my scripting skills are non-existent. Anyone have an idea how to accomplish this (conceptually) simple task? TIA.

[ Reply to This | # ]
A script to unmount cloned backup volumes at login
Authored by: jpimbert on Jun 29, '04 09:50:39AM
May Be This shell script could help you. You can modify the CCC script to add :

- at the beginning : MountLabel -m "label of your partition"

- at the end: MountLabel -d "label of your partition"

Here is the code for MountLabel (and sorry for the French Comments)


#!/bin/tcsh

##
# Script pour monter/demonter un volume par son Label
#
# Jean-Pierre IMBERT | jean-pierre.imbert@ingenieurs-supelec.org
##

##
# Verification de la syntaxe d'appel
##

set t
switch ($1)
case "-l":
 @ t = ($# == 1)
 set command = "list"
 breaksw
case "-m":
 @ t = ($# == 2)
 set command = "mount"
 breaksw
case "-d":
 @ t = ($# == 2)
 set command = "dismount"
 breaksw
default:
 @ t = 0
 breaksw
endsw

if ($t == 0) then
 echo "MountLabel:  Mount/Dismount Volume with its Label Name"
 echo "MountLabel:  MountLabel [ -m | -d ] Label"
 echo "MountLabel:  MountLabel -l"
 echo "Usage:     You can use MountLabel for mount/dismount or list Volumes knowing their Label"
 echo "Usage:     This command works only for hfs volumes"
 echo "Usage:     The acceptable command line parameters are"
 echo "Usage:         -l -- list all Volumes currently on line"
 echo "Usage:         -m -- mount the volume 'Label'"
 echo "Usage:         -d -- dismount the volume 'Label'"
 exit 1
endif
set vol_label = $2

##
# Recherche de la liste des volumes en ligne 
# et execution de la commande "list" ou recherche du "device" correspondant
##

if ($command == "list") then
 disktool -l | grep "Disk Appeared" | awk -F "'" '{print $8"   "$2}'
 else
 set device = `disktool -l | grep "Disk Appeared" | awk -F "'" '{print $8","$2}' | grep "^$vol_label," | awk -F "," '{print $2}'`
 if ($#device == 0) then
   echo "There is no drive online with label $vol_label"
   exit 1                                 # erreur : le volume cherche n'est pas en ligne
 endif
endif

##
# Realisation de la commande
##
switch ($command)
case "list":
 exit 0
 breaksw
case "mount":
 if !(-d /Volumes/$vol_label) then
   mkdir /Volumes/$vol_label                               # creation du repertoire de montage
   else
   echo "The target drive seems to be already mounted."    # erreur : le volume semble deja monte
   exit 1
 endif
 mount_hfs /dev/$device /Volumes/$vol_label
 if ($? != 0 ) exit 1                                      # erreur : probleme de montage du volume
 disktool -r
 breaksw
case "dismount":
 if !(-d /Volumes/$vol_label) then
   echo "The target drive is not mounted."                 # erreur : le volume n'est pas monte
   exit 1
 endif
 umount -f /dev/$device
 disktool -r
 rmdir /Volumes/$vol_label
 breaksw
endsw


[ Reply to This | # ]
A script to unmount cloned backup volumes at login
Authored by: PCheese on Oct 17, '04 04:38:34PM
Here's my version. The main difference is that if you run it after using it once to unmount a disk, it'll remount the disk for you, although it'll look like a disk image (but you will be making changes to the disk itself, only the icon should be different). I had to add a whole bunch of line continuation characters.

(*
   Simple unmount volume script
   By PCheese
   10/17/2004
   Useful to unmount a disk at login
   You must set the variable volumeName to the name of your disk.
   If you would like to mount the volume without having to type in a password,
      save your password in the savedPassword variable. Please be aware that this
      is insecure, and someone with access to this script could recover your password
      if you save it, even if you save the script as run-only.
  Set delayTime to something higher if you have trouble with this script at startup
*)
property volumeName : "Macintosh HD"
property savedPassword : ""
property delayTime : 0

property lastDevicePath : ""

on run
	set previousDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to " "
	-- this part is just so we can mount it again later
	try
		set matchingVolumes to do shell script "df | grep '/" & volumeName & "$'"
		set matchingVolumes to every text item of matchingVolumes
		--less than ten characters would be a mounted disk image
		if (count characters in item 1 of matchingVolumes) is greater than 10 then
			set lastDevicePath to item 1 of matchingVolumes
		end if
		-- now unmount it for real after waiting some delay time for the Finder
		delay delayTime
		try
			tell application "Finder" to eject disk volumeName
		end try
	on error errMes number errNum
		if errNum is 1 and lastDevicePath is not "" then
			try
				set baseDialogText to "The volume named \"" & volumeName & "\" last located on " & lastDevicePath ¬
& " seems to be unmounted.  Would you like to mount it as a disk image now?"
				if savedPassword is not "" then
					display dialog baseDialogText buttons {"Cancel", "Mount"} default button 2 with icon caution ¬
 giving up after 60
					do shell script "hdiutil mount " & lastDevicePath & " > /dev/null" password savedPassword ¬
 with administrator privileges
				else
					display dialog baseDialogText & return & return ¬
& "You will have to type an administrator password." ¬
buttons {"Cancel", "Mount"} default button 2 with icon caution ¬
giving up after 60
					do shell script "hdiutil mount " & lastDevicePath & " > /dev/null"
				end if
			end try
		end if
	end try
	set AppleScript's text item delimiters to previousDelimiters
end run


[ Reply to This | # ]
A script to unmount cloned backup volumes at login
Authored by: hints_hinterton on Aug 06, '08 07:07:44PM

Thanks, I needed this...after all this time...I want to modify it to unmount but if all I can do is eject, great for now.

Got some renegade hard drives that need to be connected but disconnected, if you get my drift.



[ Reply to This | # ]
A script to unmount cloned backup volumes at login
Authored by: hints_hinterton on Aug 06, '08 07:18:35PM

Here we go, this is working for me... will add a part to check if the drive is mounted...

basic line: do shell script "hdiutil unmount /Volumes/NameOfDrive"

if your drive has two words in the name it's "NameOf\\ Drive"

no idea why this works when ever other hint I've read has a million lines...hope I'm not munging something up!



[ Reply to This | # ]