This guide sets up automated database backups in Coolify that ship to a Cloudflare R2 bucket. R2 is cheap, S3-compatible and has zero egress fees, so restoring costs nothing extra. By the end, your Postgres, MySQL, MariaDB or MongoDB container will back itself up on a schedule and copy the file off-server.
What you'll need
- A Cloudflare account (R2 requires a payment method on file, but the free tier includes 10 GB of storage)
- A running Coolify instance with at least one database resource
- About 15 minutes
Part 1: Set up R2 on Cloudflare
Step 1: Open R2 in your Cloudflare dashboard
Log in to the Cloudflare dashboard, then pick Storage & databases → R2 Object Storage from the left sidebar. If this is your first time, you'll be asked to add a payment method and accept the R2 terms. You won't be charged within the free tier.

Step 2: Create a bucket
Click Create bucket and fill in:
- Bucket name: something descriptive, like
myapp-db-backups. Names are lowercase, with no spaces. - Location: leave it on Automatic, or pick a region close to your server.
- Default storage class: Standard.
Click Create bucket.
Tip: Use one bucket per project or environment (for example
myapp-prod-backups). It keeps permissions tight and makes cleanup easy.

Step 3: Confirm the bucket exists
You'll land on the bucket's page. It's empty for now. Leave Public access disabled, because backups should never be public.

Step 4: Create an R2 API token
Go back to the R2 overview and click Manage R2 API Tokens (the API section on the right), then Create API token.

Step 5: Scope the token
Configure the token with the least privilege it needs:
- Token name:
coolify-backups - Permissions: Object Read & Write
- Specify bucket(s): choose Apply to specific buckets only and select your backup bucket
- TTL: leave it as Forever, or set a rotation date you'll remember
Click Create API Token.

Step 6: Copy your credentials
Cloudflare now shows the credentials once. Copy these into a password manager:
Warning: The secret key is never shown again. If you lose it, delete the token and create a new one.
Gotcha: The endpoint is the account-level URL and does not include the bucket name. If you copy one with
/bucket-nameon the end, remove that part.

Part 2: Connect R2 to Coolify
Step 7: Add an S3 storage in Coolify
In Coolify, open Storages from the sidebar (on some versions it's under Settings) and click Add. Fill in:
- Name:
Cloudflare R2 – Backups - Endpoint:
https://<ACCOUNT_ID>.r2.cloudflarestorage.com - Bucket:
myapp-db-backups - Region:
auto - Access Key: your Access Key ID
- Secret Key: your Secret Access Key

Step 8: Validate and save
Click Validate Connection & Continue. If Coolify can reach the bucket with those credentials, you'll see a success message and the storage appears in your list.
If validation fails, check these in order:
- The endpoint has no bucket name and starts with
https://. - The token is scoped to this exact bucket with Object Read & Write.
- The region is
auto. - There are no stray spaces in the keys.

Part 3: Automate your database backups
Step 9: Open your database's Backups tab
Go to Projects → your project → your environment → your database, then open the Backups tab. Click + Add (or Create Scheduled Backup).

Step 10: Configure the schedule
Set up the backup job:
- Frequency: a cron expression or preset.
0 2 * * *runs daily at 2 AM, and0 */6 * * *runs every 6 hours. - Save to S3: turn it on, then select Cloudflare R2 – Backups.
- Retention: set how many backups to keep, for how many days, and a maximum storage size. For example, keep 7 locally, 30 days in S3 and cap storage at 10 GB. Retention is applied separately to local and S3 copies.
- Databases to back up: for Postgres you can pick specific databases, or back up all of them.
Click Save.
Tip: Keep local retention small, such as 2–3 copies. R2 holds the long history, and local copies only eat up your server's disk.

Step 11: Run a backup now to test it
Don't wait until 2 AM to find out it's broken. Click Backup Now, then watch the Executions list. A healthy run shows a Success status with a file size and timestamp.

Step 12: Verify the file landed in R2
Back in Cloudflare, open your bucket and refresh the Objects tab. You should see a folder named after your database or container, with your timestamped backup file inside.
That file sitting in R2, off your server, is your proof the pipeline works.

Restoring from a backup
Coolify can restore from a backup file for some database types, and you can always restore by hand:
- Download the file from R2 (Objects → select file → Download).
- Copy it to your server or run the restore locally.
- Restore with the native tool, for example:
# Postgres (custom format dump) pg_restore -U postgres -d mydb --clean --if-exists backup.dmp # MySQL / MariaDB gunzip < backup.sql.gz | mysql -u root -p mydb
Practise a restore into a throwaway database at least once. An untested backup is a hope, not a backup.
Bonus: lifecycle rules to cap R2 costs
Besides Coolify's retention settings, you can have R2 expire old objects on its own. In your bucket, go to Settings → Object lifecycle rules → Add rule, and set Delete objects after something like 60 days. That acts as a safety net if Coolify's cleanup ever fails.
Quick checklist
- R2 bucket created, with public access off
- API token scoped to that bucket with Object Read & Write
- Credentials stored in a password manager
- S3 storage validated in Coolify
- Scheduled backup with Save to S3 enabled
- Manual Backup Now succeeded and the file is visible in R2
- Test restore done at least once
Wrap up
Your database now backs itself up on a schedule and stores the copies on infrastructure that is separate from your server, at a cost that's usually pennies per month. It takes about 15 minutes to set up, and it's the cheapest insurance you can buy for a production backend.
Note: Screenshots and images are for illustration purposes only, are subject to change, and may not perfectly mirror the live interface.
Found this useful? Share it with the friend who still keeps their only database backup on the same VPS.





