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
Any Comments ?
sha256: 7ef0f27083824782021d670e36e682ab9ca52fca87c70532a902077b485e7568