Using an encrypted sparse bundle as a time machine destination

kadams
Contributor

Hey guys i've been back and fourth doing this project. I am getting an error with after running this script. Everything runs fine and then the sparsebundle fails to begin backing up. The error is unable to get status of backup disk. Here are the commands that I put together.

LOGGED_IN_USER=$(stat -f%Su /dev/console)

if [[ ! -e /Volumes/QTimeMachineBackups ]]; then
  mkdir -p /Volumes/QTimeMachineBackups
fi

if [[ ! -e /Volumes/QTimeMachineBackups/$LOGGED_IN_USER.sparsebundle ]]; then
  mount -t afp 'afp://Time_Machine_User:Password/QTimeMachineBackups' /Volumes/QTimeMachineBackups
fi

#Creates encrypted sparsebundle  on Synology that gives itself a name based on account username

if [[ ! -e /Volumes/QTimeMachineBackups/$LOGGED_IN_USER.sparsebundle ]]; then
  /usr/bin/printf 'password' | /usr/bin/hdiutil create -size 200g -volname "$LOGGED_IN_USER" -encryption AES-256 -type SPARSEBUNDLE -fs "HFS+J" -stdinpass "/Volumes/QTimeMachineBackups/$LOGGED_IN_USER"
fi


#Mounts the NAS sparsebundle based on specific user
if [[ ! -e /Volumes/QTimeMachineBackups/$LOGGED_IN_USER.sparsebundle ]]; then
  /usr/bin/printf 'password' | /usr/bin/hdiutil attach -stdinpass /Volumes/QTimeMachineBackups/$LOGGED_IN_USER.sparsebundle
fi


#Sets specific users sparse bundle as a time machine destination 

umount -f /Volumes/QTimeMachineBackups
tmutil setdestination -a "afp://Time_Machine_User:Password/QTimeMachineBackups/$LOGGED_IN_USER.sparsebundle"
#tmutil setdestination /Volumes/QTimeMachineBackups/$LOGGED_IN_USER.sparsebundle 

#Makes Backup Speed Increase


sysctl debug.lowpri_throttle_enabled=0

#Enables automatic backups

tmutil enable

#Starts backups

tmutil startbackup
)
5 REPLIES 5

mm2270
Legendary Contributor III

@kadams I'm sure there's a solution here to get this working. To start with, so it's easier to digest, can you edit your post and surround your script with the script tags? Either add a ``` to the top and bottom of the script, or highlight the whole script and click the >_ button in the post editing toolbar.

mm2270
Legendary Contributor III

Off the top of my head, one possible problem I see is with this line

tmutil setdestination -a "afp://Time_Machine_User:Password/QTimeMachineBackups/$LOGGED_IN_USER.sparsebundle"

I may be wrong, but I don't believe you should include the .sparsebundle extension in the path name. I think tmutil needs a standard mount path for this command, which would not have a file extension on it. When any DMG is mounted, sparsebundle or not, it just has a volume name, no extension included.
One way to test this would be to see if the above path of QTimeMachineBackups/$LOGGED_IN_USER.sparsebundle (replacing $LOGGED_IN_USER with the actual name) resolves in the Terminal. It you can't navigate to that path in Terminal when the sparse bundle is mounted, then that might be the problem. If so, try dropping the .sparsebundle extension and use the path without it to see if there's an improvement.

kadams
Contributor

@mm2270 , I changed it and it still doesn't work.

kadams
Contributor

Finally got it to work!

kadams
Contributor

@mm2270 The computer rebooted and gave me the prohibitory symbol after restoring from time machine.