Dev.to WebDev 🛠 Dev 👁 0 📖 6 min read

A Restore Is Not Undo: Holding My Own SaaS Up to My Backup Checklist

I wrote a backup guide for small products on my own site. The short version: point-in-time recovery on, a second copy your own credentials cannot delete, an inventory of every place state lives outside the database, and

I wrote a backup guide for small products on my own site. The short version: point-in-time recovery on, a second copy your own credentials cannot delete, an inventory of every place state lives outside the database, and one timed restore rehearsal. It is a reasonable checklist, and I still think it is right.

This week I held two of my own products up against it: VoiceDash (white-label client portals for Retell voice agents, Next.js + Prisma on Supabase Postgres) and Upwork Scout (AI-matched Upwork job alerts, Next.js on Firestore). The checklist assumes the disaster is a dead database or a bad migration. Reading my own code, the most likely disaster is much smaller than that, and a full restore is the wrong tool for it.

My first move was the lazy one:

grep -ril "backup\|restore" lib app

In the Upwork Scout repo that matches four files: lib/db.ts, lib/models.ts, lib/publicJobs.ts and the scan route. None of them mention backups. Every single hit is the word Firestore, which happens to contain the letters r-e-s-t-o-r-e. Not a great start.

The disaster my code actually allows

VoiceDash has 23 Prisma models, and 21 relations are declared onDelete: Cascade. That is a sensible default for tenant data: delete a workspace and nothing orphaned is left behind. Then I followed one of those cascades from a button an agency can click.

// src/app/api/agents/[id]/route.ts
export async function DELETE(_req: Request, { params }: { params: Promise<{ id: string }> }) {
  // ...auth, look up platform + platformAgentId
  await prisma.agent.deleteMany({ where: { id, workspaceId } });
  // ...hand the Retell webhook to another workspace if one is connected
  return NextResponse.json({ success: true });
}

And in the schema:

model Conversation {
  agentId        String
  platformCallId String
  transcript     Json      @default("[]")
  tags           String[]  @default([])
  note           String?
  summary        String?
  evaluation     String?
  autoTags       String[]  @default([])
  // ...
  agent          Agent     @relation(fields: [agentId], references: [id], onDelete: Cascade)
}

Deleting an agent hard-deletes every conversation imported for it, along with the tags and notes the agency typed onto those calls. The UI does ask first: confirm("Delete this agent? This cannot be undone."). That sentence is accurate, which is the problem. One misclick on the wrong row in the agents list and a client's whole call history in the portal is gone.

Part of it can come back. The raw calls still live at Retell, and a new agent row starts with an empty callsSyncedUntil cursor, so reconnecting the agent should let a sync pull the calls in again, for as long as Retell keeps them. I have not tested that path end to end, so treat it as "should". The tags and notes cannot come back that way. They only ever existed in my database.

Why "we have backups" does not fix this

Say Supabase point-in-time recovery is on, and I notice the deletion an hour later. A point-in-time restore rewinds the whole database. Every other agency loses an hour of imported calls, new client logins, settings changes and webhook rows, to bring back one agency's notes.

On a multi-tenant product, a restore is not undo. It is a time machine for everyone at once. The checklist item "restore into a separate environment" turns out to be the real recovery method here, not just the rehearsal:

  1. Restore the backup to a new database, never over production.
  2. Copy only the rows you need (here, Conversation rows for one agentId) back into production.
  3. Re-create the parent row first, because the children point at it.

That is a script, and it has to be written before the day you need it. Mine does not exist yet.

The cheaper fix is not to need it. A deletedAt column on Agent, a route that sets it instead of deleting, and a scheduled job that purges after 30 days turns "restore a database" into "flip one field". VoiceDash has no deletedAt or archive flag on any model today. My guide listed soft deletes under "preventing the restore in the first place", and I wrote that line without checking my own schema.

The restore that sends emails twice

Upwork Scout taught me a different lesson: rewinding some state is worse than losing it.

The scan runs every 15 minutes. It uses two collections as memory of what already happened:

// app/api/cron/scan/route.ts
const ref = jobsCol().doc(job.id);
if (!(await ref.get()).exists) {
  await ref.set(job);
  newJobs.push(job);          // "new" = not in the jobs collection yet
}
// ...per user
const dRef = deliveriesCol().doc(`${u.uid}_${j.id}`);
if ((await dRef.get()).exists) continue;   // already alerted this user

jobs is the "have I seen this posting" ledger and deliveries is the "have I emailed this person about it" ledger. The daily alert cap lives on the user document as alertsSentToday.

Now restore Firestore to an hour ago. All three rewind together. Any job fetched in the last hour that is still inside the 24-hour freshness window (JOB_MAX_AGE_HOURS defaults to 24) is "new" again on the next scan, the delivery record that would have stopped a repeat is gone, and the cap counter says the user has room. So users get the same job alerts a second time. Email is the one side effect you cannot pull back.

The fix I would write into the runbook: after any restore, pause the scan (the workflow is a pinger, so disabling it is one click), let the freshness window pass or backfill the deliveries ledger from the email provider's send log, then resume. None of that is in the repo either.

The inventory, honestly

Layer three of my guide is "everything that is not in the database". For these two products, from the code:

State Where Comes back how
Users, workspaces, clients, calls Supabase Postgres Provider backups (plan tier not verified from this machine)
Raw calls, recordings Retell Re-sync, within Retell's retention
Tags, notes on calls Postgres only Backup restore to a side database + row copy
Alert subscribers, AI match verdicts Firestore Point-in-time recovery, if enabled; not on by default
Seen-jobs and sent-alerts ledgers Firestore Must be restored together, then reconciled
Config Vercel env Partly documented

That last row stung. Upwork Scout ships a .env.local.example with 5 variables; the real file has 9. The missing four include the Anthropic key name and the global daily fetch budget that caps scraping spend. VoiceDash has about 30 application variables (Stripe price IDs, Wise payment links, Retell, Vapi, Resend, Supabase) and no example file at all. If the Vercel project vanished, I would be rebuilding that list from grep process.env.

I also could not answer the first question in my own guide for either product: is point-in-time recovery actually switched on? Neither repo can tell you, because it is a console setting. That belongs in the README, with the date someone last looked.

What I am changing

In order, cheapest first:

  1. Write down the backup tier and PITR state for both databases in each README, with a date.
  2. Fix the env example files so they list every variable, values blank.
  3. Soft-delete Agent (and Client) in VoiceDash with a delayed purge.
  4. A restore-rows.ts script that copies one tenant's rows from a restored side database.
  5. A post-restore step for Upwork Scout: pause the pinger, reconcile deliveries, resume.
  6. Then, and only then, the timed rehearsal the guide insists on.

None of this is shipped yet. I am publishing the list because the gap between the guide and the repos was more useful to me than the guide.

The lesson I keep relearning: backup advice is written for the disaster that kills everything. A small multi-tenant SaaS is far more likely to meet the disaster that kills one customer's data through a button that works exactly as designed. Plan the undo for that one first.

If you run a multi-tenant app: when one customer deletes something by mistake, what is your actual recovery path? A soft delete, a side-database row copy, or "sorry"?

Adapted from my original guide, Backups and disaster recovery for a small product. Related: My Unique Index Decided Which Customer Owned Each Phone Call and I Wrote a Guide to Kill Switches. Then I Grepped My Own Code.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.