Backblaze Linux
On first learning of Backblaze one of my first thoughts was that it looks like a pretty decent backup solution. Next, I noticed that they list support for Windows and OSX. What about Backblaze Linux? Companies often times leave out Linux. For their personal backup solution, that seems to be the case but for their B2 Cloud Storage service, it looks like Backblaze does support Linux.
A lot of different tools can be used to interface with Backblaze B2. Some of these are free, open source applications and others are proprietary. There are GUI and CLI options. You can even roll your own solution because Backblaze has an API for B2.
Taking a look at the documentation for their command line tool (see references section) I didn’t notice anything about installing on Linux but it looks like it is just a Python tool that should run just fine on Linux. The OSX instructions look like what you would probably need to do to get this working on Linux.
Backblaze Linux Tools
Backblaze comes with a CLI and an API. These are both great options if you are using Linux. Backblaze Linux support is pretty good.
- B2 CLI
- B2 API
There are several third party tools that can be used to interface with B2 on Linux. Here is a partial list from their site.
- Restic
- HashBackup
- Duplicity
- Duplicacy
- qBackup
- MSP360
- GoodSync
- More …
B2 CLI
Before you start using the CLI you are going to want to enable B2 Cloud Storage from the Backblaze web GUI. Start by going to “My Settings” to see your account settings, then look under “Enabled Products” and make sure that the “B2 Cloud Storage” box is checked.
We also went to “App Keys” and generated an application key. The application key should continue working if you change yor master application key. Upon generating a new applicaiton key it will give you two values: “keyID” and “applicationKey”. Save these values, you will need them both later. The applicationKey won’t be displayed again. You only have the time just after you have created it to copy the value.
You should be able to install B2 using pip. You will need a somewhat recent version of Python. We used a feshly installed Ubuntu 20.04 VM as a test system. It comes with Python 3 installed by default and no Python 2. Pip also wasn’t installed. Note that you would run Python by actually typing “python3” and pip by typing “pip3”. We installed pip with the following:
sudo apt install python3-pip
We initially tried installing b2 without sudo. It installed it here: /home/user1/.local/bin. It also wasn’t on the path. Rather than add it to the path we tried installing it with sudo and the command was sucessfully added to the path so that you can just type ‘b2’ from anywhere with no addtional setup. This ended up being the actual command to run for us:
sudo pip3 install --upgrade b2
If you were running Python 2 you would use something similar to the following:
sudo pip install --upgrade b2
You can also clone the git repo and install it manually. We didn’t do this.
git clone https://github.com/Backblaze/B2_Command_Line_Tool.git
cd B2_Command_Line_Tool
python setup.py install
Actually Getting Started
By just running the command “b2” you will be presented with a list of commands and options. This should give you pretty much everything you need.
Use your application key ID to configure B2 to connect to your account. This will save an auth token in a file named .b2_account_info in your home directory. This command will also give you a download URL that you will use later on. Replace the keyID in the c ommand below with your own keyID. It will prompt you for the corresponding applicationKey.
b2 authorize_account 07cd01a1cb39
List buckets like this. There won’t be any there initially.
b2 list_buckets
It should be noted that you will need to create a unique bucket name. Apparently you can’t have a bucket name that has already been used by someone else so using the exact example bucket names I show here will not work. I even tried using the name “mydumbbucket” and apparently someone had already named a bucket that. I received the following error: “ERROR: Bucket name is already in use: mydumbbucket”. I was able to create a bucket with the name “mydumbbucket123”.
Create a public bucket like this:
b2 create_bucket bucket1 allPublic
Create a private bucket like this:
b2 create_bucket bucket2 allPrivate
Try listing them again. You will see the ID, name, and whether or not they are allPublic or allPrivate.
b2 list_buckets
You can upload a file like this:
b2 upload_file bucket1 turtle.jpg animals/turtle.jpg
List the files in a bucket like this:
b2 ls bucket1
You can see the files in a folder like this:
b2 ls mydumbbucket1234 animals
Assuming your download URL from the create_bucket step looked like this “https://f001.backblazeb2.com/” you should be able to pull down your file from a URL like this: “https://f001.backblazeb2.com/file/bucket1/animals/turtle.jpg”. You should be able to view a file in a public bucket directly from any web browser. Trying to do the same with a private bucket will give you an “unauthorized” error.
You can download a file like this:
b2 download_file_by_name mydumbbucket1234 animals/turtle.jpg new-turtle.jpg
Backblaze Linux - Using Restic
Some would recommend downloading Restic from the official site since it is a relatively new tool and might not be available from the repos ( see the link in the references section of this page ). We actually had not trouble pulling it right down from the repo on Ubuntu 20.04.
If you don’t want to specify the password for your repository every time you run a Restic command you can save the password in a file and set the location of that file in a specific environment variable like this:
vi restic-pw.txt
export RESTIC_PASSWORD_FILE="restic-pw.txt"
You will also want to save your “keyID” and “applicationKey” in environment variables.
export B2_ACCOUNT_ID="xxxxxxxx"
export B2_ACCOUNT_KEY="xxxxxxxx"
Initialize the repository:
restic -r b2:my-backup1 init
Backup your home dir:
restic -r b2:my-backup1 backup ~
Show sanpshots:
restic -r b2:my-backup1 snapshots
Rerun the backup command to create additional backups ( snapshots ). Newer snapshots should only contain what has changed.
Restore a snapshot based on snapshot ID. Place the restored files in a specific directory.
restic -r b2:my-backup1 restore 9a83a611 -t /home/user1/restored-data
Backblaze Linux - Using Duplicity
Don’t confuse Duplicity with Duplicacy.
You supposedly need version 0.7.12 or newer. Some guides, including one we link to, recommend installing from a PPA since the version that comes with many distros might be too old. We’re testing this on Ubuntu 20.04 Desktop/Server and were able to get version 0.8.12 directly from the default repos. This is as of April 2020. Ubuntu Server needed to have it installed from the repo but Ubuntu Desktop already had it installed. The desktop edition also comes with Déjà Dup installed by default. We used the following command to install in Ubuntu Server 20.04:
sudo apt install duplicity
Backup with Duplicity
The format of the command looks like this:
duplicity ~ b2://[keyID]:[applicationKey]@[B2 bucket name]
duplicity ~ b2://[keyID]:[applicationKey]@[B2 bucket name]/[dir]
Here is an example. Substitute your own keyID and applicationKey.
duplicity ~ b2://07cd01a1cb39:564648sadf18adf4897987@mydumbbucket1234
Restore with Duplicity
You can actually leave out the “restore” command and Duplicity will figure out what it is supposed to do based on the order of your arguments. You can also leave out the “–file-to-restore” option if you want to restore everything.
Here is the syntax to restore:
duplicity restore --file-to-restore [file/folder name from backup] b2://[keyID]:[application key]@[B2 bucket name] [restore path]
duplicity b2://[keyID]:[application key]@[B2 bucket name] [restore path]
And another example:
duplicity restore --file-to-restore my-file.jpg b2://07cd01a1cb39:564648sadf18adf4897987@mydumbbucket1234 /home/user1/restored
duplicity b2://07cd01a1cb39:564648sadf18adf4897987@mydumbbucket1234 /home/user1/restored
Déjà Dup
There is an excellent tool called Déjà Dup. It comes packaged with some Linux distros, for example Ubuntu 20.04. It is a front end GUI for Duplicity. You would think that this would mean that it supports Backblaze B2 but apparently it doesn’t. People have been wanting Backblaze support for Déjà Dup for a while now. Hopefully we get this soon.
Personal vs Business vs B2 Cloud Storage
As far as I know personal and business don’t support Linux but B2 does. The difference between Personal and Business is that some group related options may be set differently. Both can be used interchangeably if you adjust the settings. Based on my understanding the reason to have both personal and business variants of the product is for marketing.
Now B2 Cloud Storage is something else. B2 is actually object storage. Also, as we have covered, it works with Linux.
References
- Backblaze B2 Docs
- Backblaze B2 - Quick Command Line
- Backblaze Linux
- Third Party B2 Tools
- Backblaze Linux - Using Duplicity
- Backblaze Linux - Using Duplicity
- Backblaze Linux - Using Restic