Install restic first before proceeding with any configuration or backup setup. I am including fuse as it seems to be required for BackBlaze integration to work correctly — without it, you may encounter errors or missing functionality when attempting to mount or interact with your BackBlaze storage backend. Make sure both packages are installed and available on your system before moving on to the next steps.
sudo apt install restic fuse && sudo restic self-update
Create a .restic-env file and set perms to 600.
nano ~/.restic-env && chmod 600 ~/.restic-env
Content example
export B2_ACCOUNT_ID="xxx"
export B2_ACCOUNT_KEY="xxx"
export RESTIC_REPOSITORY="b2:xxxx"
export RESTIC_PASSWORD="xxxxx"
export RESTIC_COMPRESSION="off"
export RESTIC_READ_CONCURRENCY=10
Put in your own Backblaze ID, key and bucket in along with an auto-generated restic password.
I’d recommend you make a new bucket and application key per server.
You can make a random password with the following command
openssl rand -hex 32
Initially, we need to create some bits
source .restic-env
restic init
This will initialise the restic repository at Backblaze.
Now we can do our script that we will run on a regular basis.
Create backup.sh.
nano backup.sh && chmod a+x backup.sh
Here’s an example I use on my Laravel Forge servers
#!/bin/bash
set -e
source .restic-env
restic unlock
restic backup /home/*/ --exclude wp-content/cache/ --exclude .git/ --exclude .bash_history --exclude .cache/ --exclude .ssh/ --exclude .local/
restic forget --keep-daily 7 --keep-monthly 1 --prune
restic cache --max-age 7
restic check --read-data
curl -s 'https://some.healthcheck.service' > /dev/null
The last line is optional. At LWD we have our own Uptime Kuma that we push to – it will alert us if the backup fails to run
Run it to test it, then schedule it as per your liking.