Skip to content
Latchkey

b2 sync: Back Up Directories to Backblaze B2

b2 sync copies only changed files between a local directory and a Backblaze B2 bucket, and with --delete removes files at the destination that are gone at the source.

B2 is a low-cost store often used for CI backups and artifact retention. b2 sync is its rsync-style transfer: incremental by default, mirror with --delete, and version-aware with --keepDays.

What it does

b2 sync compares a source and a b2://bucket/prefix and transfers only new or changed files. --delete removes destination files not in the source. Because B2 keeps versions, --keepDays controls how long old versions of overwritten or deleted files are retained.

Common usage

Terminal
b2 sync ./backup b2://my-bucket/backup
# exact mirror, dropping old versions after 7 days
b2 sync --delete --keepDays 7 ./backup b2://my-bucket/backup
# raise parallelism for many files
b2 sync --threads 20 ./artifacts b2://my-bucket/artifacts

Options

FlagWhat it does
--deleteDelete destination files not present in the source
--keepDays NKeep prior file versions for N days
--threads NNumber of parallel upload/download threads
--excludeRegex <re>Skip paths matching the regular expression
--dryRunShow what would happen without transferring

In CI

Authorize once with b2 authorize-account using a B2 application key ID and key from CI secrets (or B2_APPLICATION_KEY_ID / B2_APPLICATION_KEY env vars), then sync. Prefer an application key scoped to a single bucket over the master key. --delete plus --keepDays gives you a mirror with a short recovery window.

Common errors in CI

"ERROR: unable to authorize account" or "bad_auth_token" means the application key or key ID is wrong or expired; re-run authorize-account. "Bucket not found" means a wrong bucket name. " from_directory ... does not exist" is a missing local source path from a skipped build step. "AccessDenied"-style capability errors mean the application key lacks writeFiles or deleteFiles for --delete.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →