Skip to content

Instantly share code, notes, and snippets.

@gvlx
Created October 20, 2013 11:06
Show Gist options
  • Save gvlx/7068106 to your computer and use it in GitHub Desktop.
Save gvlx/7068106 to your computer and use it in GitHub Desktop.
A bash script to create a time machine disk image suitable for backups with OS X 10.6 (Snow Leopard)
#!/bin/bash
# A bash script to create a time machine disk image suitable for
# backups with OS X 10.6 (Snow Leopard)
# This script probably only works for me, so try it at your own peril!
# Use, distribute, and modify as you see fit but leave this header intact.
# (R) sunkid - September 5, 2009
#
# retrived from http://www.insanelymac.com/forum/topic/184462-guide-106-snow-leopard-time-machine-backup-to-network-share/
# http://www.insanelymac.com/forum/index.php?app=core&module=attach&section=attach&attach_id=55807
# 2013 10 16 2310 GMT+0 DST
#
# ioreg info retrieved from http://www.jaharmi.com/2008/03/15/get_uuid_for_mac_with_ioreg
# 2013 10 20 1202 GMT+0 DST
usage ()
{
echo ${errmsg}"\n"
echo "makeImage.sh"
echo " usage: makeImage.sh size [directory]"
echo " Create a disk image with a max storage size of <size> and copy it"
echo " to your backup volume (if specified)"
}
# test if we have two arguments on the command line
if [ $# -lt 1 ]
then
usage
exit
fi
# see if there are two arguments and we can write to the directory
if [ $# == 2 ]
then
if [ ! -d $2 ]
then
errmsg=${2}": No such directory"
usage
exit
fi
if [ ! -w $2 ]
then
errmsg="Cannot write to "${2}
usage
exit
fi
fi
SIZE=$1
DIR=$2
NAME=`scutil --get ComputerName`;
#UUID=`system_profiler | grep 'Hardware UUID' | awk '{print $3}'`
UUID=$(ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { gsub(/"/,"",$3); print $3;}')
# get busy
echo -n "Generating disk image ${NAME}.sparsebundle with size ${SIZE}GB ... "
hdiutil create -size ${SIZE}G -fs HFS+J -type SPARSEBUNDLE \
-volname 'Time Machine Backups' "${NAME}.sparsebundle" >> /dev/null 2>&1
echo "done!"
echo -n "Generating property list file with uuid $UUID ... "
#PLIST=$( cat <<EOFPLIST
cat <<EOFPLIST > "${NAME}.sparsebundle"/com.apple.TimeMachine.MachineID.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.backupd.HostUUID</key>
<string>$UUID</string>
</dict>
</plist>
EOFPLIST
echo $PLIST > "${NAME}.sparsebundle"/com.apple.TimeMachine.MachineID.plist
echo "done!"
if [ $# == 2 ]
then
echo -n "Copying ${NAME}.sparsebundle to $DIR ... "
cp -pfr "${NAME}.sparsebundle" $DIR/"${NAME}.sparsebundle"
echo "done"
fi
sudo defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1
echo "Finished! Happy backups!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment