Nextcloud Backblaze B2



Nextcloud, B2, and Cloudflare. If I wanted to migrate from Backblaze Personal to B2 I was wondering if this idea would be possible: I have four drives, totaling around 2.5+TB. I'm a sound designer, and it's several hundreds of thousands of sound files, some as small as 200k, some as large as 5-7GB. Mount the low priced redundant and unlimited storage on your desktop with Mountain Duck. Backblaze B2 Cloud Storage works similar to Amazon S3 or Microsoft Azure. Allowing you to store unlimited data in the cloud. But does it for 1/4th the cost. Create your Backblaze B2 Backup. If you have not done so already, you will need to create a Backblaze B2 bucket. To create a bucket is simple. Click on the “Buckets” menu option and then “Create a Bucket”. Enter the name of your bucket and leave the setting as private since you are only using the bucket for backup purposes.

Recently I’ve started hosting a lot of my own data using Nextcloud. It is anexcellent alternative to likes of Dropbox & Google Drive and provides a lot ofgood features out of the box, e.g. a really great user interface, Calendar andContacts, RSS reader, etc. along with native apps for all the desktop and mobileOSes.

This is a good alternative to other cloud providers because overall it’s prettycheap when there’s a need to scale up, although I had to research and findrelatively cheap infrastructure providers which provided the features that Ineeded, without providing a lot of enterprisey features which a single user likeme won’t need (r/selfhosted really helped me with finding the alternatives). Inthe end, I started with Hetzner for hosting the server and Backblaze B2 forcheap backups. The combination has been working really well for last 4 months orso, without any downtime.

As an aside, Hetzner also provides Nextcloud boxes which are pretty cheap butsince I use my VPS for some other stuff I didn’t pick that option.

Hey, I have been having problem integrating b2 into my Nextcloud, I finally figured out how to access my b2 files from Nextcloud by using Minio as the gateway to translate b2 into s3, however I could not upload/move/copy file(s) to Minio b2 gateway. BackBlaze inability to set a specific file name, file size limit and expiry date is preventing some of us from switching over from S3 to Backblaze for our storage of app data needs I made 2 separate posts regarding this previously which B2 staff replied to.

In this setup, I assume that you already have a Nextcloud server running on aVPS. I touch upon the details of my setup, but won’t go in-depth. Essentially, Icover how to provision a volume, use that to store NC data, encrypt and backthat up to Backblaze B2 using rclone (and cron).

Setting Up Hetzner (Optional)

First and foremost, one needs to create an account on Hetzner. The procedureover there is quite different as they require copy of the passport to be sentas part of their installation. Someone from their team checks it andactivates your account. They give the option of encrypting the passport copywith their gpg before sending them the passport. This helps in countering thefake accounts that crop up to use their inexpensive VPS solutions.

Changes to Nextcloud to use an External Volume

Once a VPS is procured, take it for a spin and install Nextcloud. As Imentioned, in my setup, I’ve created a volume to store all the nextclouddata.

There are 2 changes that I’ve done in my setup:

  • Since apache runs as www-data user, this folder needs to give thepermissions to this user. I’ve also added a group called cloud which hasall the users who can read through the data of multiple other servicesrunning on my machine.

  • The config of nextcloud by default uses datadirectory as/var/www/nextcloud/data and I’ve changed it to/mnt/volume-nbg1-1/nextcloud/data. The file should be available in thenextcloud root directory in the config folder.

Get a Backblaze B2 account.

Unlike Hetzner, these guys just need your email address and credit carddetails. Create an account over there, and then create a bucket. I generallyappend a guid to my bucket name as these have to be globally unique.

Once the bucket is created, create an Application key using the App Keysmenu on the left. Note down the keyId and applicationKey.

Setup A User To Backup Data

As mentioned before, and to keep a separation of different users, I created auser which has read access to services running on my machine. Let’s call thatuser syncuser. This user will be part of the cloud group and thereforewill read access to the nextcloud data directory. Essentially, you’d need torun these commands.

Setup rclone

rclone is an excellent sync utility with backends for (almost?) all the cloudproviders in existence. It is ultra fast and super simple to set up.

Nextcloud Backblaze B2 App

This step of setting rclone contains 2 substeps:

Nextcloud Backblaze B2
  1. This configuration uses the keyid and applicationKey which we savedwhile creating app keys for B2. Let’s assume that you named this backendb2 during the rclone configuration, then go ahead and sync acouple of files using the following commands:

    This should list out dir1 and dir2.

    This backend doesn’t really encrypts the data. We need to setup a cryptbackend for encryption to actually work.

  2. While doing the configuration for crypt, the setup asks for quite a fewthings. Here’s a list of values you might use, based on the steps we’vetaken till now:

    • New remote -> name -> b2-crypt

    • Type of storage -> crypt

    • Remote to encrypt/decrypt -> b2-crypt:bucketname

    • How to encrypt the filename -> “standard”

    • Encrypt directory names -> “false”

    • Password -> yes or generate

    • Salt -> yes or generate

Nextcloud Backblaze B2 Price

As listed above, the preference is to give it both the backendName andbucketName in the form b2-crypt:bucketname. This makes things easierfor syncing the folders inside the bucket. You can simple encrypt it usingb2-crypt:foldername instead of the longerb2-crypt:bucketname/foldername. I find this a bit cleaner as well.

Backing it Up

Nextcloud Backblaze B2 Plus

Nextcloud backblaze b2 proNextcloud

So far, we’ve setup Nextcloud to use an external volume, created an user forsyncing the data and have created an encrypted backend with which we hope tosync the data to B2. Let’s turn that hope into reality.

App

Backblaze B2 Price

The command that we’re going to do the syncing is:

Backup Nextcloud To Backblaze B2

dry-run and v are just there for debugging. In case everything runs fine,remove these options.

We are going to setup a cron job with clouduser to read and sync the datadirectory to the encrypted backend, everyday at 3:05AM.

Run the following command as a sudo user:

Backblaze B2 Cloud Storage

This should open up a cron file in your default editor, add the following toit:

Further

As I mentioned, this post isn’t a complete walkthrough for the setup, butmore like a skeleton. There are a couple of things you should be doing tohave a stable and painless experience in case things go south:

Test the setup

Backup is not there for backing things up, but for restoring the datawhen the luck turns bad. So setup rclone in your local machine, syncsome data back, and try to decrypt it. It should work, if it doesn’t thensee where it went bad.

Have more than one backup

One problem with encryption is either of bitrot or of lost keys. Since we’restoring our data in someone else’s computer, it might make sense to encryptit. But it’s always a good idea to have a local copy of it. With this setup,you have a (in case of Hetzner) triple replicated volume with non-encrypteddata and another encrypted backup at B2. Make sure you have another localcopy in your machine and/or external hard disk.

This blog post is just half backup

Nextcloud documentation says:

You must have both the database and data directory. You cannot completerestoration unless you have both of these.

So come up with a similar approach of backing up your Nextcloud’sdatabase. The details are in the documentation. In my setup, I have a weeklycron job that backups up my database to B2.