Skip to content

Instantly share code, notes, and snippets.

@matthinc
Last active April 4, 2023 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matthinc/6377ddd3686b1660ac4e0b3477b4062e to your computer and use it in GitHub Desktop.
Save matthinc/6377ddd3686b1660ac4e0b3477b4062e to your computer and use it in GitHub Desktop.
Script for using borg-backup with Hetzner storagebox
#!/usr/bin/env bash
########## Configuration ##########
SSH_PASSWD="" # SSH password of the storagebox
BORG_USER="" # Storagebox user
BORG_SERVER="xxx.your-storagebox.de" # Storagebox
BORG_REPO="~/borg" # Borg repository on the storagebox
FILES="/home /opt" # Files to backup (space separated)
###################################
BORG="${BORG_USER}@${BORG_SERVER}:${BORG_REPO}"
ARCHIVE_NAME="$(date)"
export BORG_RSH="sshpass -p $SSH_PASSWD ssh -o StrictHostKeyChecking=no -p 23"
export BORG_PASSPHRASE=""
if [ "$1" == "init" ]; then
borg init -e repokey-blake2 $BORG
fi
if [ "$1" == "delete" ]; then
borg delete $BORG
fi
if [ "$1" == "export_key" ]; then
borg key export $BORG /dev/stdout
fi
if [ "$1" == "run" ]; then
borg create --progress $BORG::"$ARCHIVE_NAME" $FILES
touch /var/last_backup
fi
if [ "$1" == "list" ]; then
borg list $BORG
fi
if [ "$1" == "mount" ]; then
sudo mkdir -p /mnt/borg
sudo chown $(whoami) /mnt/borg
borg mount $BORG /mnt/borg
fi
if [ "$1" == "unmount" ]; then
borg umount /mnt/borg
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment