Backing up using Backblaze B2 and Restic
Mar 29, 2020
Backblaze is a pioneer in robust, scalable low cost cloud backup and storage services. Their B2 service is similar to Amazon's S3 where you have a bucket where you just throw stuff into and pay for the bandwidth and storage used.
The most important difference though is the pricing. Backblaze B2 is quite a bit cheaper than AWS S3.
But this isn't an entirely fair comparison as AWS offers another service next to S3 which is called S3 Glacier. Where S3 is mainly used a data storage that has frequent access to the data, Glacier is the opposite where you store data for long periods that don't get accessed. The use case is to back up data and not access it only in case we ever need to recover it so it makes more sense to compare the pricing with Glacier.
Their price data is quite similar to B2 even slightly cheaper. But there's one giant caviat... It's horrible to use. I've taken a look at it and tried setting it up to take automatic backups but everything regarding Glacier is soooooo badly designed user experience wise. It's such a pain that I just gave up and started looking for something else.
From what I understand people often use S3 as their main data storage and then set lifecycle rules on their data to expire to Glacier. But doing this for a simple file server storage backup feels like you're just bringing in extra costs to do something cool on such a small scale.
To make backing up to B2 easier there's a lot of tools:
- duplicity
- attic
- duplicacy
- restic
It's just a matter of personal preference though which one you would want to use. I've currently settled with restic as my main tool but am open to test others.
The writer of duplicacy did a benchmark which you can read here: https://github.com/gilbertchen/benchmarking/blob/master/README.md. Unsure if those results are still the same though with the newer versions of the tools.
To easen backing up I just wrote a simple bash script to run through a cronjob every now and then.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/usr/bin/env bash echo "[LOG] Starting backup script at $(date)" # Additional restic options OPTIONS="--option b2.connections=50" # Iterate over directories and perform separate snapshots per dir dirs_to_backup=( /foo /bar ) for dir in "${dirs_to_backup[@]}" do echo "[LOG] Creating backup of directory: ${dir}" /usr/local/bin/restic ${OPTIONS} backup $dir done # Iterate over files and perform separate snapshots per file files_to_backup=( /foo/bar.yml ) for file in "${files_to_backup[@]}" do echo "[LOG] Creating backup of file: ${file}" /usr/local/bin/restic ${OPTIONS} backup $file done # Clean up and only keep the last snapshots available echo "[LOG] Cleaning up" /usr/local/bin/restic ${OPTIONS} forget --keep-last 1 --prune
For more information on Backblaze B2: https://backblaze.com/b2/cloud-storage.html For more information of Restic: https://github.com/restic/restic