This article was originally posted on my blog.
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:
The 3-2-1 Backup Rules/Best Practices
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:
• Raspberry Pi 3 Model B (Amazon)
• Raspberry PI Case (Amazon)
• SD Card (Amazon)
• Internal Hard Drive (Amazon)
• External Hard Drive Enclosure (Amazon)
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 here), I will be using B2 from Backblaze. 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 downloads page to find the installer for your computer. If you are following my hardware choice, select the ARM - 32 Bit installer. Finally, follow the installation instructions on the Rclone website to properly install Rclone on your computer.
Step 3 - Connect Rclone to Backblaze B2
- Run
rclone config
. - Press
n
to create a new remote. - Specify a name to reference this remote in commands. For my purposes, I chose
remote
. - Press
2
then hitenter
to select Backblaze B2. - Enter your Backblaze Account ID then hit
enter
. This will look something like123456789abc
. - Enter your Backblaze Application Key then hit
enter
. This will look something like0123456789abcdef0123456789abcdef0123456789
. - Leave Endpoint blank then hit
enter
. - Press
y
then hitenter
to save configuration.
For more information, please visit the Rclone B2 website.
Step 4 - Configure Encryption in Rclone
- Run
rclone config
. - Press
n
to create an encrypted container. - Specify a name to reference this container in commands. For my purposes, I chose
secret
. - Press
5
then hitenter
to select crypt. - Enter
<REMOTE_NAME>:<B2_BUCKET_NAME>
then hitenter
to select the previously made remote. For my purpose, this isremote:backup
wherebackup
is the name of my B2 bucket. - Type
standard
for encrypted file names. - Choose a passphrase or generate one. It is important that you remember your passphrase - you will not be able to decrypt your backups without it.
- Choose a salt or generate one. It is important that you remember your salt - you will not be able to decrypt your backups without it.
- Press
y
to confirm the configuration and pressq
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
Note: 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.
- Run
crontab -e
- At the end of the file, add the following command:
0 * * * * /usr/bin/setsid /usr/sbin/rclone sync /path/to/folder secret: &>/dev/null
- Save and exit your crontab file.
Note: 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
That's it!
Your files are now being securely backed up to the cloud!
Big shoutout to defectivebit on GitHub who wrote this awesome Gist that helped guide me on getting my backup setup.
Comments or Question?
Please feel free to drop me a note here.
Discussion
Thanks Hunter for this excellent write-up.
Oddly, when I run the suggested rclone command (after having set up the B2 remove account), rclone simply creates a folder with the backed up files. That folder has the name of the remove account.
UPDATE: I see my mistake. The colon was missing on the command you said you use,
rclone sync Backup/ secret
so I did it that way too. Problem solved.Hi, excuse me, do you know if is it possible to choose not only a bucket but a folder inside the bucket to sync? For example, I would like to have a bucket to backup my 20 websites and not have 20 buckets one per website to backup. Thanks in advance.