Skip to main content

CLI tool to clean up unfinished Backblaze B2 large uploads

Project description

b2-cleanup

🧹 A Python CLI tool to clean up unfinished large file uploads in a Backblaze B2 bucket.

Built using b2sdk, click, and uv for performance and reproducibility.


🔧 Features

  • Lists all unfinished large file uploads in a given B2 bucket
  • Optionally cancels them (dry-run support included)
  • Uses the official b2sdk for native Backblaze API access
  • Supports authentication via env vars, CLI override, or the b2 CLI
  • Clean CLI with logging support
  • Class-based and easily extensible

🚀 Installation

1. Clone and create an isolated environment

git clone https://github.com/<your-username>/b2-cleanup.git
cd b2-cleanup

uv venv
source .venv/bin/activate
uv pip install -e .

Requires uv and Python 3.8+


🧪 Usage

b2-cleanup BUCKET_NAME [OPTIONS]

Example (dry run):

b2-cleanup my-bucket --dry-run

Example (delete for real, with logging):

b2-cleanup my-bucket --log-file cleanup_$(date +%F).log

Example (override credentials):

b2-cleanup my-bucket --key-id my-key-id --key my-app-key

🔐 Authentication

This tool supports three ways to authenticate with B2, in priority order:

  1. Explicit CLI arguments:

    b2-cleanup my-bucket --key-id abc123 --key supersecretkey
    
  2. Environment variables:

    export B2_APPLICATION_KEY_ID=abc123
    export B2_APPLICATION_KEY=supersecretkey
    
  3. The b2 CLI (must be previously authorized):

    b2 account authorize
    # Then the tool will read credentials via:
    b2 account info
    

📁 Project Structure

b2-cleanup/
├── cleanup_unfinished_b2_uploads.py   # Core CLI logic (class-based)
├── pyproject.toml                     # Project metadata + dependencies
├── .gitignore
└── README.md

📦 Packaging Notes

  • The CLI entry point is b2-cleanup via pyproject.toml
  • Install in editable mode (uv pip install -e .) for fast development
  • Dependencies are managed via uv

🛠️ Roadmap

  • Filter uploads by file age
  • Support multiple buckets
  • Output metrics (count, size, cost saved)
  • Optional integration with S3-compatible B2 APIs

📝 License

MIT License © 2025 Jeroen Verhoeven

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

b2_cleanup-0.1.3.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

b2_cleanup-0.1.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file b2_cleanup-0.1.3.tar.gz.

File metadata

  • Download URL: b2_cleanup-0.1.3.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.7.2

File hashes

Hashes for b2_cleanup-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fab36e56497f006d87ef1ede7eb134c50d1d601189a5dfb692db3e262453b204
MD5 808251644d4991e97693c2403ba67965
BLAKE2b-256 75c8c661d77f3703047e897cb1e2be864e9234be42d454d7db06d6a8b14712af

See more details on using hashes here.

File details

Details for the file b2_cleanup-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for b2_cleanup-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3e9b2d6872ae719d6297c5a63130bfe4e579dda6cef21a355bd1db9be67306d0
MD5 2ef48828239b80773c79f45d3045cdee
BLAKE2b-256 39633fcbfcb1b3e63a052aa2f61cc7cc480ca2c18bfe31b70baec64a481d5d2c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page