Skip to content

Instantly share code, notes, and snippets.

@macro
Created April 23, 2015 18:52
Show Gist options
  • Save macro/39345323fea291b751eb to your computer and use it in GitHub Desktop.
Save macro/39345323fea291b751eb to your computer and use it in GitHub Desktop.
Simple bash script to stop time machine backup and eject the disk (assumes time machine disk is disk id 3)
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
ts () {
echo "$(python -c 'import datetime; print datetime.datetime.now().isoformat()')"
}
TM_DISK=disk3
if [ $# -gt 0 ] && [ "$1" != "" ]; then
TM_DISK="$1"
fi
# set -x
TM_UTIL=/usr/bin/tmutil
DISK_UTIL=/usr/sbin/diskutil
echo "[$(ts)] Stopping timemachine ..."
${TM_UTIL} stopbackup
echo "[$(ts)] Unmounting volumes ..."
sudo ${DISK_UTIL} unmountDisk force ${TM_DISK}
echo "[$(ts)] Ejecting disk ..."
sudo ${DISK_UTIL} eject ${TM_DISK}
echo "[$(ts)] Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment