Shirt Pocket Discussions

Shirt Pocket Discussions (http://www.shirt-pocket.com/forums/index.php)
-   General (http://www.shirt-pocket.com/forums/forumdisplay.php?f=6)
-   -   An (Applescript) hack to automate mounting and unmounting external volumes (http://www.shirt-pocket.com/forums/showthread.php?t=235)

kbradnam 02-20-2005 03:22 PM

An (Applescript) hack to automate mounting and unmounting external volumes
 
My problem (see the other thread of mine) is that when you launch SuperDuper!, it 'remembers' the drives it last backed up to. So if you last backed up to an external drive that is currently not plugged in or mounted, you have to click 'Cancel' when SuperDuper reports that it can't find external drive 'XYZ'.

This has caused me some problems when trying to automate our backups as the backup scripts don't get past the 'Cancel' button and so they just sit there and wait.

Another problem I have is that I use an external firewire drive which contains two disk images (created as sparse images so that I can run Smart Update). SuperDuper can automatically mount these disk images but only if the external drive itself is first mounted. There are reasons why I think it is not always good to keep an external drive mounted when it is not in use. Also I've noticed that SuperDuper does not unmount the mounted disk images when it has finished backing up.

So on Friday I tried learning some Applescript to amend the basic Daily Backup script. My daily backup script now has the following at the start of the script:


Property diskname : "External HD"

tell application "Finder"
if not (exists the disk diskname) then
do shell script "diskutil mount `disktool -l | grep 'External HD' | sed 's/.*\\(disk[0-9s]*\\).*/\\1/'`"
delay 1
end if
end tell

delay 2


This uses the UNIX 'disktool' command to find out (with some sed and grep hacks) which device our firewire drive is connected to (will usually be disk2 or disk3 depending on how many other drives are connected). It then passes this disk name to the diskutil command to mount that volume.

I then include the rest of the SuperDuper script which is then followed by the next piece of code:


delay 2

tell application "Finder"
if (exists the disk "local_home_backup") then
eject "local_home_backup"
delay 2
end if
eject "External HD"
end tell



This ejects the disk image that was mounted for the backup and then ejects the volume as well. If you have multiple disk images on a volume, you may need to add extra lines in this section to first eject all of the disk images that may be mounted (SuperDuper can mount all images on an external volume...or at least all of those that you have ever backed up to). You won't be able to eject the firewire disk without first ejecting *all* mounted volumes on it.

This hack now means that I can automate our nightly backups without worrying about SuperDuper asking for a particular disk image to be mounted. It also means that when the backup finishes the external disk is unmounted.

Hope this might be useful to someone else.

Keith

P.S. This is my first ever attempt at using AppleScript, I'm sure there are better/neater ways of doing this.[FONT=Century Gothic]

dnanian 02-20-2005 03:45 PM

Great tips, Keith -- and one of the reasons we decided to write the backup "engine" in AppleScript! This makes it easy for users with specific requirements to modify and adjust it to their own particular requirements.

Thanks for contributing!

sjk 02-22-2005 04:22 AM

Thanks for the AppleScript code, Keith.

Here's a shell command example of the method I use to obtain the device node for a volume (e.g. Backup) with diskutil:

% diskutil list | awk '/ Backup / {print $6}'
disk1s5

There's a space before and after the Backup string so it's recognized as a single word to differentiate it from my BackupBoot volume. And to mount it:

% diskutil mount `diskutil list | awk '/ Backup / {print $6}'`
Volume disk1s5 mounted

tom.coady 05-30-2006 08:53 AM

Quote:

Originally Posted by kbradnam

eject "External HD"
end tell

The mount script works if I enter Backup instead where my firewire drives are called Backup A and Backup B, but is there a way to eject Backup * or all mounted external drives so I don't have to name the drive specifically?

dnanian 05-30-2006 09:22 AM

Tom -- this functionality is now integrated into SD! itself, so you shouldn't have to do this at all. Just unmount the drives after you're created the schedule(s) with 2.1.1, and we'll take care of the rest.

tom.coady 05-30-2006 11:25 AM

Quote:

Originally Posted by dnanian
Tom -- this functionality is now integrated into SD! itself, so you shouldn't have to do this at all. Just unmount the drives after you're created the schedule(s) with 2.1.1, and we'll take care of the rest.

Thanks Dave. I just tried this and it did nothing and when I opened SD it popped up a messages saying "Please attach or mount the volume named "Backup B". If you can't find this volume, or it was erased outside SuperDuper!, click Cancel." - but the FW vol was mountable using a script modded to find its name.

dnanian 05-30-2006 11:29 AM

That's right, though, Tom -- the automount only happens when the schedule fires.

tom.coady 05-30-2006 12:26 PM

Quote:

Originally Posted by dnanian
That's right, though, Tom -- the automount only happens when the schedule fires.

Sorry, Dave, you are right. It worked. I was looking at the wrong logs.

AVT 07-28-2007 01:03 PM

One question. I've created the scripts in the original post, but what is the "daily backup script" referenced in the original post? The problem is that SuperDuper gets stuck when it launches and the external drive is not already mounted and the only option is "cancel." I need to automatically mount the external drive before SuperDuper even launches. How do I do that?

Quote:

Originally Posted by dnanian (Post 1015)
Great tips, Keith -- and one of the reasons we decided to write the backup "engine" in AppleScript! This makes it easy for users with specific requirements to modify and adjust it to their own particular requirements.

Thanks for contributing!


dnanian 07-28-2007 01:08 PM

If you plug the drive in at that point, it should be recognized and the copy should continue.

AVT 07-28-2007 02:22 PM

I understand that, but I'm trying to get things set up so that the drive is automatically mounted, superduper runs, and the drive is automatically unmounted. That's what the scripts provided above do. My problem is how to get the external drive mounted before SuperDuper tries to do its thing. I've fiddled with the crontab file, and I've managed to get the drive mounted before SuperDuper runs. But when SuperDuper attempts to run the "unmount drive" script, it reports that "permission is denied". So, I've found a half-solution, so far.

Quote:

Originally Posted by dnanian (Post 13193)
If you plug the drive in at that point, it should be recognized and the copy should continue.


dnanian 07-28-2007 03:54 PM

You'll need to use the general framework we provide in our own copy template, and you'll want to run with "without user interaction", too.

Wings 07-30-2007 07:12 AM

Quote:

Originally Posted by AVT (Post 13192)
One question. I've created the scripts in the original post, but what is the "daily backup script" referenced in the original post? The problem is that SuperDuper gets stuck when it launches and the external drive is not already mounted and the only option is "cancel." I need to automatically mount the external drive before SuperDuper even launches. How do I do that?

AVT: What I do is to set iCal to run a mount script about a minute or 2 before SD is scheduled to run.

My mount script is: (compiled & saved as an application in Script Editor, and set to run as an alarm in iCal)

set diskName to "Backup"
set deviceName to do shell script "diskutil list | grep \"" & diskName & "\" | awk '{print $6}'"
do shell script "diskutil mountDisk /dev/" & deviceName


All times are GMT -4. The time now is 12:48 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.