Skip to content

Instantly share code, notes, and snippets.

@eproxus
Created April 11, 2022 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eproxus/e03dfaf8eb3ab7506244019e03495a33 to your computer and use it in GitHub Desktop.
Save eproxus/e03dfaf8eb3ab7506244019e03495a33 to your computer and use it in GitHub Desktop.
OP-Z Automated Backup on macOS

OP-Z Automated Backup for macOS

Setup

  1. Store backup.sh somewhere and make it executable:

    $ vim ~/Music/OP-Z/Backups/Support/backup.sh

    (The file opz_backup.sh is only needed as a convenience shortut to manually run the backup)

  2. Store local.opzbackup.plist at ~/Library/LaunchAgents:

    $ vim ~/Library/LaunchAgents/local.opzbackup.plist

    Update the keys SOURCE, TARGET, Program, StandardOutPath and StandardErrorPath to match your desired locations.

  3. Open System PreferencesPrivacyFull Disk Access and add your sh binary to the list (/bin/sh) or if it is already there, enable the checkbox.

  4. Load the launch agent:

    $ launchctl load ~/Library/LaunchAgents/local.opzbackup.plist

Backups should now be automatically performed when connecting the OP-Z as a mounted disk (by connecting it over USB and pressing and holding the track button while turning the device on).

#!/bin/sh
set -e -x
if [ -z "$SOURCE" ]; then
echo "$(date '+%Y-%m-%d_%H-%M-%S'): Need to set SOURCE"
exit 1
fi
if [ -z "$TARGET" ]; then
echo "$(date '+%Y-%m-%d_%H-%M-%S'): Need to set TARGET"
exit 1
fi
if [ ! -d "$SOURCE" ]; then
echo "$(date '+%Y-%m-%d_%H-%M-%S'): $SOURCE not found, skipping backup"
exit 0
fi
if [ ! -d "$TARGET" ]; then
echo "$(date '+%Y-%m-%d_%H-%M-%S'): $TARGET missing, aborting backup"
exit 1
fi
/usr/bin/rsync \
--recursive \
--partial \
"$SOURCE"/* \
"$TARGET/$(date '+%Y-%m-%d_%H-%M-%S')"
echo "$(date '+%Y-%m-%d_%H-%M-%S'): Backup successful!"
osascript -e 'display notification "Backup completed succesfully!" with title "OP-Z"'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>SOURCE</key>
<string>/Volumes/OP-Z</string>
<key>TARGET</key>
<string>/Users/user/Music/OP-Z/Backups</string>
</dict>
<key>Label</key>
<string>local.opzbackup</string>
<key>Program</key>
<string>/Users/user/Music/OP-Z/Backups/Support/backup.sh</string>
<key>StartOnMount</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/user/Music/OP-Z/Backups/Support/backup.stdout</string>
<key>StandardErrorPath</key>
<string>/Users/user/Music/OP-Z/Backups/Support/backup.stderr</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment