Auto mounting your Time Machine sparsebundle image on a network drive

Ok you can now do ad-hoc Time Machine backups up to your newly mounted network sparsebundle, but you want to leave Time Machine running continuously;

How do we get this sparse bundle image  to mount automatically without having to double click on the sparse image each time we reboot the box?

The traditional method of mounting the network drive, by dragging the network share into system preferences -> users & groups -> your account -> Login Items, followed by adding a small apple script to mount the sparsebundle image has the annoying side effect that your newly mounted shares will automatically open finder at login, so my preferred solution is to  use automator to do the work silently in the background

In my last post, my network drive was  GUEST:@mkdrive/NETBACKUP with a mount point of  /Volumes/NetBACKUP on my mac. The sparsebundle image file  in that directory was called macbook_backup.sparsebundle.

The format of the  command you would type in terminal rather than double clicking on sparsebundle image file to mount would be “hdiutil attach -quiet -nobrowse -mountpoint  TM_sparsebundle_mount_point   

So in my example it would be

hdiutil attach -quiet -nobrowse -mountpoint /Volumes/macbook_backup /Volumes/NETBACKUP/macbook_backup.sparsebundle

N.B. I use the -nobrowse option so that my sparse image does not show up in finder, if you would rather see this in finder just remove this option.

Using Terminal, you can test this command replacing the mount point and sparsebundle image filename name with your own.

Once tested, we can use a single automator workflow to do all of this, mount your network drive without opening finder,  mounting the sparsebundle image, all in the background.

autoator

Above the first part of the automator workflow lists the address of the shared folder / network drive you wish to connect to, the second part of the workflow connects to the server, and finally the last part of the work flow runs the shell command we worked out earlier.

Clicking on the above image will download a example workflow which you can open in automator, modify and save if you wish.

Once you have edited the workflow, click save in automator, making sure you save the file as an applicaiton.

We now need to get this application to run at login, this is easily done

Mac OS X 10.3 or later

  1. Log in as the user who wishes to have a login item or as an admin user.
  2. Choose System Preferences from the Apple menu.
  3. Choose Accounts from the View menu.
  4. Click the name of the user.
  5. Mac OS X 10.3.x: Click the Startup Items button.
    Mac OS X 10.4 or later: Click the Login Items button.
  6. Click the “Add {+}” button.
  7. Find and select your newly created automation application, and click add

Simple as that, now when you log into that users account, the network drive and the sparsebundle will be mounted automatically.

timemachine_on

You can now go into Time Machine , and move the slider to “on” and you are done..

 

Getting Time Machine working on a network drive with Mountain Lion

It’s always annoyed me that since moving to Lion, I’ve had problems using Time Machine over a network drive. As with all things Apple, the need to simplify actually restricts; the user interface of Time Machine does not have the option to use network storage, only that of direct attached disks or Apple Time Capsules.

timemachine screentimemachine no options

After a lot of Googling and playing, I finally got it working and have written it up so even my Mother could follow it. I’ve put the directions first and more detailed help further down.

In order to create a Time Machine backup on a network folder you need to follow these four steps:

  1. Create a HFS+ disk image, preferably sparse disk image, and place the disk image  into its destination folder/server where it will live. It shouldn’t matter whether it is an SMB (Windows) or AFP (Mac) shared folder as long as your Mac can write to it.
  2. Mount the disk image and drop into terminal to use the tmutil command to tell TM where it is (that’s the import bit!).
  3. Start the backup process to make sure it works.
  4. For scheduled backups, automate the mounting of the sparse disk image so backups will continue to work, after your mac is rebooted.

1. Creating the Disk Image

  1. Open Disk Utility Spotlight -> Disik Utility
  2. Click on New Image
  3. Set a large enough size for the disk image. Ensure that the Format is “Mac OS X Extended (Journaled)”  and the Image Format is “sparse bundle disk image“, you can also set “128-bit AES Encryption” if you want but not necessary. My recommendation is to encrypt as you’re going to put it on a network which could potentially be accessed by others.diskutility
  4. Save the disk image directly to  your shared folder, or alternatively as in this example I am saving the image locally and then moving it manually to the destination folder on the server.
  5. If you set encryption, it will ask for a password. Do not forget this password, or you will not be able to restore from your backup! macbook bundle password
  6. If you saved to your desktop, you will have a newly created sparsebundle image. In my case named macbook_backup.sparsebundle, move this file to its permanent home on your network share

2. Tell Time Machine to use the Disk Image

Now this is the bit that catches people out, and where you get conflicting advice across the net. The most common mistake is people mounting the network drive rather than the sparsebundle image, when Time Machine will not support network filesystems. Or trying to get Time Machine via tmutil to point at sparse bundle filename, rather than the mounted sparse bundle mount point.

In this example I have a shared network drive of //mkdrive/NETBACKUP and I have placed my newly created macbook_backup.sparse bundle into this directory.

Make sure that the disk image is in its permanent home before you use tmutil don’t change the server name or shared folder name after Time Machine uses it as your backup volume.

  1. Open Finder
  2. Navigate to the shared folder in which you put the new disk image.
  3. Double-click on the disk image to mount it. You should see the new volume in Finder’s sidebar.mounted sparse
  4. We now need to force Time Machine to see this Disk. This can only be done at the command line. Open Terminal spotlight -> Terminal. Enter the following command “df -H“, this will display your file system. I have marked in red where you can see my network drive ‘mkdrive share NETBACKUP’, as well as our newly mounted matchbook_backup.
  5. Now type the command “df -l” this displays only your local file systems. Looking at my terminal screenshot I have marked the interesting line in green. Even though our sparse bundle image is siting on the network drive, our mac is seeing this as a local disk. Result!dh-l
  6. Now let’s tell Time Machine to use this “local disk” and enter the following command sudo tmutil setdestination /Volumes/{mounted-disk-image} Be sure to replace {mounted-disk-image} with the appropriate name for your new disk image. So in my example I would of typed  ”sudo tmutil setdestination /Volumes/macbook_backup/“, You will be prompted for your password, this is normal.
  7. All done, we just need to enable Time Machine under Systems Preferences, and see if everything has gone ok. You should now see that Time Machine is configured to use your newly created disk, as shown in green below. While you’re in this screen check the box Show Time Machine in menu bar.tim machine using backupdisk

3. Do a Test Backup

Ok now we have Time Machine setup, lets check everything is working correctly.

  1. Click the Time Machine icon in the Menu Extras area (that’s the upper-right side of the screen) and select “Back Up Now”.
  2. Wait for Time Machine to do its thing
  3. Check the backup has worked by either opening Finder, navigating to the mounted disk image, and ensuring that Time Machine has created the “Backups.backupdb” folder and there is a folder inside it with the same name as your computer. Try that or actually entering Time Machine!
  4. You now have a way to save backups to non-Mac drives.

4. Bringing it all together

In my next post we will be looking at how we can automate the mounting of the sparse bundle so that Time Machine can schedule automatic backups.

 

23 years of Sleepless Nights

Link

My 5 year old asked what computer games did I play when i was younger, the answer is Sleepless Nights. I was hooked to MUDs in my teens and through university, and still host the MUD I started in the 80′s, its been running it for over 23 years!

You can stuff your world of warcraft, and modern warfare, and HD games, with the power of the written word..

seadog Inn