Skip to content
Cloudflare Docs

Changelog

New updates and improvements at Cloudflare. Subscribe to RSS

hero image

Set retention polices for your R2 bucket with bucket locks

Mar 06, 2025, 10:00 AM

You can now use bucket locks to set retention policies on your R2 buckets (or specific prefixes within your buckets) for a specified period — or indefinitely. This can help ensure compliance by protecting important data from accidental or malicious deletion.

Locks give you a few ways to ensure your objects are retained (not deleted or overwritten). You can:

  • Lock objects for a specific duration, for example 90 days.
  • Lock objects until a certain date, for example January 1, 2030.
  • Lock objects indefinitely, until the lock is explicitly removed.

Buckets can have up to 1,000 bucket lock rules. Each rule specifies which objects it covers (via prefix) and how long those objects must remain retained.

Here are a couple of examples showing how you can configure bucket lock rules using Wrangler:

Ensure all objects in a bucket are retained for at least 180 days

Terminal window
npx wrangler r2 bucket lock add <bucket> --name 180-days-all --retention-days 180

Prevent deletion or overwriting of all logs indefinitely (via prefix)

Terminal window
npx wrangler r2 bucket lock add <bucket> --name indefinite-logs --prefix logs/ --retention-indefinite

For more information on bucket locks and how to set retention policies for objects in your R2 buckets, refer to our documentation.