The Important Files: Part 5
All notes in this series:
In these notes I configure borg on my FreeNAS jail (named fnbbu
) to automatically backup up every night to both a local repository, and a remote repository at rsync.net.
rsync.net vs Wasabi §
First, a quick comparison of rsync.net and Wasabi on price alone. Note that there are many aspects we could use to compare them (uptime, data center distribution, technical support, etc.) so this is not a well balanced comparison.
Wasabi is $4.99/TB/month with a 1TB minimum. So prices start at $4.99 for 1TB per month.
rsync.net is $0.02/GB/month (using the borg discount) with a 40GB minimum. So prices start at $0.80 for 40GB per month
This means up until the 250GB point, rsync.net is cheaper than Wasabi.
I’m starting at $9.60 (£7.37) for 40GB for a year with rsync.net.
Create borg repository on rsync.net §
NOTE: rsync.net does not permit interactive SSH sessions. We use the -t
option and pass in the command to execute on the remote server, after which stdout is printed and then the session terminates.
Commands here are run from our FreeNAS jail.
First, let’s create a folder on rsync.net for our borg repository (this may or may not be necessary):
Next, we initialise the remote borg repository.
NOTE: if your borg client is 1.x and borg server is 0.x, you may see an error similar to the following. In my case it says the error can safely be ignored.
The remote repository was created successfully.
Set up passwordless SSH login to Rsync.net §
rsync.net provide excellent documentation on how to set up SSH keys to allow passwordless login. Esssentialy, you first generate your key pair:
Then you upload the public key to rsync.net, overwriting the authorized_keys
file:
That’s it! To verify, try running a command over SSH:
Write backup script §
Next we write a script to perform the backup. Following is what I am using:
This script creates a backup and stores it locally, then creates a backup and stores it remotely. It then prunes the local and remote backups. At various points it logs with timestamps.
Copy script into jail §
To get this script inside the jail, I copy it from my laptop at 192.168.0.13
into the jail. I run the scp
command from inside the jail in order to avoid the step of setting up an SSH server inside the jail, since one already runs on my laptop.
Give it execute permissions:
Set borg passphrase in shell §
This section is optional, but it is useful because it will allow you to run borg manually without being prompted for the passphrase each time, e.g. if you want to use borg list
to inspect the repositories.
Let’s set the BORG_PASSPHRASE
environment variable. The fnbbu
jail uses the csh shell by default, so if we store the passphrase in .cshrc
it will be loaded automatically when the shell opens when we log in to the jail.
I append the following line to the existing list of setenv
, using tabs rather than spaces for the gaps, because that is what the others have done.
Test that the script runs manually §
Run the command and verify it works as expected:
Set up cron to run script daily §
Let’s use cron to schedule this script to run daily. Open up crontab for editing:
I’m going to schedule the backup to run at 5 minutes past midnight, every day. Use -x
to get sh
to log debug info (e.g. each command that is executed), and use >> /root/backup.log
to keep a log of the backups in case you want to debug them, or verify they are working as expected.
Check over the next few days and weeks to verify that it is backing up and pruning as expected. Read up on pruning to better understand how it works.
Next up, the most important step of all: verify that you can restore from backup.
Generally helpful links:
- https://localconspiracy.com/2017/10/backup-everything.html
- https://jstaf.github.io/2018/03/12/backups-with-borg-rsync.html
- http://borgbackup.readthedocs.io/en/stable/quickstart.html
- https://opensource.com/article/17/10/backing-your-machines-borg
Possibly useful in future: