Last active
January 16, 2026 18:35
-
-
Save bigntallmike/b62497f4810f0bafa20fe5e9b9b558af to your computer and use it in GitHub Desktop.
Personal borg backup script
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
| #!/bin/sh | |
| # | |
| # Obviously substitute for your own: | |
| TARGET="backups@backups:/backups" | |
| # Contains BORG_REPO and BORG_PASSPHRASE, and optionally KEEP_n options seen below | |
| . $HOME/.config/netborgbackup | |
| export BORG_PASSPHRASE | |
| OPTIONS="--stats" | |
| if tty -s; then | |
| OPTIONS="$OPTIONS --verbose --progress" | |
| fi | |
| if [ ! "x$EXCLUDE_LIST" = "x" ]; then | |
| if [ -f "$EXCLUDE_LIST" ]; then | |
| OPTIONS="$OPTIONS --exclude-from=\"$EXCLUDE_LIST\"" | |
| fi | |
| fi | |
| borg create $OPTIONS \ | |
| --one-file-system \ | |
| $TARGET/$BORG_REPO::$(date +%Y%m%d%H%M%S) ./.config | |
| borgret=$? | |
| if [ $borgret -ne 0 ]; then | |
| echo "Backup failed: $borgret" | |
| exit $borgret | |
| fi | |
| KEEP_OPTIONS="" | |
| if [ ! "X$KEEP_DAILY" = "x" ]; then | |
| KEEP_OPTIONS="$KEEP_OPTIONS --keep-daily=$KEEP_DAILY" | |
| fi | |
| if [ ! "x$KEEP_WEEKLY" = "x" ]; then | |
| KEEP_OPTIONS="$KEEP_OPTIONS --keep-weekly=$KEEP_WEEKLY" | |
| fi | |
| if [ ! "x$KEEP_MONTHLY" = "x" ]; then | |
| KEEP_OPTIONS="$KEEP_OPTIONS --keep-monthly=$KEEP_WEEKLY" | |
| fi | |
| borg prune $OPTIONS \ | |
| $KEEP_OPTIONS \ | |
| $TARGET/$BORG_REPO | |
| # To automate, create borgbackup.timer: | |
| # [Unit] | |
| # Description=Run borg backup every night | |
| # [Timer] | |
| # OnCalendar=*-*-* 02:30:00 | |
| # [Install] | |
| # WantedBy=multi-user.target | |
| # | |
| # And borgbackup.service: | |
| # [Unit] | |
| # Description=borg backup service | |
| # [Service] | |
| # Type=oneshot | |
| # ExecStart=/usr/local/sbin/netborgbackup | |
| # These can be in your user systemd folder or /etc/systemd/system/ depending. Then systemctl enable them. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment