-
-
Save bonelifer/c1f032cc8d7d97b34b9961e6477c5239 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env bash | |
set -o errexit # Exit on most errors | |
set -o nounset # Dissallow expansion of unset variables | |
DISK=/media/backup | |
export BORG_PASSPHRASE="$(pass borg)" | |
BORG_REPOSITORY="$DISK/borg" | |
# DESC: notify the user that backups are done | |
# ARGS: none | |
function notify() { | |
BORG_PUSHOVER_USER="$(pass borg-pushover-user)" | |
BORG_PUSHOVER_TOKEN="$(pass borg-pushover-token)" | |
# Pushover app | |
curl -s \ | |
--form-string "token=$BORG_PUSHOVER_TOKEN" \ | |
--form-string "user=$BORG_PUSHOVER_USER" \ | |
--form-string "message=Your backups are completed" \ | |
https://api.pushover.net/1/messages.json | |
zenity --info --text='Backup complete!' | |
} | |
# DESC: Unmount the given disk | |
# ARGS: Disk to unmount | |
function unmount() { | |
devmon --unmount "$1" | |
} | |
# DESC: prune the archive to reduce consumed disk space | |
# ARGS: location of archive | |
function prune_backup_archive() { | |
# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly | |
# archives of THIS machine. The '{hostname}-' prefix is very important to | |
# limit prune's operation to this machine's archives and not apply to | |
# other machine's archives also. | |
borg prune -v "$1" --prefix '{hostname}-' \ | |
--keep-daily=7 --keep-weekly=4 --keep-monthly=6 &>>"$HOME/backup.log" | |
} | |
# DESC: make new backup archive for the day | |
# ARGS: location of backup repository | |
function create_backup_archive() { | |
# Backup all of $HOME except a few excluded directories | |
borg create --verbose --stats --progress \ | |
--compression lzma,9 \ | |
"$1"::'{hostname}-{now:%Y-%m-%d}' \ | |
"$HOME" \ | |
--exclude "$HOME/code" \ | |
--exclude "$HOME/.cache" \ | |
--exclude "$HOME/Dropbox" \ | |
--exclude "$HOME/.rustup" \ | |
--exclude "$HOME/.cargo" \ | |
--exclude "$HOME/backup.log" \ | |
--exclude '*tags' \ | |
--exclude '*.pyc' \ | |
--exclude '*.class' \ | |
--exclude '*.com' \ | |
--exclude '*.dll' \ | |
--exclude '*.exe' \ | |
--exclude '*.o' \ | |
--exclude '*.so' \ | |
--exclude '*.beam' \ | |
--exclude-caches \ | |
--exclude-if-present '.git' &>>"$HOME/backup.log" | |
} | |
create_backup_archive "$BORG_REPOSITORY" | |
prune_backup_archive "$BORG_REPOSITORY" | |
unmount "$DISK" && notify |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment