Example Portable Mac Backup Script

Whipped up a little backup script I can use on random machines I don’t typically backup. It has a fancy little ASCII art logo, sets variables, allows you to drag and drop folders/files, figures out if you’re on an M1 Mac or not, checks for internet connectivity and self-updates if so, backs up while setting the machine name (I don’t like the .local at the end, so I used scutil) and tagging the username, then ejects the drive.

I’m backing up local, but you could just as easily do remote, and utilize Rclone, which I included update commands for.

#!/bin/bash
clear
# Calvin S from https://patorjk.com/software/taag/
cat << "EOF"                                             
╦╔╗╔╔═╗╔═╗╦═╗╔╦╗  ╔═╗╔═╗╔═╗╦╦  ╔═╗╦═╗╔╦╗  ╦ ╦╔═╗╦═╗╔═╗
║║║║╚═╗║╣ ╠╦╝ ║   ╠═╣╚═╗║  ║║  ╠═╣╠╦╝ ║   ╠═╣║╣ ╠╦╝║╣ 
╩╝╚╝╚═╝╚═╝╩╚═ ╩   ╩ ╩╚═╝╚═╝╩╩  ╩ ╩╩╚═ ╩   ╩ ╩╚═╝╩╚═╚═╝
EOF
echo

# Set variables
export RESTIC_REPOSITORY=/Volumes/YOUR_DRIVE_NAME_HERE/db/
export RESTIC_PASSWORD=
export RESTIC_COMPRESSION=auto
export RESTIC_PACK_SIZE=128

# Input paths
echo 'Drag and drop files and paths here: '
echo
read PATHS
echo

# Determine architecture
if [ $( uname -m ) = x86_64 ]; then
	RESTIC="/Volumes/YOUR_DRIVE_NAME_HERE/bin/restic_amd64"
	RCLONE="/Volumes/YOUR_DRIVE_NAME_HERE/bin/rclone_amd64"
elif  [ $( uname -m ) = arm64 ]; then
	RESTIC="/Volumes/YOUR_DRIVE_NAME_HERE/bin/restic_arm64"
	RCLONE="/Volumes/YOUR_DRIVE_NAME_HERE/bin/rclone_arm64"
else
	echo Architecture not detected, quitting... && exit
fi
echo

# Update
if [ $( ping -c 1 www.restic.net | grep icmp* | wc -l ) -eq 1 ]
then
	$RESTIC self-update
	$RCLONE self-update
fi

# Backup
$RESTIC backup -H "$(scutil --get ComputerName)" --tag "$USER" --iexclude-file "/Volumes/YOUR_DRIVE_NAME_HERE/etc/excludes.txt" "$PATHS"
echo

# Eject
ECHO Ejecting in 30 seconds, press [CTRL+C] to skip, or press [Enter] to exit now...
read -n 1 -t 30
osascript -e 'tell application "Finder" to eject "YOUR_DRIVE_NAME_HERE"'