Skip to content

Instantly share code, notes, and snippets.

@ahmadawais
Created February 26, 2018 15:36
Show Gist options
  • Save ahmadawais/a5c2b8121bad027a5d59fe9df6e54c45 to your computer and use it in GitHub Desktop.
Save ahmadawais/a5c2b8121bad027a5d59fe9df6e54c45 to your computer and use it in GitHub Desktop.
MAC: Backup script
# Rsync based backup for Mac.
# .
# Usage: bk ~/path/to/backup/
# E.g. bk ~/Documents/Audio will create /Volumes/AhmadAwais.com/Z-BACKUPS/Users/Documents/Audio backup.
function bk() {
# Halt the script on any errors.
set -e
echo "-"
# -a is archive mode so it keeps your original created and modified properties.
# -v is verbose mode to get a bit of extra output (useful for debugging).
# -R is relative mode. It ensures the included paths get created on the target.
RS_PARAM="-avR"
# The input from user.
BK_SRC="$1"
# Your backup HDD's volume path.
BK_DST="/Volumes/AhmadAwais.com/Z-BACKUPS/"
echo "—————————————————————————————"
echo "➤ Backing up "$1" :"
echo "—————————————————————————————"
# The progress bar can be improved. But it works.
rsync "$RS_PARAM" --exclude="node_modules" --exclude=".git" "$BK_SRC" "$BK_DST" |\
pv -lep -s $(rsync "$RS_PARAM"n --exclude="node_modules" --exclude=".git" "$BK_SRC" "$BK_DST" | awk 'NF' | wc -l)
echo "-"
echo "--------------- ✔︎✔︎✔︎ DONE!!! 💯 🎉 ✔✔✔ ---------------"
echo "-"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment