Fork me on GitHub

This is an old revision of the document!


Backing up Disk Images Between Machines

If you store you backup within a (encrypted) disk image and you would like to keep this disk image consistent across various systems then you may find the information on this page helpful.

Mac OS X Sparse Bundle Images

Mac OS X 10.5.x and later supports sparse bundle images. These are disk images which are split into smaller files. The advantage of sparse bundle images is that you may use a tool such as rsync to keep your disk image(s) consistent across various systems.

Copy sparse bundle between machines using rsync.

It is possible to copy / update a sparse bundle between two Mac OS X machines using a patched version of rsync v3.


A One Line Version

Remember that before coping or update a sparse bundle it is important that you have checked to ensure the images is unmounted.

if [ -d /path/to/my_backup.sparsebundle ] && ! [ -d /Volumes/mybackupimage ] ; then ssh backup@remoteserver "df -h" | head -n 2 ; sleep 5 ; /usr/local/bin/rsync_v3 --rsync-path=/usr/local/bin/rsync_v3 -aNHAXEx --delete --progress --stats --protect-args --fileflags --force-change /path/to/my_backup.sparsebundle backup@remoteserver:/backups/ ; else echo "ERROR! : Source not available, or image is mounted ; fi



A Script Version

#!/usr/bin/env bash

# Copyright 2009 Henri Shustak
# Released Under The GNU GPL v3
# Lucid Information Systems 
# http://www.lucidsystems.org

# This script will use rsync to push an updated copy of a sparse bundle image
# from the local machine to a remote machine. 
# 
# This script could easily be modified to pull the backup or move the backup between two servers.
#
# This script is also easily condensable into a single line so it can be added concisely to your .profile
# for easy execution.
#
# The script will display progress of each band being copied or deleted during the copy. To disable this 
# remove the --progress option when calling rsync.
# 
# Finally, IT IS VERY IMPORTANT that before you call this script you check the disk image is not mounted.

# Various settings which you will want to alter before running this script.
local_sparse_bundle_to_sync="/path/to/my_backup.sparsebundle"
remote_sparse_bundle_destination="/backups/"
remote_server_address="myremotesshserver.mydomain.com"
remote_server_user="mrbackup"
path_to_rsync="/usr/local/bin/rsync_v3.0.6"

# Internal Variables
hdiutil_mounted_status=`hdiutil info | grep "image-path" | grep "${local_sparse_bundle_to_sync}"`

# Okay now we have all the configuration information lets copy / update the sparse bundle.

# Check the image available and is not mounted.
if [ -d "${sparse_bundle_to_sync}" ] && [ "${hdiutil_mounted_status}" == "" ] ; then 

  # Print some volume statistics for the remote servers root partition.
  ssh ${remote_server_user}@${remote_server_address} "df -h" | head -n 2 

  # Wait a moment so you can easily stop this process if you made a mistake.
  sleep 5

  # Use rsync to copy / update the remote file
  ${path_to_rsync} --rsync-path=${path_to_rsync} \
  -aNHAXEx --delete --progress --stats --protect-args --fileflags --force-change \     
  ${local_sparse_bundle_to_sync} \         
  ${remote_server_user}@${remote_server_address}:${remote_sparse_bundle_destination}

  exit $?

else

  echo "ERROR! : Source not available : ${local_sparse_bundle_to_sync}"
  echo "         Or the image is mounted : ${mounted_image_path}"
  exit -1

fi