Backing up Files to Backblaze B2 with Rclone
Tags: backup
Published: 2017-08-08 15:15:44

---
title: Backing up Files to Backblaze B2 with Rclone
published: true
description: Automatic and Encrypted
tags: backup
---

This article was originally posted on <a href="http://blog.hunterparks.com/2017/08/05/backing-up-files-to-backblaze-b2-with-rclone/" target="_blank">my blog</a>.

<hr>

Backing up files is arguably one of the most important things someone can do on their computer. Ensuring there is a copy of your most important data affords you the ability to not  worry about a future ransomware virus, a stolen/broken computer, or just a simple accident that could erase your information forever.

A strategy that is widely seen as a very effective way to backup your data is the 3-2-1 Backup Rules/Best Practices:

<img src="https://thepracticaldev.s3.amazonaws.com/i/al41lqy2bhh6a0s7yecf.png" alt="3-2-1 Backup">
<span class="caption text-muted">The 3-2-1 Backup Rules/Best Practices</span>

With the following guide, I hope to be able to have an additional copy of my data, stored on a different storage type, and synced with a cloud service provider - Backblaze in this case.

# Preparing the Hardware (optional) #

If you already have a computer setup, please skip this step. If not, see the list of hardware I used for this project - found below:

&bull;&nbsp;&nbsp;Raspberry Pi 3 Model B (<a target="_blank" href="https://www.amazon.com/gp/product/B01CD5VC92/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B01CD5VC92&linkCode=as2&tag=unterarkslog-20&linkId=3cde54f6d62e0bdfc684a5174af6310b">Amazon</a>)<img src="//ir-na.amazon-adsystem.com/e/ir?t=unterarkslog-20&l=am2&o=1&a=B01CD5VC92" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
&bull;&nbsp;&nbsp;Raspberry PI Case (<a target="_blank" href="https://www.amazon.com/gp/product/B01CDVSBPO/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B01CDVSBPO&linkCode=as2&tag=unterarkslog-20&linkId=98613710f9b7e334d16f6b8072d80b88">Amazon</a>)<img src="//ir-na.amazon-adsystem.com/e/ir?t=unterarkslog-20&l=am2&o=1&a=B01CDVSBPO" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
&bull;&nbsp;&nbsp;SD Card (<a target="_blank" href="https://www.amazon.com/gp/product/B00M55C0VU/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B00M55C0VU&linkCode=as2&tag=unterarkslog-20&linkId=bcc884eea17254efa5e6fb7542177ff3">Amazon</a>)<img src="//ir-na.amazon-adsystem.com/e/ir?t=unterarkslog-20&l=am2&o=1&a=B00M55C0VU" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
&bull;&nbsp;&nbsp;Internal Hard Drive (<a target="_blank" href="https://www.amazon.com/gp/product/B008JJLZ7G/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B008JJLZ7G&linkCode=as2&tag=unterarkslog-20&linkId=53267666dca9307b4a12fffeef2c1c17">Amazon</a>)<img src="//ir-na.amazon-adsystem.com/e/ir?t=unterarkslog-20&l=am2&o=1&a=B008JJLZ7G" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
&bull;&nbsp;&nbsp;External Hard Drive Enclosure (<a target="_blank" href="https://www.amazon.com/gp/product/B00GAML7OK/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B00GAML7OK&linkCode=as2&tag=unterarkslog-20&linkId=b64186ffdb36377efdc44057cc77f5da">Amazon</a>)<img src="//ir-na.amazon-adsystem.com/e/ir?t=unterarkslog-20&l=am2&o=1&a=B00GAML7OK" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />

**Note**: If you do not have an extra hard drive sitting around, you can purchase external drive instead.

# Preparing the Computer #

The only prerequisite for the computer is that you have Windows, macOS, or Linux installed and functioning. Plug in your external hard drive and make sure that it is functioning correctly. Additionally, ensure that you have an active internet connection as that will be required for installing the necessary software and uploading your files to Backblaze B2 for backup.

# Backing up Your Files #

### Step 1 - Set Up a Backblaze B2 Account ###

While Rclone supports many different cloud providers (see their website <a href="https://rclone.org/overview/" target="_blank">here</a>), I will be using <a href="https://www.backblaze.com/b2/cloud-storage.html" target="_blank">B2</a> from <a href="https://www.backblaze.com/" target="_blank">Backblaze</a>. Follow the instructions on the B2 website to setup your B2 account and get your API key - this key will allow you to access you B2 account through Rclone.

### Step 2 - Install Rclone ###

Rclone will need to be installed on the computer you are using to store your files. If you are not using the same hardware I am, please install the Rclone version that will work for your computer. Visit the Rclone <a href="https://rclone.org/downloads/" target="_blank">downloads</a> page to find the installer for your computer. If you are following my hardware choice, select the <u>ARM - 32 Bit</u> installer. Finally, follow the <a href="https://rclone.org/install/" target="_blank">installation instructions</a> on the Rclone website to <i>properly</i> install Rclone on your computer.

### Step 3 - Connect Rclone to Backblaze B2 ###

1. Run `rclone config`.
2. Press `n` to create a new remote.
3. Specify a name to reference this remote in commands. For my purposes, I chose `remote`.
4. Press `2` then hit `enter` to select Backblaze B2.
5. Enter your Backblaze Account ID then hit `enter`.
<span class="caption text-muted" style="text-align: left;">This will look something like `123456789abc`.</span>
6. Enter your Backblaze Application Key then hit `enter`.
<span class="caption text-muted" style="text-align: left;">This will look something like `0123456789abcdef0123456789abcdef0123456789`.</span>
7. Leave Endpoint blank then hit `enter`.
8. Press `y` then hit `enter` to save configuration.

For more information, please visit the <a href="https://rclone.org/b2/" target="_blank">Rclone B2</a> website.

### Step 4 - Configure Encryption in Rclone ###

1. Run `rclone config`.
2. Press `n` to create an encrypted container.
3. Specify a name to reference this container in commands. For my purposes, I chose `secret`.
4. Press `5` then hit `enter` to select crypt.
5. Enter `<REMOTE_NAME>:<B2_BUCKET_NAME>` then hit `enter` to select the previously made remote.
<span class="caption text-muted" style="text-align: left;">For my purpose, this is `remote:backup` where `backup` is the name of my B2 bucket.</span>
6. Type `standard` for encrypted file names.
7. Choose a passphrase or generate one.
<span class="caption text-muted" style="text-align: left;">It is important that you remember your passphrase - you will not be able to decrypt your backups without it.</span>
8. Choose a salt or generate one.
<span class="caption text-muted" style="text-align: left;">It is important that you remember your salt - you will not be able to decrypt your backups without it.</span>
9. Press `y` to confirm the configuration and press `q` to close Rclone.

### Step 5 - Backing up Your Files ###

Now, when wanting to backup a folder to BackBlaze, type the following command:

~~~
rclone sync /path/to/folder secret:
~~~

This line takes all of your files in the folder path and uploads them to your Backblaze B2 bucket. For me, I write the following line:

~~~
rclone sync Backup/ secret
~~~

<b>Note</b>: There are two options for uploading to the cloud. While I use `sync`, you can also use `copy`. Here are the differences:
* `Sync` will mirror the folder path exactly from your local filesystem to Backblaze. This deletes files in the destination that have been removed from the source.
* `Copy` will copy files from your local filesystem to Backblaze where deleted files will NOT be deleted from Backblaze.

If you have a lot of files to upload that could take a long time, use the following command so that output is recorded to a file and the upload will not get killed if you log out:

~~~
setsid [command] --log-file /path/to/file.log &>/dev/null
~~~
where `[command]` is the command you used above.

### Step 6 - Backup Automation ###

The following set of commands will setup your computer to run an automatic backup of your files.

1. Run `crontab -e`
2. At the end of the file, add the following command:

~~~
0 * * * * /usr/bin/setsid /usr/sbin/rclone sync /path/to/folder secret: &>/dev/null
~~~

3. Save and exit your crontab file.

<b>Note</b>: You can add an output log file by using the `--log-file` parameter found in step 5. Additionally, you can also choose between the `sync` and `copy` rclone modes.

### Step 7 - Restoring Your Files ###

To obtain you files from Backblaze, you will need to configure rclone on a new machine or you will need to move to a different location of your uploading computer. It can be helpful to backup you configuration files to make it easier to restore. Once your configuration is correct, run the following command:

~~~
rclone sync secret: /path/to/folder
~~~

<hr>

### That's it! ###

Your files are now being securely backed up to the cloud!

Big shoutout to <a href="https://gist.github.com/defectivebit" target="_blank">defectivebit</a> on GitHub who wrote <a href="https://gist.github.com/defectivebit/95b159ed5ba7e1d5d85d74c6e4b04dea" target="_blank">this</a> awesome Gist that helped guide me on getting my backup setup.

<hr>

<p style="font-family: monospace; font-size: 1.5em;">Comments or Question?</p>

Please feel free to drop me a note <b><a href="mailto:huntermparks@gmail?subject=Blog%20Feedback%20-%20">here</a></b>.