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] <COMMAND> [COMMAND_OPTIONS] [ARGUMENTS]
Examples:
b2 authorize <accountId> <applicationKey>
b2 ls --long b2://my-bucket
b2 upload_file --no-progress my-bucket local_file.txt remote_path/file.txt

PARAMETERS

--help
    Displays a help message for the b2 command or a specific subcommand.

--version
    Shows the installed version number of the b2 command-line tool.

--debug
    Enables verbose debug logging, useful for troubleshooting issues.

--account-id <ID>
    Specifies the Backblaze B2 account ID, overriding any ID stored in the configuration file.

--application-key <KEY>
    Specifies the Backblaze B2 application key, overriding any key stored in the configuration file.

--skip-by-hash
    During uploads, if a file with the same name and SHA1 hash already exists at the destination, the upload is skipped.

--no-progress
    Disables the display of the progress bar during file uploads or downloads.

DESCRIPTION

The b2 command-line tool is a versatile utility for interacting with Backblaze B2 Cloud Storage. It allows users to perform various operations on their B2 buckets and files directly from the command line, providing a powerful interface for automating cloud storage tasks. Key functionalities include listing buckets and files, uploading and downloading data, managing file versions, and handling bucket lifecycle rules. It serves as a programmatic interface ideal for scripts and integration into larger workflows, ensuring secure and efficient data transfers. Being Python-based, it is commonly installed via pip and requires an active Backblaze B2 account for full functionality.

CAVEATS

The b2 command is not a standard Linux utility and must be installed separately (e.g., using pip).
Requires an active Backblaze B2 account and proper authorization before most operations can be performed.
Internet connectivity is essential for interacting with the B2 cloud storage service.
Security: Always protect your account ID and application keys. Avoid hardcoding them directly in scripts where possible; use environment variables or secure configuration methods.

AUTHENTICATION AND CONFIGURATION

Before using most b2 commands, you must authenticate. This is typically done via b2 authorize <accountId> <applicationKey>. This command stores your credentials securely in a configuration file (usually ~/.b2_account_info), allowing subsequent commands to operate without re-entering credentials. You can create multiple application keys in the Backblaze B2 web interface with different permissions.

SUBCOMMANDS STRUCTURE

The b2 tool employs a subcommand structure. After the main b2 command, you specify the operation you want to perform (e.g., ls, upload_file, delete_file, sync). Each subcommand has its own specific options and arguments. For example, to see options for listing files, you would run b2 ls --help.

HISTORY

The b2 command-line tool was developed as a crucial interface for Backblaze B2 Cloud Storage, which launched in 2015. Its inception provided users with a robust programmatic method to manage their cloud data, complementing the web-based interface. Written in Python, its development has closely tracked the evolution of the B2 API, continuously adding features for efficient data management, synchronization, and automation, making it an indispensable tool for developers and system administrators utilizing Backblaze B2.

SEE ALSO

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

Copied to clipboard