Important data is backed up to Backblaze B2 using restic. This file describes the general configuration, individual systems may introduce certain changes, though. Check the docs for those systems.
First, create a new bucket (private, disable object lock). Then on the Application Keys page, create a new key (only allow access to the bucket in question, read/write).
Then, create a file ~/env-restic-b2.sh
like so:
export RESTIC_REPOSITORY=b2:<bucket name>:restic-repo
export RESTIC_PASSWORD=123
export B2_ACCOUNT_ID=abc # Choose a new password and save it in 1Password.
export B2_ACCOUNT_KEY=def
Run:
apt install restic
source ~/env-restic-b2.sh
restic init
Create a file ~/backup-restic-b2.sh
like so:
#!/bin/bash
set -e
source /root/env-restic-b2.sh
# Optional: Run a backup script or similar here.
BACKUPDIR="<full path to folder>"
restic backup "$BACKUPDIR"
rm -rf "$BACKUPDIR"
Create a file ~/housekeeping-restic-b2.sh
like so, optionally modifying the numbers:
#!/bin/bash
set -e
source /root/env-restic-b2.sh
restic forget --prune --keep-last 7 --keep-daily 7 --keep-weekly 8 --keep-monthly 3 --keep-yearly 2
restic check
Make the scripts executable (chmod +x ~/backup-restic-b2.sh && chmod +x ~/housekeeping-restic-b2.sh
).
Do a test run of the backup script: ~/backup-restic-b2.sh
And the cleanup script: ~/housekeeping-restic-b2.sh
Create two new checks on healthchecks.io. Then, add the following lines to the crontab using crontab -e
but set different times:
30 5 * * * m=$(/root/backup-restic-b2.sh 2>&1) ; curl -fsS -m 30 --retry 5 --data-raw "$m" https://hc-ping.com/<healthcheck_ID_1>/$?
00 8 * * 2 m=$(/root/housekeeping-restic-b2.sh 2>&1) ; curl -fsS -m 30 --retry 5 --data-raw "$m" https://hc-ping.com/<healthcheck_ID_2>/$?