Skip to content

Instantly share code, notes, and snippets.

@jamessimas
Created June 13, 2025 14:59
Show Gist options
  • Select an option

  • Save jamessimas/a1e7d2f8bc611e43565fe2931e46b405 to your computer and use it in GitHub Desktop.

Select an option

Save jamessimas/a1e7d2f8bc611e43565fe2931e46b405 to your computer and use it in GitHub Desktop.
Backup script for external hard drives
bkexternal () {
HOST=$(hostname -s)
EXT_DRIVE_PATH="/Volumes/RsyncBackupDrive"
if [[ ! -e "$EXT_DRIVE_PATH" ]]; then
echo "Drive path not found: $EXT_DRIVE_PATH"
return 1
fi
# Helpful cheat sheet: https://devhints.io/rsync
rsync -avz --delete --delete-excluded \
--exclude 'Applications' \
--exclude '.DS_Store' \
--exclude '.Trash' \
--exclude 'Library' \
"$HOME/" \
"$EXT_DRIVE_PATH/backup-$HOST"
local return_code=$?
if [[ $return_code -ne 0 ]]; then
return 1
fi
date > "$EXT_DRIVE_PATH/backup-$HOST-last-backup.txt"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment