SuperDuper Bash Script to Automatically Mount or Unmount a Hard Drive

March 6, 2009

SuperDuper! is a superb backup program for the Mac.

It does one (major) thing: It duplicates your hard drive to another hard drive.

mount-or-unmount-for-superduper.sh is a shell script which automates the process of mounting and un-mounting a hard drive to use with SuperDuper.

“What? Why? I don’t get it.”

Imagine this: you have a desktop Mac (or a laptop Mac that you keep the external drive plugged into all the time, I suppose).

You want to automate your backups because you know that you won’t really run them if they aren’t automated, because you’re lazy.

Nothing personal, everyone is lazy when it comes to backups. That’s why almost no one has them, even if they know they should.

SuperDuper is super easy (I promise I’ll stop with the super super bit) and works great, and even has a scheduler so you can set it to backup your machine at 3 a.m. or whenever you won’t be using it.

The only problem is that the drive has to be mounted (obviously) to do that, and having it mounted all the time can be annoying:

  1. Spotlight finds 2x the number of actual results: once for your main hard drive, once for your backup. [This is enough of an annoyance that there really needs to be no #2, but…]

  2. Having the drive mounted means that it will spin up and down all day long as it goes to ‘sleep’ and then thinks that it may be needed. If you’re only using it for SuperDuper, why not only have it spin up once per day?

  3. Installers will often check to see if maybe you want to install on a different hard drive than the main one. Having unmounted the drive means that you don’t have to worry about the Installer checking it.

  4. Imagine something horribly unexpected happens and you delete a bunch of files by accident. Do you want that list of “Files I May Have Accidentally Deleted” to include your backups? If not, having the backup drive unmounted prevents accidental deletions too.

How does it work?

The script is very simple. All you have to do is edit one line.

# Where Finder shows the drive when it is mounted
DRIVE_NAME_SHORT="iMac_Backup"

(Note that this must not include the /Volumes/ part of the path, but JUST the part which appears when the drive appears on the desktop or in Finder.)

I would encourage you not to get ‘creative’ with the name: Use letters only, no spaces or other punctuation except _ or - if you must

Names are important

Make sure to save the file with a name that begins with either ‘mount-’ or ‘unmount-‘

I recommend this that you:

  1. Download mount-or-unmount-for-superduper.sh

  2. Save it to ~/bin/ or somewhere else in your $PATH.

  3. Rename it:

    mv mount-or-unmount-for-superduper.sh mount-drive-for-superduper.sh

  4. Link it (so that any changes in one will be reflected in the other)

    ln mount-drive-for-superduper.sh unmount-drive-for-superduper.sh

  5. Launch SuperDuper, click the ‘Options’ button and then the ‘Advanced’

  • Add the ‘mount-drive-for-superduper.sh’ to ‘Before Copy: Run shell script before copy starts’

  • Add the ‘unmount-drive-for-superduper.sh’ to ‘After Copy: Run shell script after copy completes’

You ought to have a window that looks something like this:

SuperDuperScriptsWindow.png

Click ‘OK’ and it should look like this:

SuperDuper Confirmation Window.png

And then click ‘Schedule’ to tell SuperDuper when to run.

Feedback?

I welcome feedback on the script, especially if anything is unclear or you can see an easier way to do something.

Please leave a valid email address in comments. No one else but me will ever see it.

  • Scott A

    You'd probably also want to make sure that the drive name is unique, so you don't get it mounting with a trailing number that may not correspond to the script.

  • Fred

    I get the error:


    | Error | /Users/Fred/mount-drive-for-superduper.sh: line 42: /Users/Fred/.source: No such file or directory


    What is this invisible file? And how can I generate it? Thank you for your help.

  • OOps.


    My bad. You can simply run this command:


    touch ~/.source

  • Awesome script! This was exactly what I needed. :)

  • Louis

    Can you please explain were i will save the file: (mount-for-superduper.sh)
    in your instructions, you say to save it to: ( ~/bin/ or somewhere else in your $PATH)
    but were is that.


    What I did is to save it to" (Copy scripts file) inside the Resources of SuperDuper
    but I am getting this message: Scripts/unmount-for-superduper.sh
    | 05:28:15 PM | Error | sh: /Applications/SuperDuper!.app/Contents/Resources/Copy Scripts/unmount-for-superduper.sh: Permission denied
    Can you please help me.
    Thank you
    Louis

  • a) I don't think my script is necessary. The developer said that SuperDuper will automatically mount/unmount the drive if needed


    b) ~ is a Unix short cut for $HOME


    c) You probably need to get into Terminal and paste this command (including the " marks!) Make sure it is ALL ONE LINE:


    chmod 755 "/Applications/SuperDuper!.app/Contents/Resources/Copy Scripts/unmount-for-superduper.sh"

  • Graham Street

    Excellent script, thanks. I clone my main drive to a backup in my Mac Pro every evening. Your script will solve a problem I've had for a while where everything's duplicated in 'Launch Services' because OSX finds all the duplicate applications on my clone drive. The only thing I can't solve is that the disk mount requests my password, and therefore I can't leave the automatic clone update to run unattended. Do you have any suggestions for this?

  • Hrm. I don't know why it requests your password. I used that command specifically because it does not request my password. Sorry I don't have an answer.

blog comments powered by Disqus

Previous post:

Next post: