Borg

Page content

BorgBackup

how do you backup your data … ? a really cool solution is borgbackup.

BorgBackup (short: Borg) gives you:

  • Space efficient storage of backups
  • Secure, authenticated encryption.
  • Compression: LZ4, zlib, LZMA, zstd (since borg 1.1.4).
  • Easy installation on multiple platforms: Linux, macOS, BSD, …
  • Free software (BSD license).
  • Backed by a large and active open source community.

Always a good Idea is to keep a Backup external. Rsync.net has a really competitve Offer (without Support). 100 GB for $18/year.

Install Borgbackup

pkg_add borgbackup

Generate KeyPair

mkdir /backup
ssh-keygen -o -a 100 -t ed25519 -C '"My Rsync Key"' -f /backup/id_ed25519_rsync-net

Public Key

you need to create an account at rsync.net (or wherever you want) and put your public key (/backup/id_ed25519_rsync-net.pub) to the .ssh/authrorized_key file

Backup Script

cat << 'EOF' > /backup/borgbackup.sh
#!/bin/sh

# Vars
_app="myborgrepo"
_rsync_user="RSYNC-USER-ID"
_rsync_host="RSYNC-HOSTNAME"
_passphrase="MY-TOP-SECRET-PASSPHRASE"

_host=$(hostname)
_date=$(date +"%Y%m%d-%H%M")

# Exports
export BORG_RSH='ssh -i /backup/id_ed25519_rsync-net'
export BORG_PASSPHRASE="${_passphrase}"
export BORG_REMOTE_PATH=borg1
export repo="${_rsync_user}@${_rsync_host}:${_app}"


## Hints ##

# Create Repo
#borg init -e repokey-blake2 ${repo}

# List Repo
#borg list ${repo} |grep ${_host}

# Show Last Backup
#borg list ${repo} |grep ${_host} |head -1 |awk '{print $1}'

# Restore File from last Backup
#borg extract ${repo}::`borg list ${repo} |grep ${_host} |head -1 |awk '{print $1}'` etc/hosts


# Do Backup
/usr/local/bin/borg create --compression lz4 -e keyfile ${_param} ${repo}::${_host}-${_date} \
        / \
        --exclude "*.pyc" \
        --exclude "*__pycache__*" \
        --exclude "/mnt" \
        --exclude "/tmp"

# Do Cleanup
/usr/local/bin/borg prune -v --list ${repo} --prefix ${_host} \
        --keep-hourly=2 \
        --keep-daily=8 \
        --keep-weekly=5 \
        --keep-monthly=13 \
        --keep-yearly=3

# Done
exit 0
EOF

chmod 700 /backup/borgbackup.sh

you can now start your first backup by hand: ./backup/borgbackup and then add cronjob and run it daily

Problems

on Debian 12.2, i got the following Error Message when running Borgbackup

You do not have a supported version of the msgpack python package installed. Terminating. This should never happen as specific, supported versions are required by our setup.py. Do not contact borgbackup support about this.

Solution

Downgrade msgpack from 1.0.7 to 1.0.3 (both were installed, 1.0.3 through ‘apt-get install’, 1.0.7 through ‘pip install …’)

# Remove Lock
root@docker:~# mv /usr/lib/python3.11/EXTERNALLY-MANAGED /usr/lib/python3.11/EXTERNALLY-MANAGED.old

# Uninstall Package
root@docker:~# pip3 uninstall msgpack
Found existing installation: msgpack 1.0.7
Uninstalling msgpack-1.0.7:
  Would remove:
    /usr/local/lib/python3.11/dist-packages/msgpack-1.0.7.dist-info/*
    /usr/local/lib/python3.11/dist-packages/msgpack/*
Proceed (Y/n)? y

# run borg
/backup/borg_backup.sh

Any Comments ?

sha256: 7ef0f27083824782021d670e36e682ab9ca52fca87c70532a902077b485e7568