Skip to content

Instantly share code, notes, and snippets.

View iancd's full-sized avatar

Ian Davidson iancd

  • Edinburgh
View GitHub Profile
@iancd
iancd / macOSuserbackup
Last active October 20, 2020 10:39
Script to backup macOS home folder
#!/bin/bash
# Designed to be run inside the user environment to create a sparse bundle image which contains parity and checksums
# Band size is 256MB
# variables
CONSOLEUSER="$(stat -f %Su /dev/console)" || { echo "`date`: Failed to get username correctly. Exiting"; exit 1; }
# stash and eject previous image if exists
if [ -d "/Volumes/$CONSOLEUSER.sparsebundle" ]; then
/usr/bin/hdiutil eject "/Volumes/$CONSOLEUSER.sparsebundle" || { echo "`date`: Failed to unmount previous image. Try again"; exit 1; }
sleep 10
fi