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
)