Restic and Backblaze B2 for backups

Posted on April 18, 2018 in software

restic

I have been using restic for the past two weeks. Restic is the backup tool I wished for, but had not realized it already existed!

Here's how I'm using it:

Tested on:

  • MacOS El Capitan, FreeBSD 11.1
  • bash

Install ( read-the-docs ):

$ brew install restic  # MacOS
$ pkg install restic  # FreeBSD

Sign-up for or provision remote storage ( options supported by restic ):

I am using Backblaze B2 since it allows backing up multiple machines to the same repo, while restic does the deduplicating and encryption before uploading part.

B2 is inexpensive and fast and I found it very simple to set up. Let's say you could get restic+B2 up and running possibly in less time than it takes to only read through the instructions to perform the same actions on AWS.

Configure the remote storage repo ( docs ):

$ nano ~/.restic

    export B2_ACCOUNT_ID="<account-id>"
    export B2_ACCOUNT_KEY="<account-key>"
    export RESTIC_PASSWORD="<encryption-password>"
    export RESTIC_REPOSITORY="<remote-repo>"

$ chmod 600 ~/.restic

If you intend to back up source code directories, excluding cache folders might appeal to you. Let us make a shell script to automate remembering that.

If you don't have a private binaries folder, create one:

$ mkdir -p ~/.bin/

Create a bash script with the content:

$ nano ~/.bin/backup.sh

    #!/usr/bin/env bash
    source ~/.restic
    restic backup `pwd` \
        --exclude=__pycache__ \
        --exclude=.git      

Make it executable:

$ chmod +x backup.sh

Add the private bin folder to $PATH environment variable, assuming bash.

$ echo 'export PATH="~/.bin:$PATH"' >> ~/.bash_profile

Now you can execute $ backup.sh in any directory to back it up securely.

coughprotipcough. I am not entirely sure if this is a good idea, but so far so good!

$ ln -s ~/.bin/backup.sh ~/.bin/,,

$ cd directory-to-backup

$ ,,<ENTER>

ta-da!

Restoring specific files is quite straightforward too:

Imagine you want to restore a file named fabfile.py

$ restic find fabfile.py
Found matching entries in snapshot [SNAPSHOT-ID]
/example/project/fabfile.py

$ restic restore [SNAPSHOT-ID] --target /tmp/phew --include /example/project/fabfile.py

It will be saved as /tmp/phew/example/project/fabfile.py

That's all there is for basic usage!