Last active
September 19, 2021 07:06
-
-
Save JonathanWThom/2a42c3dd5ac86b2a8c93572767377a35 to your computer and use it in GitHub Desktop.
Sample backup script using Borg (with optional Rclone sync)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Backup a folder to a remote address using borg. | |
# To restore: borg extract $BORG_REPO::computer-and-date | |
set -eu | |
# Will need a remote server setup with Borg, and a Borg repo first. | |
export BORG_REPO="<user>@<host>:<borg-repo>" | |
# Assuming you've installed Borg with Homebrew | |
export BORG_REMOTE_PATH=/usr/bin/borg | |
# Not 100% necessary, but you can save your borg passphrase in MacOS Keychain | |
# security add-generic-password -a $LOGNAME -s borg-passphrase -w <your-borg-passphrase> | |
export BORG_PASSPHRASE=$(security find-generic-password -w -a $LOGNAME -s borg-passphrase) | |
# optionally include Rclone sync with configuration password | |
# security add-generic-password -a $LOGNAME -s rclone-configuration -w <your-rclone-configuration-password> | |
RCLONE_CONFIGURATION_PASSWORD=$(security find-generic-password -w -a $LOGNAME -s rclone-configuration) | |
/usr/local/bin/borg create -s --progress ::"$(hostname)-$(date)" ~/directory-to-backup ~/another-directory | |
/usr/local/bin/borg prune --keep-daily=14 --keep-monthly=6 | |
# optionally include Rclone sync | |
# requires having an Rclone remote setup on your server first. | |
# If you haven't password protected the configuration, you can leave out the variable. | |
ssh user@host /bin/bash <<EOT > /dev/null | |
rclone sync --config=/path/to/rclone/config <borg-repo> <rclone-remote>:<rclone-remote-dir> <<< $RCLONE_CONFIGURATION_PASSWORD | |
EOT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment