How to configure Backblaze B2 with Restic on Linux

Restic is a multi-platform command line backup software program that is designed to be fast, efficient, and secure. Restic supports a variety of backends for storing backups, including a local server, SFTP server, HTTP Rest server, and a number of cloud storage providers, including Backblaze B2.

Files are uploaded to a B2 bucket as de-duplicated, encrypted chunks. Each time a backup runs, only changed data is backed up. On each backup run, a snapshot is created enabling easy restores to a specific date or time.

The location where the backup data is stored is assumed to not be a trusted environment, such as a shared space where others could possibly access the backups. To guarantee the confidentiality and integrity of the backed up data, Restic uses cryptography to protect it.

Restic is open source and free software and licensed under the BSD 2-Clause License and actively developed on GitHub.

Getting Started with Restic and Backblaze B2

This guide is intended to get you started with Restic and begin using the basic commands to do a full backup and restore of a specific folder to Backblaze B2.

There are many more options than we cover here and opportunities to streamline and automate the process through shell scripts and other means. You can find more information on using Restic at


Being a relatively new program, Restic is not yet widely available from Linux distribution repositories. It is becoming more popular, so likely that will change. You should check whether it is possible to install Restic using your standard distribution package management tools, such as apt, yum, and dnf.

In any case, you can download a number of the latest pre-compiled binaries from the Restic release page.

Our examples use the Ubuntu Linux distribution. On that platform we needed to download the binary from the release page and install it.

As we will be installing Restic on Ubuntu 16.04, we will select the AMD64 pre-compiled binary.


Download it to your system.


Once in our downloads folder, we can extract the binary using the Archive Manager.

The binary file can be placed anywhere in the path for the current system or user. In this example, it is placed in /home/roderick/bin. Update the binary to make it executable by the user with the chmod command, such as:

$ chmod u+x restic_0.9.2_linux_amd64

(using the exact name of the binary you downloaded and extracted).

Change the name of the executable binary to restic.

$ mv restic_0.9.2_linux_amd64 restic

Verify that Restic is available by typing “restic version” in the terminal.


Create Backblaze account with B2 enabled

If you don’t have a Backblaze account, you need to create a Backblaze account and enable B2. If you already have a Backblaze account, login, visit "My Settings" and enable "B2 Cloud Storage" on your account under "Enabled Products.” 


Second, create an Private bucket in your B2 account. (Or, you can do this directly from Restic. See Initialize the Restic Repository below.)


Note that the bucket name must be unique across all of B2, not just your account.

Third, retrieve your account id and application key. You will need to specify these in Restic to perform backups and restores. 

Performing a backup of your home directory

Restic can use environment variables to make it easier to use the command line. Use the account ID and application key you obtained from your B2 account. If you wish, you can set these as environment variables so you don't have to enter them with every command. You can export them in your .bashrc file or other place of your choosing so they’re available whenever you type a restic command. 


In case you want to use Backblaze Application keys, replace <MY_ACCOUNT_ID>
and <MY_SECRET_ACCOUNT_KEY> with <applicationKeyId> and <applicationKey>
respectively. See Application Keys for more information.

You also can specify the name of the B2 bucket in an environment variable. In these examples, the bucket is called "my-restic-backup". As it is located on B2, it has a b2: prefix.

$ export RESTIC_REPOSITORY="b2:my-restic-backup"

If you do that, you don't need to enter the "-r <repo string>" parameter every time you enter a Restic command. In the examples below, we'll assume the account ID and application key are in environment variables, but we'll specify the -r repository parameter each time for clarity.

Each time you enter a Restic command, you will be asked for your repository password. You will need to enter that or store the password in a file and retrieve it with the -p parameter. Or, you can use an environment variable to store the name of the password file and it will be used automatically.

$ export RESTIC_PASSWORD_FILE="restic-pw.txt"

Initialize the Restic repository

Initialize the repository stored at Backblaze B2 with the bucket name of your choice. If the bucket does not exist yet, it will be created.

$ restic -r b2:my-restic-backup init


You will be asked to create a repository password.

To back up your home directory using the home environment variable ($HOME or ~) and the restic environment variables set as above, you would enter the following:

$ restic -r b2:my-restic-backup backup ~


The contents of a directory at a specific point in time is called a “snapshot” in Restic. The specific snapshot just created is identified by a sequence of hexadecimal characters.

To view the snapshot you now have stored on B2, enter

$ restic -r b2:my-restic-backup snapshots


If you run the backup command again, Restic will create another snapshot of your data, but this time it will be faster due to de-duplication. When you back up the same directory again (maybe with new or changed files) Restic will find the old snapshot in the repo and by default only reads those files that are new or have been modified since the last snapshot. This is decided based on the modify date of the file in the file system.

For subsequent backups (snapshots), you would enter the same command.

$ restic -r b2:my-restic-backup backup ~


 You now have two snapshots in your repository.

$ restic -r b2:my-restic-backup snapshots


Restoring your backup

To restore your backup, you specify which snapshot you wish to restore and where you want it to be put with the restore and the -t parameters.

$ restic -r b2:my-restic-backup restore  9a83a611 -t /tmp/restic-restore 


(Open image above in new window/tab to view.)

The snapshot will be restored to your system at /tmp/restic-restore.

You can save to and restore from different systems. The repository in the example above was saved from an Ubuntu Linux system and a snapshot from that repository was restored to a Debian Linux system.

On Debian:

$ restic -r b2:my-restic-backup snapshots


$ restic -r b2:my-restic-backup restore 9a83a611 -t /tmp/restic-restore


(Open image above in new window/tab to view.)

Note: The number of concurrent connections to the B2 service can be set with the

-o b2.connections=10

switch. By default, at most five parallel connections are established.

To Learn More

There's a lot you can do with Restic, including adding tags, mounting a repository locally, and scripting. To learn more, you can read the documentation at



Have more questions? Submit a request


  • 0

    @florian: I think you have to run an unlock command:

    Restic -r <path> unlock


  • 0

    Is there any way to have Backblaze run `restic prune` on the server periodically so the user doesn't have to incur the cost of the downloading required for this?

  • 0

    Florian. The lock should be released if it's a process that has completed. If you continue to experience this or other delays, check with our support team at

  • 0

    I wish you would have mentioned excluding directories.  I didn't think about it.  I'm doing my first backup now and it has been on the ~/.cache directory for 53 minutes (12146 files, 868 MiB) ... and ncdu says my cache directory is 2.2GB ... so it will be working on my cache directory for more than another hour!

Article is closed for comments.
Powered by Zendesk