Backblaze B2 Cloud Storage vs Google Cloud Storage: What are the differences? Developers describe Backblaze B2 Cloud Storage as 'A Cloud Storage service'. It is a generic cloud storage. You can use it from any computer, any operating system or any cloud storage purpose. You can manage and store large amounts of media files using this service. Innovative Companies Build on B2 Cloud Storage Organizations around the world choose Backblaze to solve for their use cases while improving their cloud OpEx vs. Amazon S3 and others.
This guide will show you how to use Backblaze B2 as a database replica path forLitestream.
Create a bucket#
To begin, you’ll need a bucket to store your data. If you don’t already have oneset up in Backblaze, follow the steps below:
- From your Backblaze dashboard, go to My Account > Buckets
- Click “Create a Bucket”
- Enter a unique name for “Bucket Unique Name” and leave the remaining fields as their defaults.
- Click “Create a Bucket”
- Copy the bucket details to the appropriate places in your
litestream.yml
file:
Create a user#
Next, create a user with programmatic access to the bucket you just created.
- From your Backblaze dashboard, go to My Account > App Keys
- Click “Add Application Key”
- In “Name of Key”, enter any unique name
- Under “Allow access to Bucket(s)' select the bucket you created above.
- Leave the remaining fields as their defaults.
- Click “Create new key”
- Copy the credentials to the appropriate places in your
litestream.yml
file- The
keyID
field is youraccess-key-id
- The
applicationKey
field is yoursecret-access-key
- The
Configuration file#
Your final litestream.yml
configuration file should look like this:
Backblaze is an online backup tool that allows Windows and Mac OS X users toback up their data to an offsite data center.
Backblaze B2 is their cloud object storage offering similar to Amazon S3 andother object storage services.
Instantiating a driver¶
To instantiate the driver you need to pass your key id and application key tothe driver constructor as shown below.
To access the credentials, you can login tohttps://secure.backblaze.com/user_signin.htm, then click “App Keys” or goto https://secure.backblaze.com/app_keys.htm directly.
keyID
serves as the first and applicationKey
as the second argument tothe driver constructor.
API Docs¶
libcloud.storage.drivers.backblaze_b2.
BackblazeB2StorageDriver
(key, secret=None, secure=True, host=None, port=None, api_version=None, region=None, **kwargs)[source]¶Parameters: |
|
---|---|
Return type: |
|
connectionCls
¶alias of BackblazeB2Connection
create_container
(container_name, ex_type='allPrivate')[source]¶Create a new container.
Parameters: | container_name (str ) – Container name. |
---|---|
Returns: | Container instance on success. |
Return type: | libcloud.storage.base.Container |
delete_container
(container)[source]¶Delete a container.
Parameters: | container (libcloud.storage.base.Container ) – Container instance |
---|---|
Returns: | True on success, False otherwise. |
Return type: | bool |
delete_object
(obj)[source]¶Delete an object.
Parameters: | obj (libcloud.storage.base.Object ) – Object instance. |
---|---|
Returns: | bool True on success. |
Return type: | bool |
download_object
(obj, destination_path, overwrite_existing=False, delete_on_failure=True)[source]¶Download an object to the specified destination path.
Parameters: |
|
---|---|
Returns: | True if an object has been successfully downloaded, Falseotherwise. |
Return type: |
|
download_object_as_stream
(obj, chunk_size=None)[source]¶Return a iterator which yields object data.
Parameters: |
|
---|---|
Return type: |
|
download_object_range
(obj, destination_path, start_bytes, end_bytes=None, overwrite_existing=False, delete_on_failure=True)¶Download part of an object.
Parameters: |
|
---|---|
Returns: | True if an object has been successfully downloaded, Falseotherwise. |
Return type: |
|
download_object_range_as_stream
(obj, start_bytes, end_bytes=None, chunk_size=None)¶Return a iterator which yields range / part of the object data.
Parameters: |
|
---|---|
Return type: |
|
enable_container_cdn
(container)¶Enable container CDN.
Parameters: | container (libcloud.storage.base.Container ) – Container instance |
---|---|
Return type: | bool |
enable_object_cdn
(obj)¶Enable object CDN.
Parameters: | obj (libcloud.storage.base.Object ) – Object instance |
---|---|
Return type: | bool |
ex_get_upload_data
(container_id)[source]¶Retrieve information used for uploading files (upload url, auth token,etc).
Rype: | dict |
---|
ex_get_upload_url
(container_id)[source]¶Retrieve URL used for file uploads.
Return type: | str |
---|
get_container
(container_name)[source]¶Return a container instance.
Parameters: | container_name (str ) – Container name. |
---|---|
Returns: | Container instance. |
Return type: | libcloud.storage.base.Container |
get_container_cdn_url
(container)¶Backblaze Cloud Storage
Return a container CDN URL.
Parameters: | container (libcloud.storage.base.Container ) – Container instance |
---|---|
Returns: | A CDN URL for this container. |
Return type: | str |
get_object
(container_name, object_name)[source]¶Return an object instance.
Parameters: |
|
---|---|
Returns: |
|
Return type: |
get_object_cdn_url
(obj)¶Return an object CDN URL.
Parameters: | obj (libcloud.storage.base.Object ) – Object instance |
---|---|
Returns: | A CDN URL for this object. |
Return type: | str |
iterate_container_objects
(container, prefix=None, ex_prefix=None)[source]¶Return a generator of objects for the given container.
Parameters: |
|
---|---|
Returns: | A generator of Object instances. |
Return type: |
|
iterate_containers
()[source]¶Return a iterator of containers for the given account
Returns: | A iterator of Container instances. |
---|---|
Return type: | iterator of libcloud.storage.base.Container |
list_container_objects
(container, prefix=None, ex_prefix=None)¶Return a list of objects for the given container.
Parameters: |
|
---|---|
Returns: | A list of Object instances. |
Return type: |
|
list_containers
()¶Return a list of containers.
Returns: | A list of Container instances. |
---|---|
Return type: | list of Container |
upload_object
(file_path, container, object_name, extra=None, verify_hash=True, headers=None)[source]¶What Is Object Storage
Upload an object.
Note: This will override file with a same name if it already exists.
upload_object_via_stream
(iterator, container, object_name, extra=None, headers=None)[source]¶Upload an object.
Backblaze Object Storage Device
Note: Backblaze does not yet support uploading via stream,so this calls upload_object internally requiring the object datato be loaded into memory at once