Created
April 23, 2015 18:52
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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