Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to automate the creation of an encrypted sparsebundle and configure backup for a 10.7 machine using a TimeCapsule. I've created the script below

read -p "This should create an encypted sparse bundle and save it to the timecapsule share. It should then configure your Timecapsule with the appropriate settings. Before you begin browse to your timecapsule/backup device and if requested save the password to the keychain." -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
echo -e "\n\n\n\nWhat is the name of your Time Capsule or Device you are backing up to ?"
echo -e "\n\n\nI will use /Volumes/$CAPSULE\n\n\n"
echo -e "\n\n\nWhat is the Username for the device? \n\n\n"
#echo -e "\n\n\nWhat is the PASSWORD for the device? \n\n\n"
echo -e "\n\n\nLets get going .....\n\n\n"
NAME=$(system_profiler | sed -ne 's/.*Computer Name://p' | sed 's/^[ \t]*//')
SERIAL=$(system_profiler | sed -ne 's/Serial Number (system)://p' | sed 's/^[ \t]*//')
DISK=$(df -lh |grep /dev/disk | awk '{ print $2*1.5}')
#Serial number for the salt and then hash the NAME
PASSWORD=$(echo "$SERIAL":"$NAME" | openssl sha1)
#Find the primary disk size then create the sparesebundle 1.5 times larger.
echo -e "\n\n\n\nAbout to begin creating and encrypting the sparsebundle.\n\n\n"
printf $PASSWORD | hdiutil create -encryption AES-128 -stdinpass -size "$DISK"g -volname "bob" "/Volumes/$CAPSULE/$NAME.sparsebundle" -fs HFS+J -type SPARSEBUNDLE
#echo -e "\n\n\nAbout to mount the sparsebundle.\n\n\n\n"
#printf $PASSWORD |hdiutil attach -encryption AES-128 -stdinpass -mountpoint #"/Volumes/Loosing_it" "/Volumes/$CAPSULE/$NAME.sparsebundle"
#Turn on Timemachine
echo -e "\n\n\nAbout to enable Time Machine. If prompted for a password put in your user password.\n\n\n"
sudo /usr/bin/tmutil enable
sleep 5
#echo -e "\n\n\nAbout to enable Local Snapshots.\n\n\n"
#Enable local snapshots
sudo /usr/bin/tmutil disablelocal
sleep 15
#Set the destination to wherever
echo -e "\n\n\nAbout to configure the backup destination.\n\n\n"
sudo /usr/bin/tmutil setdestination -p "afp://$USERNAME@$CAPSULE._afpovertcp._tcp.local/$CAPSULE/$NAME.sparsebundle"
sudo /usr/bin/tmutil snapshot "/Volumes/bob"
sleep 5
#Make sure only backups if plugged in.
sudo /usr/bin/defaults write /Library/Preferences/ RequiresACPower 0
#Start backup
echo -e "\n\n\nAbout to run the first backup.\n\n\nThis will most likely take\n\n\na few hours\n\n\n"
sudo /usr/bin/tmutil startbackup > /dev/null
echo -e "This is your password.\n\n\n$PASSWORD\n\n\nThis is the password that was used to setup your encryption. You will now need to enter it into your keychain so backups can be encrypted.\n\n\n\n" > ~/Desktop/"$NAME"_Password.txt
echo -e "\n\n\nThis is your password.\n\n\n"$(tput setaf 1)$PASSWORD$(tput sgr0)"\n\n\nThis is the password that was used to setup your encryption. You will now need to enter it into your keychain so backups can be encrypted.\n\n\n\nSave the "$NAME"_Password.txt file somewhere safe in case you need it."

The script creates the sparsebundle to the share. It encrypts it. I'm able to restore from "Enter Timemachine" (On the right hand side my recovery points are pink, I think that is remote backups?), the available space on the share gets smaller i.e. data is being saved there.

However if I double click on the sparsebundle the disk that mounts is empty? If I try and restore from the recovery partition I'm prompted to put in my encrypted password but again there's no backups?

What have I done wrong?

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.