LinuxCommandLibrary

b2

Manage Backblaze B2 cloud storage files

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] subcommand [subcommand-options] [arguments]

Examples:
b2 authorize-account [options]
b2 upload-file <bucket> <local-path> <b2-path>
b2 ls [bucket]

PARAMETERS

--version
    Show program's version number and exit

-h, --help
    Show help message and exit

--debug
    Print debug information to stderr

--log-level LEVEL
    Set log level: DEBUG, INFO, WARNING, ERROR, CRITICAL

--no-color
    Disable colored terminal output

--user-agent-suffix SUFFIX
    Append string to user-agent header

--authorization ACCOUNT_AUTH
    Provide base64 authorization token directly

DESCRIPTION

The b2 command-line tool provides a powerful interface to Backblaze B2 Cloud Storage, an affordable S3-compatible object storage service. It enables seamless file management operations including uploading, downloading, listing, deleting, and sharing files and buckets directly from the Linux terminal.

Key capabilities include multipart uploads for large files (>5GB recommended), resumable transfers, server-side encryption support, bucket lifecycle policies, and CORS configuration. Users authenticate once via application keys, after which the tool caches credentials for subsequent operations. It integrates well with shell scripts, supports progress indicators, and handles versioning and legal holds.

Developed in Python, b2 is open-source, cross-platform, and extensible. Ideal for backups, media serving, and data archiving, it offers cost-effective storage without vendor lock-in. Installation is straightforward via pip install b2 or package managers. Common workflows involve authorizing an account, creating buckets, and syncing data with local directories.

With robust error handling and logging, it's suitable for both interactive use and automation in cron jobs or CI/CD pipelines. Compared to GUI tools, it excels in efficiency for bulk operations.

CAVEATS

Requires initial setup with b2 authorize-account using Backblaze application key; credentials cached in ~/.b2_account. Not installed by default on Linux distributions. Large uploads need sufficient bandwidth; multipart threshold configurable per subcommand. API calls incur B2 usage fees.

INSTALLATION

pip install b2 or pipx install b2; binaries available on GitHub releases for standalone use.
Apt/brew support via third-party repos.

COMMON SUBCOMMANDS

authorize-account: Authenticate.
upload-file: Upload local files.
download-file-by-name: Download by path.
ls: List buckets/files.
rm: Delete files.
sync: Mirror directories.
Run b2 --help for full list.

EXAMPLE

b2 authorize-account KEYID APPLICATIONKEY
b2 create-bucket mybackup shared
b2 upload-file mybackup ./data.tar.gz b2://mybackup/data.tar.gz

HISTORY

Released by Backblaze in 2016 as open-source Python CLI (MIT license). Actively maintained on GitHub with regular updates for new B2 features like Object Lock and legal holds. Widely adopted for cost-effective backups since B2's 2015 launch.

SEE ALSO

rclone(1), aws(1), s3cmd(1)

Copied to clipboard