### Automatically Setup Replication Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/replication.md Use this command for a simplified replication setup between two buckets. It handles key provisioning and configuration automatically. ```sh $ b2 replication setup --destination-profile myprofile2 my-bucket my-bucket2 ``` -------------------------------- ### Install B2 CLI from Source Source: https://github.com/backblaze/b2_command_line_tool/blob/master/README.md Install the B2 CLI directly from its GitHub repository. This method is not recommended for general use and is intended for development or testing pre-release code. ```bash pip install git+https://github.com/Backblaze/B2_Command_Line_Tool.git ``` -------------------------------- ### Replication Setup Command Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/replication_setup.md Use this command to set up replication between two buckets. It can create or replace keys as needed and requires specific capabilities on both profiles. ```bash b2 replication setup [-h] [--destination-profile DESTINATION_PROFILE] [--name NAME] [--priority PRIORITY] [--file-name-prefix PREFIX] [--include-existing-files] SOURCE_BUCKET_NAME DESTINATION_BUCKET_NAME ``` -------------------------------- ### Install nox and uv Source: https://github.com/backblaze/b2_command_line_tool/blob/master/CONTRIBUTING.md Install the necessary development tools, nox and uv, using pip. These are required for running development automation tasks. ```bash pip install nox uv ``` -------------------------------- ### Install B2 CLI from PyPI (minimal) Source: https://github.com/backblaze/b2_command_line_tool/blob/master/README.md Install the B2 CLI from the Python Package Index without extra dependencies. A virtual environment is recommended. ```bash pip install b2 ``` -------------------------------- ### Install B2 CLI from PyPI (full) Source: https://github.com/backblaze/b2_command_line_tool/blob/master/README.md Install the B2 CLI from the Python Package Index with extra dependencies for improved debugging and performance. A virtual environment is recommended. ```bash pip install b2[full] ``` -------------------------------- ### Create B2 Bucket with Lifecycle Rules Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Create a B2 bucket and configure lifecycle rules for automatic file management. This example sets rules for temporary files and documents. ```bash b2 bucket create my-bucket allPrivate \ --lifecycle-rule '{"daysFromHidingToDeleting": 1, "daysFromUploadingToHiding": 7, "fileNamePrefix": "temporary/"}' \ --lifecycle-rule '{"daysFromHidingToDeleting": 1, "daysFromUploadingToHiding": null, "fileNamePrefix": "documents/"}' ``` -------------------------------- ### Install B2 CLI with Homebrew Source: https://github.com/backblaze/b2_command_line_tool/blob/master/README.md Use this command to install the B2 CLI on macOS using Homebrew. ```bash brew install b2-tools ``` -------------------------------- ### List specific files in directories matching a pattern Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/ls.md This example demonstrates listing `info.txt` files within directories that start with 'b' followed by any single character, using recursive search. ```bash b2 ls --recursive --with-wildcard "b2://bucketName/b?/info.txt" ``` -------------------------------- ### Install Bash Completion for B2 CLI Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/bash_completion.md Run this command to install bash completion for the b2 CLI. For other shells, consult the argcomplete documentation. ```bash b2 install-autocomplete ``` -------------------------------- ### Install Autocomplete Command Syntax Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/install-autocomplete.md This is the basic syntax for the `install-autocomplete` command. The shell can be autodetected or specified manually using the `--shell` argument. ```bash b2 install-autocomplete [-h] [--shell {bash,fish,zsh}] ``` -------------------------------- ### Set up B2 Replication Automatically Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Use `b2 replication setup` for automatic replication configuration between buckets. Supports specifying different profiles and custom rule priorities/names. ```bash b2 replication setup my-source-bucket my-dest-bucket ``` ```bash b2 replication setup \ --destination-profile myprofile2 \ my-source-bucket \ my-dest-bucket ``` ```bash b2 replication setup \ --destination-profile myprofile2 \ --priority 100 \ --rule-name daily-backup-rule \ my-source-bucket \ my-dest-bucket ``` -------------------------------- ### Install B2 Shell Tab-Completion Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Install shell tab-completion for the `b2` command using `b2 install-autocomplete`. Bash is supported natively; other shells like zsh and fish require `argcomplete`. ```bash # Install bash completion (adds hook to ~/.bashrc or equivalent) b2 install-autocomplete ``` ```bash # For zsh – activate argcomplete globally and reload shell activate-global-python-argcomplete --user exec zsh ``` ```bash # For fish – see https://pypi.org/project/argcomplete/#activating-global-completion ``` -------------------------------- ### bucket get Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Retrieves detailed information about a specific bucket, including its configuration, lifecycle rules, and replication settings. ```APIDOC ## bucket get — Get bucket details Returns detailed information about a specific bucket, including its settings, lifecycle rules, and replication configuration. ### Method `b2 bucket get ` ### Parameters - **bucketName** (string) - Required - The name of the bucket to retrieve details for. ### Optional Parameters - **--show-size** (boolean) - Includes the total size of the bucket in the output. ### Request Example ```bash b2 bucket get my-bucket b2 bucket get --show-size my-bucket ``` ``` -------------------------------- ### Get Account Information Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/account_get.md Use this command to retrieve details about your B2 account. It shows your account ID, key, authentication token, URLs, and application key capabilities. ```bash b2 account get [-h] ``` -------------------------------- ### Get Details of a Specific B2 Bucket Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Retrieve detailed information about a specified B2 bucket, including its configuration and settings. ```bash b2 bucket get my-bucket ``` -------------------------------- ### Sync with Regex Exclusion Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/sync.md Synchronizes files, excluding those matching the specified regular expressions. This example ignores `.DS_Store` files and `.Spotlight-V100` folders. ```default b2 sync --exclude-regex '(.*\.DS_Store)|(.*\.Spotlight-V100)' ... b2://... ``` -------------------------------- ### Get B2 Bucket Details with Size Information Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Retrieve detailed information about a specified B2 bucket, including its total size and the number of files it contains. ```bash b2 bucket get --show-size my-bucket ``` -------------------------------- ### Get Help for a Specific B2 Command Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/main_help.md Use this command structure to access detailed help for any specific B2 command. This is useful for understanding command-specific capabilities and options. ```default b2 --help ``` -------------------------------- ### Create Bucket with Replication Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_create.md Create a bucket and configure replication settings for cross-region data redundancy. ```bash b2 bucket create --replication '{"destination": {"bucketName": "your-replication-bucket"}}' bucketName {allPublic,allPrivate} ``` -------------------------------- ### List Application Keys Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/key_list.md Use this command to list all application keys for your account. The output includes key ID, name, bucket restrictions, expiration, file name prefix, and capabilities. Requires the `listKeys` capability. ```bash b2 key list [-h] [-l] ``` -------------------------------- ### Create Bucket with Lifecycle Rules Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_create.md Create a bucket and define lifecycle rules for managing object versions. Multiple rules can be specified. ```bash b2 bucket create --lifecycle-rule '{"daysFromHidingToDeleting": 1, "daysFromUploadingToHiding": null, "fileNamePrefix": "documents/"}' --lifecycle-rule '{"daysFromHidingToDeleting": 1, "daysFromUploadingToHiding": 7, "fileNamePrefix": "temporary/"}' bucketName {allPublic,allPrivate} ``` -------------------------------- ### List Files with Options Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Use 'b2 ls' to list files. Options include showing all versions, recursive listing, wildcard matching, and filtering with include/exclude patterns. For machine-readable output, use the --json flag. ```bash b2 ls --versions b2://my-bucket/data/ ``` ```bash b2 ls --recursive --with-wildcard "b2://my-bucket/*.[ct]sv" ``` ```bash b2 ls --recursive --with-wildcard "b2://my-bucket/b[0-9]/*.pdf" ``` ```bash b2 ls --recursive --include "*.log" --exclude "debug-*" b2://my-bucket/app/ ``` ```bash b2 ls --json b2://my-bucket/ | jq '.[].fileName' ``` -------------------------------- ### Create a Bucket Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_create.md Basic command to create a bucket with a specified name and access level. ```bash b2 bucket create bucketName {allPublic,allPrivate} ``` -------------------------------- ### Build Documentation with Watch Mode Source: https://github.com/backblaze/b2_command_line_tool/blob/master/CONTRIBUTING.md Use this command to build the documentation and automatically recompile it when changes are detected in the source code. ```bash nox -s doc ``` -------------------------------- ### B2 CLI Usage Overview Source: https://github.com/backblaze/b2_command_line_tool/blob/master/README.md This is a general overview of available B2 CLI commands. Use ' --help' for specific command details. ```bash b2 account Account management subcommands. b2 bucket Bucket management subcommands. b2 file File management subcommands. b2 install-autocomplete Install autocomplete for supported shells. b2 key Application keys management subcommands. b2 license Print the license information for this tool. b2 ls List files in a given folder. b2 replication Replication rule management subcommands. b2 rm Remove a "folder" or a set of files matching a pattern. b2 sync Copy multiple files from source to destination. b2 version Print the version number of this tool. ``` -------------------------------- ### Copy Usage String to README Source: https://github.com/backblaze/b2_command_line_tool/blob/master/README.release.md Copies the main usage string from 'b2 --help' to README.md. This command ensures a consistent format for the usage information. ```bash COLUMNS=4000 b2 --help | awk '/^usages:/ {p=1; next} p {sub(/^ */, "", $0); print}' ``` -------------------------------- ### account get Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Retrieves and displays information about the currently authorized account, including account ID, authentication token, API URLs, and granted capabilities. ```APIDOC ## account get — Show current account info Prints account ID, application key ID, auth token, API/download URLs, and the capabilities granted to the currently authorized key. ### Method `b2 account get` ### Response #### Success Response (200) - **accountId** (string) - The account ID. - **authToken** (string) - The authentication token. - **apiUrl** (string) - The API endpoint URL. - **downloadUrl** (string) - The download endpoint URL. - **allowed** (object) - An object detailing the granted capabilities. - **capabilities** (array of strings) - List of allowed capabilities. - **bucketId** (string or null) - The bucket ID if capabilities are restricted to a specific bucket. - **bucketName** (string or null) - The bucket name if capabilities are restricted to a specific bucket. - **namePrefix** (string or null) - The name prefix if capabilities are restricted. ### Response Example ```json { "accountId": "YOUR_ACCOUNT_ID", "authToken": "...", "apiUrl": "https://api003.backblazeb2.com", "downloadUrl": "https://f003.backblazeb2.com", "allowed": { "capabilities": ["listBuckets","listFiles","readFiles","writeFiles",...], "bucketId": null, "bucketName": null, "namePrefix": null } } ``` ``` -------------------------------- ### Get B2 Download Authorization Token Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Generate a temporary token for downloading from private buckets without a full application key. The token can be restricted by prefix and duration. ```bash b2 bucket get-download-auth my-private-bucket # Default: 86400 seconds (1 day) ``` ```bash b2 bucket get-download-auth --prefix images/ --duration 3600 my-private-bucket # Token valid for 1 hour, restricted to the "images/" prefix ``` -------------------------------- ### Build Documentation Non-Interactively Source: https://github.com/backblaze/b2_command_line_tool/blob/master/CONTRIBUTING.md Run this command to build the documentation without interactive prompts. Useful for automated builds. ```bash nox --non-interactive -s doc ``` -------------------------------- ### List all buckets Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/ls.md To list all available buckets, simply run the `b2 ls` command without any arguments. ```bash b2 ls ``` -------------------------------- ### Manually Configure B2 Replication Rules Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Configure replication manually using `b2 key create` and `b2 bucket update` for cross-account replication when accounts are not simultaneously accessible. Ensure correct permissions are granted. ```bash # Step 1: Create a source replication key (source account) b2 key create my-bucket-rplsrc readFiles,readFileLegalHolds,readFileRetentions # Output: 0014ab1234567890000000123 K001ZA12345678901234567890ABCDE ``` ```bash # Step 2: Configure source bucket replication rules b2 bucket update --replication '{ "asReplicationSource": { "replicationRules": [{ "destinationBucketId": "85644d98debc657d880b0e1e", "fileNamePrefix": "files-to-share/", "includeExistingFiles": false, "isEnabled": true, "priority": 128, "replicationRuleName": "my-replication-rule-name" }], "sourceApplicationKeyId": "0014ab1234567890000000123" } }' my-source-bucket ``` ```bash # Step 3: Create a destination replication key (destination account) b2 --profile myprofile2 key create my-bucket-rpldst \ writeFiles,writeFileLegalHolds,writeFileRetentions,deleteFiles # Output: 0024ab2345678900000000234 K001YYABCDE12345678901234567890 ``` ```bash # Step 4: Configure destination bucket b2 --profile myprofile2 bucket update --replication '{ "asReplicationDestination": { "sourceToDestinationKeyMapping": { "0014ab1234567890000000123": "0024ab2345678900000000234" } } }' my-dest-bucket ``` -------------------------------- ### Create a Simple Public B2 Bucket Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Create a new B2 bucket with public access. The bucket name must be globally unique. ```bash b2 bucket create my-public-bucket allPublic ``` -------------------------------- ### List PDF files in directories with a numeric prefix Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/ls.md Recursively list all PDF files located in directories named 'b0' through 'b9' (or any directory starting with 'b' followed by a digit). ```bash b2 ls --recursive --with-wildcard "b2://bucketName/b[0-9]/*.pdf" ``` -------------------------------- ### List Application Keys Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Use 'b2 key list' to view all application keys associated with your account. The output includes key ID, name, capabilities, and restrictions. Use --json for machine-readable output. ```bash b2 key list ``` ```bash b2 key list --json ``` -------------------------------- ### Create Application Key Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Use 'b2 key create' to generate new application keys. You can specify capabilities, restrict access to specific buckets or name prefixes, and set expiration durations. Use --all-capabilities with caution. ```bash b2 key create readonly-key readFiles,listFiles,listBuckets ``` ```bash b2 key create bucket-key readFiles,writeFiles,listFiles --bucket my-bucket ``` ```bash b2 key create temp-key readFiles --duration 3600 ``` ```bash b2 key create prefix-key readFiles,listFiles \ --bucket my-bucket \ --name-prefix images/ ``` ```bash b2 key create admin-key --all-capabilities ``` -------------------------------- ### Get Current B2 Account Info Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Retrieve and display information about the currently authorized B2 account, including account ID, auth token, API URLs, and granted capabilities. ```bash b2 account get ``` -------------------------------- ### Set Python versions for nox Source: https://github.com/backblaze/b2_command_line_tool/blob/master/CONTRIBUTING.md Configure the Python versions nox will use for sessions by setting the NOX_PYTHONS environment variable. This example sets nox to use Python 3.10 and 3.13. ```bash export NOX_PYTHONS=3.10,3.13 ``` -------------------------------- ### Bucket List Command Usage Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_list.md Shows the basic command structure for listing buckets, including help and JSON output flags. Requires the 'listBuckets' capability. ```bash b2 bucket list [-h] [--json] ``` -------------------------------- ### Create Bucket with Custom Encryption Algorithm Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_create.md Create a bucket with a specific default server-side encryption algorithm. SSE-B2 is the only supported algorithm. ```bash b2 bucket create --default-server-side-encryption=SSE-B2 --default-server-side-encryption-algorithm=AES256 bucketName {allPublic,allPrivate} ``` -------------------------------- ### Enable Custom Log Configuration in B2 CLI Source: https://github.com/backblaze/b2_command_line_tool/blob/master/README.md Enable logging with a user-defined format and verbosity by using the hidden --log-config flag, specifying a configuration file. Refer to the example log configuration for details. ```bash b2 --log-config ``` -------------------------------- ### Get B2 CLI Version Information Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Use `b2 version` to display the current CLI version and active ApiVer interface. Use `--list` to see available interfaces and `b2v4 version` for version-pinned commands. ```bash b2 version # Output: b2 command line tool, version 4.7.0 ``` ```bash # Show available CLI ApiVer interfaces b2 version --list # Output: # b2v3 (legacy) # b2v4 (latest stable) ``` ```bash # Use the version-pinned command (safe for long-lived scripts) b2v4 version ``` -------------------------------- ### Get file metadata Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Use `b2 file info` to retrieve all metadata for a specific file version, including its ID, name, size, content type, upload timestamp, and encryption status. You can specify the file by its bucket path or its unique file ID. ```bash b2 file info b2://my-bucket/path/to/file.txt ``` ```bash b2 file info b2id://4_za71f544e781e6891531b001a_f200ec353a2184825_d20160409_m004829_c001_v0001016_t0028 ``` -------------------------------- ### Authorize B2 Account with CLI Arguments Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Authorize your B2 account by providing `applicationKeyId` and `applicationKey` directly on the command line. This is not recommended due to credential exposure in the process list. ```bash b2 account authorize 4ab123456789 001aabbccddeeff123456789012345678901234567 ``` -------------------------------- ### Get public download URL for a file Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Generate a public download URL for a file using `b2 file url`. For private buckets, use the `--with-auth` flag to include a time-limited authorization token. The token duration can be customized with the `--duration` flag. ```bash # Get URL for a public file b2 file url b2://my-public-bucket/images/photo.jpg ``` ```bash # Get pre-authorized URL for a private file (valid for 1 day by default) b2 file url --with-auth b2://my-private-bucket/docs/report.pdf ``` ```bash # Custom token duration (in seconds) b2 file url --with-auth --duration 3600 b2://my-private-bucket/assets/video.mp4 ``` -------------------------------- ### Display help for b2 command Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/account_clear.md Use this command to view details about the B2 command-line tool, including how the cache location is determined. ```default b2 --help ``` -------------------------------- ### Create Source Replication Key Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/replication.md Creates a key for the source bucket with read permissions necessary for replication. Ensure the key has the specified capabilities. ```sh $ b2 key create my-bucket-rplsrc readFiles,readFileLegalHolds,readFileRetentions 0014ab1234567890000000123 K001ZA12345678901234567890ABCDE ``` -------------------------------- ### Configure Destination Bucket for Replication Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/replication.md Sets up the destination bucket to accept replicated files by mapping the source application key ID to the destination application key ID. This establishes the trust relationship for replication. ```sh $ b2 bucket update --profile myprofile2 --replication '{ "asReplicationDestination": { "sourceToDestinationKeyMapping": { "0014ab1234567890000000123": "0024ab2345678900000000234" } } }' my-bucket ``` -------------------------------- ### Create Bucket with SSE-B2 Encryption Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_create.md Create a bucket with SSE-B2 encryption enabled by default for all uploads. The default algorithm is AES256. ```bash b2 bucket create --default-server-side-encryption=SSE-B2 bucketName {allPublic,allPrivate} ``` -------------------------------- ### Sync with Deletion and Replacement Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/sync.md Use this command to make the destination exactly match the source by deleting extraneous files and replacing newer destination files with older source files. ```bash b2 sync --delete --replace-newer ... ... ``` -------------------------------- ### File Download Command Syntax Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/file_download.md This is the general syntax for the `b2 file download` command. Use this to understand the required and optional arguments. ```bash b2 file download [-h] [--threads THREADS] [--max-download-streams-per-file MAX_DOWNLOAD_STREAMS_PER_FILE] [--no-progress] [--source-server-side-encryption {SSE-C}] [--source-server-side-encryption-algorithm {AES256}] [--write-buffer-size BYTES] [--skip-hash-verification] B2_URI localFileName ``` -------------------------------- ### Bucket Notification Rule Create Command Syntax Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_notification-rule_create.md This shows the general syntax for the `b2 bucket notification-rule create` command, including all available optional arguments. ```bash b2 bucket notification-rule create [-h] --event-type EVENT_TYPE --webhook-url WEBHOOK_URL [--sign-secret SIGN_SECRET] [--custom-header CUSTOM_HEADER] [--enable] [--disable] [--json] B2_URI ruleName ``` -------------------------------- ### Synchronize Directories Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Use 'b2 sync' for bidirectional synchronization between local and B2. Supports uploads, downloads, bucket-to-bucket sync, pruning, versioning, filtering, encryption, and dry-runs. Tune parallelism with --threads. ```bash b2 sync /home/user/data/ b2://my-bucket/backups/data/ ``` ```bash b2 sync b2://my-bucket/backups/data/ /home/user/data-restore/ ``` ```bash b2 sync b2://source-bucket/ b2://dest-bucket/mirror/ ``` ```bash b2 sync --delete --replace-newer /home/user/data/ b2://my-bucket/data/ ``` ```bash b2 sync --keep-days 30 --replace-newer /home/user/data/ b2://my-bucket/data/ ``` ```bash b2 sync --exclude-regex '(.*\.DS_Store)|(.*\.Spotlight-V100)' \ /home/user/data/ b2://my-bucket/data/ ``` ```bash b2 sync --dry-run /home/user/data/ b2://my-bucket/data/ ``` ```bash b2 sync --threads 2 /home/user/data/ b2://my-bucket/data/ ``` ```bash b2 sync --destination-server-side-encryption SSE-B2 \ /home/user/data/ b2://my-bucket/data/ ``` ```bash b2 sync --incremental-mode /home/user/logs/ b2://my-bucket/logs/ ``` ```bash b2 sync --exclude-if-modified-after 1700000000 /home/user/data/ b2://my-bucket/data/ ``` -------------------------------- ### File Upload Command Syntax Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/file_upload.md This is the general syntax for the file upload command. Use this to understand the available arguments and options for uploading files. ```bash b2 file upload [-h] [--content-type CONTENT_TYPE] [--sha1 SHA1] [--info INFO] [--custom-upload-timestamp CUSTOM_UPLOAD_TIMESTAMP] [--cache-control CACHE_CONTROL] [--content-disposition CONTENT_DISPOSITION] [--content-encoding CONTENT_ENCODING] [--content-language CONTENT_LANGUAGE] [--expires EXPIRES] [--min-part-size MIN_PART_SIZE] [--threads THREADS] [--no-progress] [--destination-server-side-encryption {SSE-B2,SSE-C}] [--destination-server-side-encryption-algorithm {AES256}] [--legal-hold {on,off}] [--file-retention-mode {compliance,governance}] [--retain-until TIMESTAMP] [--incremental-mode] bucketName localFilePath b2FileName ``` -------------------------------- ### b2 ls command usage Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/ls.md This shows the general syntax and available options for the `b2 ls` command, including optional flags for detailed output, JSON formatting, replication status, versioning, recursion, wildcard matching, and include/exclude filters. ```bash b2 ls [-h] [-l] [--json] [--replication] [--versions] [-r] [--with-wildcard] [--include FILTERS] [--exclude FILTERS] [B2_URI] ``` -------------------------------- ### Run nox format session Source: https://github.com/backblaze/b2_command_line_tool/blob/master/CONTRIBUTING.md Execute the 'format' nox session to automatically format the code. This uses ruff for code formatting. ```bash nox -s format ``` -------------------------------- ### Authorize B2 Account using Environment Variables Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Authorize your B2 account by setting `B2_APPLICATION_KEY_ID` and `B2_APPLICATION_KEY` environment variables. This is the recommended method to avoid credential exposure. ```bash export B2_APPLICATION_KEY_ID="$(cat file-with-key-id.txt)" export B2_APPLICATION_KEY="$(cat file-with-key.txt)" b2 account authorize ``` -------------------------------- ### Upload Single File via Pipe to Docker Source: https://github.com/backblaze/b2_command_line_tool/blob/master/README.md Upload a single file to Backblaze B2 by piping its content to the Docker container. Ensure the b2 Docker image is available and the volume 'b2' is mounted. ```bash cat source_file.txt | docker run -i --rm -v b2:/root backblazeit/b2:latest b2v4 upload-unbound-stream bucket_name - target_file_name ``` -------------------------------- ### Authorize account with positional arguments Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/account_authorize.md Authorize your Backblaze B2 account by providing the application key ID and application key as positional arguments. This command requires the 'listBuckets' capability. ```bash b2 account authorize [-h] [applicationKeyId] [applicationKey] ``` -------------------------------- ### Configure Source Bucket for Replication Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/replication.md Updates the source bucket's replication settings, specifying the destination bucket, file prefix, and other rule parameters. The `sourceApplicationKeyId` must match the key created previously. ```sh $ b2 bucket update --replication '{ "asReplicationSource": { "replicationRules": [ { "destinationBucketId": "85644d98debc657d880b0e1e", "fileNamePrefix": "files-to-share/", "includeExistingFiles": false, "isEnabled": true, "priority": 128, "replicationRuleName": "my-replication-rule-name" } ], "sourceApplicationKeyId": "0014ab1234567890000000123" } }' my-bucket ``` -------------------------------- ### List Buckets (Human-Readable) Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_list.md Displays bucket information including ID, type, and name in a human-readable format. This is the default output when no formatting options are specified. ```bash 98c960fd1cb4390c5e0f0519 allPublic my-bucket ``` -------------------------------- ### Create a Private B2 Bucket with SSE-B2 Encryption Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Create a new private B2 bucket that enforces Server-Side Encryption with Backblaze B2 (SSE-B2) by default for all uploaded files. ```bash b2 bucket create my-private-bucket allPrivate \ --default-server-side-encryption=SSE-B2 ``` -------------------------------- ### Use B2 CLI with Docker Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Utilize the official `backblazeit/b2:latest` Docker image for B2 CLI operations. Persist credentials using volumes and specify API versions for script stability. ```bash # Authorize once and persist credentials in a named Docker volume docker run --rm -it -v b2credentials:/root backblazeit/b2:latest b2v4 account authorize ``` ```bash # List buckets using persisted credentials docker run --rm -v b2credentials:/root backblazeit/b2:latest b2v4 bucket list ``` ```bash # Upload via stdin pipe (no local file mount needed) cat source_file.txt | docker run -i --rm -v b2credentials:/root \ backblazeit/b2:latest b2v4 upload-unbound-stream my-bucket - target_file.txt ``` ```bash # Upload by mounting a local directory into the container docker run --rm \ -v b2credentials:/root \ -v /home/user/data:/data \ backblazeit/b2:latest b2v4 file upload my-bucket /data/source.txt remote/target.txt ``` ```bash # Pass credentials via environment variables (no volume needed for auth) B2_APPLICATION_KEY= B2_APPLICATION_KEY_ID= \ docker run --rm -e B2_APPLICATION_KEY -e B2_APPLICATION_KEY_ID \ backblazeit/b2:latest b2v4 bucket list ``` -------------------------------- ### Print b2 tool version Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/version.md Use this command to display the full version number of the b2 command-line tool. No arguments are required. ```bash b2 version ``` -------------------------------- ### Create a File-Lock Enabled B2 Bucket Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Create a new B2 bucket with file locking enabled, suitable for compliance and governance retention requirements. ```bash b2 bucket create my-locked-bucket allPrivate --file-lock-enabled ``` -------------------------------- ### Run B2 CLI with Docker Source: https://github.com/backblaze/b2_command_line_tool/blob/master/README.md Execute B2 CLI commands using the official Docker image. Replace '...' with your desired command. ```bash docker run backblazeit/b2:latest ... ``` -------------------------------- ### ls Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Lists files and virtual folders using B2's `/`-delimited naming convention. Supports recursive listing, wildcards, version history, long output, and JSON output. ```APIDOC ## `ls` — List files in a bucket or folder Lists files and virtual folders using B2's `/`-delimited naming convention. Supports recursive listing, wildcards, version history, long output, and JSON output. ```bash # List top-level entries in a bucket b2 ls b2://my-bucket/ # List all buckets b2 ls # Long format (shows size, date, file ID, type) b2 ls --long b2://my-bucket/photos/ # Recursive listing of all files under a prefix b2 ls --recursive b2://my-bucket/logs/ ``` ``` -------------------------------- ### Create a B2 Bucket Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/quick_start.md Create a new B2 bucket with a specified name and privacy setting. Optional configurations for storage, CORS, and lifecycle rules can be applied. ```sh $ b2 bucket create example-mybucket-b2-3 allPublic ... ``` -------------------------------- ### Set Lifecycle Rules for a Bucket Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_update.md Use the `--lifecycle-rule` option to set lifecycle rules for a bucket. Multiple rules can be specified by repeating the option. All rules are set at once, so provide all existing rules if adding a new one. ```bash b2 bucket update --lifecycle-rule '{"daysFromHidingToDeleting": 1, "daysFromUploadingToHiding": null, "fileNamePrefix": "documents/"}' --lifecycle-rule '{"daysFromHidingToDeleting": 1, "daysFromUploadingToHiding": 7, "fileNamePrefix": "temporary/"}' ``` -------------------------------- ### Enable Bucket Notification Rule Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_notification-rule_enable.md Use this command to enable an existing notification rule for a bucket. Ensure you have the necessary read and write bucket notification capabilities. ```bash b2 notification-rule enable b2://bucketName/ ruleName ``` -------------------------------- ### bucket create Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt Creates a new Backblaze B2 bucket with specified name and visibility. Supports advanced configurations like server-side encryption, lifecycle rules, and file locking. ```APIDOC ## bucket create — Create a new bucket Creates a new B2 bucket with the given name and visibility type. Supports SSE-B2 encryption, lifecycle rules, CORS, and file lock. ### Method `b2 bucket create ` ### Parameters - **bucketName** (string) - Required - The desired name for the new bucket. - **bucketType** (string) - Required - The visibility type for the bucket (e.g., `allPublic`, `allPrivate`). ### Optional Parameters - **--default-server-side-encryption** (string) - Sets the default server-side encryption for the bucket (e.g., `SSE-B2`). - **--lifecycle-rule** (string) - Defines a lifecycle rule for the bucket. Can be specified multiple times. - **--file-lock-enabled** (boolean) - Enables file locking for the bucket. ### Request Example ```bash # Simple public bucket b2 bucket create my-public-bucket allPublic # Private bucket with SSE-B2 encryption b2 bucket create my-private-bucket allPrivate --default-server-side-encryption=SSE-B2 # Bucket with lifecycle rules b2 bucket create my-bucket allPrivate --lifecycle-rule '{"daysFromHidingToDeleting": 1, "daysFromUploadingToHiding": 7, "fileNamePrefix": "temporary/"}' # File-lock-enabled bucket b2 bucket create my-locked-bucket allPrivate --file-lock-enabled ``` ``` -------------------------------- ### List All B2 Buckets Source: https://context7.com/backblaze/b2_command_line_tool/llms.txt List all buckets associated with the authorized B2 account, displaying their ID, type, and name. ```bash b2 bucket list ``` -------------------------------- ### Create a Bucket Notification Rule Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_notification-rule_create.md Use this command to create a new notification rule for a bucket. Specify the bucket URI, rule name, event type, and the webhook URL for receiving notifications. ```bash b2 notification-rule create b2://bucketName/optionalSubPath/ ruleName --event-type "b2:ObjectCreated:*" --webhook-url https://example.com/webhook ``` -------------------------------- ### Bucket Notification Rule Enable Command Usage Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/subcommands/bucket_notification-rule_enable.md This shows the general syntax for enabling a bucket notification rule, including optional arguments like help and JSON output. ```bash b2 bucket notification-rule enable [-h] [--json] B2_URI ruleName ``` -------------------------------- ### Authorize B2 Account with Credentials Source: https://github.com/backblaze/b2_command_line_tool/blob/master/doc/source/quick_start.md Authorize your B2 account using your application key ID and application key. Provide credentials directly or use environment variables for security. ```sh $ b2 account authorize 4ab123456789 001aabbccddeeff123456789012345678901234567 Using https://api.backblazeb2.com ``` ```sh $ export B2_APPLICATION_KEY_ID="$(