Create encrypted data backups to Backblaze B2
Creating & keeping backups of your data is essential and often not done because of the hassle associated with it. Using the powerful & easy command line tool HashBackup you can create encrypted local and remote backups in different storage destinations like WebDAV, Amazon S3, Backblaze B2.
Remote storage backups protect you against the loss of the local backup data due to hardware failure or an on-site disaster. HashBackup can write to different remote storage destinations. In this article we will use Backblaze B2 as the remote storage destination
Prerequisite
1. Installing HashBackup
wget --content-disposition -q http://www.hashbackup.com/download/hb-linux-64bit.tar.gz?attredirects=0&d=1
Unpack the HashBackup executable…:
tar xfz hb-linux-64bit.tar.gz
…and copy it into /usr/bin/ and make it accessible in the regular PATH:
cp -v hb /usr/bin/
2. Create a B2 Bucket & create Your Application Keys
Creating a B2 bucket – Step 1
Creating a B2 bucket – Step 2
Creating application keys – Step 1
Creating application keys – Step 2
After the application keys are created you'll get the keyID and applicationKey values, which you'll need in the next step:
Creating application keys – Step 3
3. Initialise the local HashBackup directory
After the installation of the HashBackup command line tool hb you'll create the directory in which the local backup of your data will be stored and from where the remote backups will be configured.
user@local:~# hb init -c /bak/mydatabackup2020
HashBackup installer #6 Copyright 2009-2020 HashBackup, LLC
Downloading http://upgrade.hashbackup.com/2525/hb.r2525.Linux.x86_64.bz2
Verified file signature
Installed #2525 as /usr/bin/hb
HashBackup #2525 Copyright 2009-2020 HashBackup, LLC
Backup directory: /bak/mydatabackup2020
Permissions set for owner access only
Created key file /bak/mydatabackup2020/key.conf
Key file set to read-only
Setting include/exclude defaults: /bak/mydatabackup2020/inex.conf
VERY IMPORTANT: your backup is encrypted and can only be accessed with
the encryption key, stored in the file:
/bak/mydatabackup2020/key.conf
You MUST make copies of this file and store them in secure locations,
separate from your computer and backup data. If your hard drive fails,
you will need this key to restore your files. If you have setup remote
destinations in dest.conf, that file should be copied too.
Backup directory initialized
> As mentioned by the hb command you should keep the file key.conf in a secure location to be able to restore your encrypted backup.
4. Setup B2 Backblaze login credentials
nano /bak/mydatabackup2020/dest.conf
The file dest.conf:
destname b2
type b2
accountid 000d7b06cfe57aa0000000009
appkey K000YEGq00Bps7VHGh0Rk2ZhkdzV2g8
bucket mydatabackup2020
dir mydata2020
5. Create your backup
user@local:~# hb backup -c /bak/mydatabackup2020/ /user/mydata2020/
$HashBackup #2525 Copyright 2009-2020 HashBackup, LLC
Backup directory: /bak/mydatabackup2020
Backup start: 2020-07-22 19:34:50
Using destinations in dest.conf
Copied HB program to /bak/mydatabackup2020/hb#2525
This is backup version: 0
Dedup not enabled; use -Dmemsize to enable
/
/bak
/bak/mydatabackup2020
/bak/mydatabackup2020/inex.conf
/user
/user/mydata2020
/user/mydata2020/test.txt
Copied arc.0.0 to b2 (144 bytes 1s 79 bytes/s)
Writing hb.db.0
Copied hb.db.0 to b2 (4.7 KB 1s 3.4 KB/s)
Copied dest.db to b2 (36 KB 1s 24 KB/s)
Time: 4.0s
CPU: 0.1s, 3%
Mem: 72 MB
Checked: 7 paths, 110 bytes, 110 bytes
Saved: 7 paths, 110 bytes, 110 bytes
Excluded: 0
Dupbytes: 0
Compression: 12%, 1.1:1
Efficiency: 0.00 MB reduced/cpusec
Space: +96 bytes, 36 KB total
No errors
The offsite backup on Backblaze B2
6. Restore your backup
user@local:~# hb get -c /bak/mydatabackup2020/ /user/mydata2020
HashBackup #2525 Copyright 2009-2020 HashBackup, LLC
Backup directory: /bak/mydatabackup2020
Most recent backup version: 0
Restoring most recent version
Using destinations in dest.conf
Restoring mydata2020 to /user
/user/mydata2020
/user/mydata2020/test.txt
Restored /user/mydata2020 to /user/mydata2020
No errors
user@local:~# ls /bak/mydatabackup2020_NEW_DIR
dest.conf key.conf
user@local:~# hb recover -c /bak/mydatabackup2020_NEW_DIR/
HashBackup #2525 Copyright 2009-2020 HashBackup, LLC
Backup directory: /bak/mydatabackup2020_NEW_DIR
Using destinations in dest.conf
Recovering backup files from destination: b2
Files will be copied to: /bak/mydatabackup2020_NEW_DIR
Proceed with recovery? yes
Removed /bak/mydatabackup2020_NEW_DIR/dest.db
Getting dest.db from b2
Getting hb.db from b2
Queueing hb.db files
Waiting for /bak/mydatabackup2020_NEW_DIR/hb.db.0
Loading hb.db.0
Verified hb.db.0 signature
Verified hb.db signature
Checking db integrity
Removing hb.db.N files
Queueing arc files from b2
Waiting for 1 arc files...
Backup files recovered to: /bak/mydatabackup2020_NEW_DIR
Verify the backup with the selftest command:
$ hb selftest -c /bak/mydatabackup2020_NEW_DIR/
If inex.conf was customized, restore it with the hb get command.
user@local:~# hb get -c /bak/mydatabackup2020_NEW_DIR/ /user/mydata2020
HashBackup #2525 Copyright 2009-2020 HashBackup, LLC
Backup directory: /bak/mydatabackup2020_NEW_DIR
Most recent backup version: 0
Restoring most recent version
Using destinations in dest.conf
Restoring mydata2020 to /user
/user/mydata2020
/user/mydata2020/test.txt
Restored /user/mydata2020 to /user/mydata2020
No errors
user@local:~# ls mydata2020/
test.txt
Conclusion
In this article we have used HashBackup to create and restore a backup of our data to a local and a remote backup destination.