LinuxCommandLibrary

b2-tools

Manage Backblaze B2 Cloud Storage

TLDR

Access your account

$ b2 authorize_account [key_id]
copy

List the existing buckets in your account
$ b2 list_buckets
copy

Create a bucket, provide the bucket name, and access type (e.g. allPublic or allPrivate)
$ b2 create_bucket [bucket_name] [allPublic|allPrivate]
copy

Upload a file. Choose a file, bucket, and a folder
$ b2 upload_file [bucket_name] [path/to/file] [folder_name]
copy

Upload a source directory to a Backblaze B2 bucket destination
$ b2 sync [path/to/source_file] [bucket_name]
copy

Copy a file from one bucket to another bucket
$ b2 copy-file-by-id [path/to/source_file_id] [destination_bucket_name] [path/to/b2_file]
copy

Show the files in your bucket
$ b2 ls [bucket_name]
copy

Remove a "folder" or a set of files matching a pattern
$ b2 rm [path/to/folder|pattern]
copy

SYNOPSIS

b2 [global-options] <command> [command-options] [arguments]

Examples:
b2 ls --buckets
b2 upload_file my-bucket local-file.txt remote-path/file.txt
b2 sync --delete local-dir/ b2://my-bucket/remote-dir/

PARAMETERS

--help, -h
    Displays a help message for the b2 command or a specific subcommand, detailing its usage and available options.

--version
    Shows the program's version number and exits, useful for verifying the installed version.

--debug
    Enables verbose debug output, which can be very helpful for troubleshooting issues or understanding internal operations.

--info
    Prints informative messages about the command's execution, providing a higher level of detail than default output.

--verbose
    Increases the verbosity of output messages, often providing more progress or action details.

--quiet
    Suppresses most output messages, making it suitable for scripting where only errors or final results are desired.

--color {always,auto,never}
    Controls the use of colored output in the terminal for enhanced readability of different message types.

--non-interactive
    Disables interactive prompts, ensuring the command can run without user input, which is essential for automation.

--profile <profile_name>
    Specifies a named profile from the configuration file to use for authentication and settings, allowing management of multiple B2 accounts.

<command>
    A specific operation to perform on B2, such as authorize_account, ls (list files/buckets), upload_file, download_file, sync, and many others. Each subcommand has its own unique set of specific options and arguments.

DESCRIPTION

The b2-tools utility provides a comprehensive command-line interface for interacting with Backblaze B2 Cloud Storage. It enables users to perform a wide range of operations, including managing buckets, uploading and downloading files, listing file versions, and handling large file operations. Designed for automation and scripting, b2-tools offers robust functionality for integrating Backblaze B2 into various workflows and scripts. It supports multiple authentication methods, such as environment variables and configuration files, and efficiently manages B2's unique file versioning and large file architecture. Its design makes it an essential tool for developers and system administrators looking to programmatically interact with their B2 data, offering capabilities from simple file transfers to complex synchronization tasks.

CAVEATS

Authentication is critical: b2-tools requires valid Backblaze B2 Application Key IDs and Application Keys for access. These are typically set as environment variables (e.g., B2_APPLICATION_KEY_ID and B2_APPLICATION_KEY) or configured persistently via the b2 authorize_account command. Performance for large file operations is highly dependent on network stability and available bandwidth. Users should also be aware that all operations on Backblaze B2, including storage, downloads, and certain API calls, incur costs. The tool itself is written in Python and requires a compatible Python environment to be installed.

SUBCOMMAND-BASED OPERATION

The core functionality of b2-tools is structured around a rich set of subcommands, where b2 acts as a dispatcher. This modular design allows for clear, distinct operations. For instance, to upload a file, you use b2 upload_file; to list buckets, you use b2 ls --buckets. Each subcommand is self-contained with its own specific options and arguments, which can be easily discovered by appending --help to the subcommand (e.g., b2 upload_file --help).

CONFIGURATION AND PROFILES

Authorization credentials and other persistent settings for b2-tools are typically stored in a configuration file, often located at ~/.b2_account_info. This file facilitates persistent sessions, meaning you don't need to re-authorize for every command. Furthermore, it supports the management of multiple Backblaze B2 accounts or profiles, which can be conveniently switched using the --profile global option, making it ideal for users managing data across different accounts.

POWERFUL SYNC COMMAND

One of the most frequently used and powerful features of b2-tools is the b2 sync subcommand. This command provides highly efficient synchronization of local directories with B2 buckets, functioning similarly to tools like rsync or aws s3 sync. It intelligently detects changes, handles deletions (with the --delete option), and manages large file uploads and downloads incrementally, making it an indispensable tool for backup, disaster recovery, and data migration tasks.

HISTORY

b2-tools was developed by Backblaze, Inc. as the official command-line interface for their B2 Cloud Storage service. It was created to provide a robust programmatic way for users and applications to interact with B2, complementing the web UI and direct API. Written in Python, it is maintained as an open-source project, allowing for community contributions and transparent development. Its evolution has focused on expanding functionality (e.g., the powerful sync command), improving performance, and ensuring seamless compatibility with new B2 features and services, establishing itself as a key tool for data management on the platform.

SEE ALSO

aws(1), gsutil(1), rclone(1), curl(1), mc(1)

Copied to clipboard