Use a run-on-drive-connect SuperDuper backup script
Mar 19, '09 07:30:00AM
Contributed by: Anonymous
I've put together information from several other guides (see references at the end) that I found around the web to create an auto-run SuperDuper backup script. The backup will start when you attach a USB (or FireWire) drive, and the drive is then automatically un-mounted when the backup is complete.
This is very useful for me (versus scheduled backups) because I am at my home and office desks at variable times of the day. When I get to work in the morning, I just connect the drive and away it goes! A few hours later when I leave, I just check Finder to make sure the drive is unmounted and pack up.
Read on for the details.
Note that my script is designed for two different drives; it can be reduced for only one. First, create a shell script to unmount your external drives, and place it in ~/Library/Scripts. For USB disks:
#!/bin/bash
system_profiler SPUSBDataType | grep "BSD Name: disk.$" | \
sed "s/^.*: //" | (while read i; do /usr/sbin/diskutil unmountDisk $i; done)
For Firewire disks, use this script instead:
#!/bin/bash
system_profiler SPFireWireDataType | grep "BSD Name: disk.$" | \
sed "s/^.*: //" | (while read i; do /usr/sbin/diskutil unmountDisk $i; done)
Remember to make these scripts executable (chmod a+x script_name). Next, with the backup drive attached, create an automated, timed backup in SuperDuper that runs the unmount shell script upon completion. Once that's done, copy the Scheduled Setting from ~/Library » Application Support » SuperDuper! » Schedule Copies to ~/Library » Application Support » SuperDuper! » Saved Settings.
In Terminal, create a symbolic link in ~/Library » Scripts to the Copy Job.app inside the Saved Setting package:
sudo ln -s "/Users/your_user/Library/Application Support/SuperDuper!/Saved Settings/Smart Update OfficeDrive from MacHD.sdsp/Copy Job.app" "Smart Update OfficeBackup"
Repeat these steps (create scheduled backup, copy scheduled settings, link to the Copy Job app) for every drive that you want to back up -- just remember to use a new name for each symbolic link.
Create a new AppleScript called Auto Backup to External Drive with this code (set the top parameters appropriate to your drive or drives):
Save this script to the /Library » Scripts » Folder Action Scripts folder. Finally, in the Finder, press Shift-Command-G (Go » Go to Folder) and type /Volumes then press Return. Control-click in a blank area of the Volumes folder and go to More » Attach Folder Action. In the dialog that appears, navigate to and select the Auto Backup to External Drive script you just created.
That's it. To use your new auto-backup script, just plug in your backup drive and wait.
References:
[robg adds: I haven't tested this one yet, but I intend to, as it seems perfect for my once-daily boot drive clone task. Note, too, that that unmount scripts will unmount all attached USB (or FireWire) drives. If you just want to unmount one drive, you'll need to modify the code to unmount just that one drive. I worked out a replacement script that should work for just one drive, attached via FireWire or USB; here's what I came up with as the executable line:
diskutil list | grep name_of_volume | cut -c 69-73 | (while read i; do /usr/sbin/diskutil unmountDisk $i; done)
You'd need to verify that the cut columns are correct on your machine -- do that by leaving off everything after 73 and checking the output shows the full disknn name -- and replace name_of_volume with the name of the volume (disk) you'd like to eject. This bit of code worked in my testing, but proceed at your own risk.]
Comments (8)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20090315132133858