r/CloudFlare • • 6d ago

Question Workers backup ?

Is there a way to backup my workers , they are already connected to GitHub and set to auto deploy but what about the dns, r2, d1 and variables in the worker

Basically I want to say backup worker abc and have an offsite copy of everything needed to put that worker back together

5 Upvotes

17 comments sorted by

•

u/AutoModerator 6d ago

For faster advice with technical questions, we'd recommend asking in the Orange Cloud Discord server; the unofficial Cloudflare Discord server by the community, for the community. https://discord.gg/TrPNVKaagR

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/Lumethys 6d ago

everything needed to put that worker back together

terraform

1

u/carwash2016 6d ago

Ok any guides or repos someone has written where I give it my repo and a destination and backup done

2

u/Lumethys 6d ago

1

u/aguynamedbrand 6d ago

Lazy people don’t Google, they expect everything to be spoon-fed to them.

0

u/carwash2016 6d ago

or maybe i checked google and couldnt find anything

2

u/winner_68 2d ago

Git covers the code, but the part that actually bit me was the restore, not the backup. A Worker is really code plus config plus state, and the state is the bit that quietly doesn't come back with a git clone.

What I do now for my small Workers, including a Telegram bot Worker backed by D1, is keep the wrangler config in the repo so the bindings, routes, cron triggers and non-secret variables are all in one place, and keep a short restore note in the same repo listing every binding, custom domain, route and secret name, just the names, never the values, because secrets can't be read back once they're set. I store the actual secret values in a password manager.

For the data, I run a nightly export of D1 into an R2 bucket in a different account, then pull a copy down to my VPS as well, so the backup isn't sitting in the same account as the thing it backs up. That covers the database, but it doesn't cover KV, Durable Objects or the objects in R2 themselves, so those get their own export or sync. I also export the DNS zone as a file every now and then, it's a thirty second job and it's the cheapest insurance in the whole setup.

The bit I'd really push is testing the restore. The first time I tried rebuilding one of my Workers from my notes, it failed on a missing binding I'd forgotten to write down. Now I rebuild it on a staging Worker every couple of months and fix the notes when something's missing. A backup you've never restored is just a hope, and it's much better to find the gap on a quiet afternoon than when you're actually trying to put a Worker back together.

1

u/carwash2016 2d ago

Yes the bindings part as I also didn’t want to put the wrangler file into GitHub as that’s the one with the details i didn’t want leaked but also one of the most important ones

2

u/zhiqingl 2d ago

What I do for mine: keep wrangler.jsonc in the repo so bindings, routes, crons and non-secret vars are versioned; secrets can't be read back, so they live in a password manager. D1 gets a scheduled wrangler d1 export <db> --remote --output=backup-$(date +%F).sql (and Time Travel covers the "oops" cases for recent changes). R2 is S3-compatible, so rclone sync to another bucket/provider works. DNS you can export as a BIND zone file from the dashboard or the API. If you want it all as code, cf-terraforming will generate Terraform from your existing account, which is a decent starting point.

1

u/carwash2016 2d ago

I’ve heard of terraform just never used it , thanks

5

u/Known_Currency7966 6d ago

You might looking something like this ? https://github.com/gateweavehq/backup

8

u/DazzlingRecover5037 6d ago • Bravo

Hey, that's my project, thanks for sharing it! 🙌Yes, Gateweave Backup does scheduled, encrypted backups of D1, Durable Objects' SQLite and R2 into your own R2 bucket, with retention, alerts and restore tests that run every 30 days to prove the backups actually restore.

2

u/barth_dev 4d ago

I need to give it a try!

2

u/Opening-Commercial97 11h ago

The test I’d use is whether you can restore the app into a throwaway environment. Start with one D1 export, a small R2 sample, and the Worker config. If it boots but can’t read its data, you’ll know which bindings or settings are missing before you rely on the backup.

1

u/RelayForgeDev 6d ago

Git covers the code, but the Worker is really code + wrangler config + state, so back up those separately. Keep wrangler.jsonc in the repo so bindings, routes, cron and non-secret vars are rebuilt on deploy, and re-set secrets with wrangler secret put (store them in a password manager, since they can't be read back). For D1 run wrangler d1 export <db> --remote --output=backup.sql on a nightly GitHub Action and push it to a private repo or an R2 bucket in another account. For R2, rclone or aws s3 sync against the S3-compatible endpoint works fine for offsite copies. DNS you can export as a BIND file from the dashboard (or via the API) and that's the 30-second 'oh no' insurance; Terraform is nice but overkill if this is just a few Workers.