Every engineer has a version of this story: a command typed in the wrong terminal window. What made GitLab's incident famous was not the mistake but what came after it. The company had several backup and replication mechanisms, and when it needed them, none of them worked the way everyone assumed. GitLab also did something unusual: it debugged in public and then published a detailed postmortem. That document remains one of the best free lessons on backups available.
What happened in the GitLab database incident?
According to GitLab's postmortem:
- A spike in database load, likely from spam plus a background job removing an account that had been wrongly flagged for abuse, caused the secondary PostgreSQL database to fall behind the primary.
- The primary had already removed the write-ahead log (WAL) segments the secondary needed, so the secondary had to be rebuilt by hand. Attempts to do this hung, and settings were changed while troubleshooting.
- Late in the evening, an engineer decided to wipe the secondary's data directory and start again. The command was run on the primary.
- It was stopped within seconds, but roughly 300 GB of data was already gone.
The team then went looking for the most recent good copy of the database.
Why did every backup method fail?
| Mechanism | What GitLab assumed | What was actually true |
|---|---|---|
| Daily pg_dump to S3 | Regular logical backups | The job used pg_dump 9.2 against a PostgreSQL 9.6 database, so every run failed. The failure emails were rejected because DMARC was not configured. The S3 bucket was empty. |
| Azure disk snapshots | Disk-level backups | Not enabled for the database servers. |
| LVM snapshots | Usable copies | They existed, but were made for copying data to staging, not for disaster recovery. One manual snapshot was about six hours old. |
| Replication | A live second copy | The secondary had just been wiped for rebuilding. Replication is not a backup anyway: it copies deletions too. |
| WAL archiving / point-in-time recovery | Not in use | No way to replay to the minute before the deletion. |
The pg_dump failure is the one to remember. The cron job ran on a server without a database data directory, so the packaging defaulted to the older 9.2 tools. Nothing about the setup looked wrong from the outside. The job ran every day. It just produced nothing, and the alert that would have said so went nowhere.
What was lost and how long did recovery take?
GitLab restored from the six-hour-old LVM snapshot made for staging. Because the staging disks were slow, copying the data took around 18 hours. Database records created in roughly a six-hour window were lost; GitLab estimated around 5,000 projects, 5,000 comments and 700 new user accounts. Git repositories and wikis were stored separately and were not affected. Projects created in the lost window were recreated in basic form from the repositories, without their issues and other database data. Database ID sequences were pushed forward by 100,000 so that new records would not reuse old IDs.
GitLab streamed the recovery live and documented progress in a public document. That openness earned it a lot of goodwill, but goodwill is not the plan to rely on.
The root cause was ownership, not the command
GitLab's own "five whys" analysis lands in the right place. The trigger was a load spike and a mistaken command. The reason recovery took so long and lost data was that backups failed silently, the alternative copies were never designed for recovery, and nobody owned or regularly tested the backup procedures. Its list of improvements reflects that: monitored backups, automated restore testing, hourly snapshots, point-in-time recovery, better runbooks, and a named owner for data durability.
Notice what is not on the list as the main fix: "stop engineers running dangerous commands". Humans will make mistakes under pressure late at night. The system should make the mistake recoverable.
How common is this in Indian startups and SMEs?
It is a very common pattern. The typical setup is a single managed or self-hosted database, a nightly dump script someone wrote two years ago, and a vague belief that "the cloud provider takes backups". Typical gaps:
- The dump script fails after a database upgrade and nobody notices.
- Backups are stored in the same account, region or even the same server as the database, so a compromised account or ransomware takes both.
- Managed database snapshots exist but retention is a few days, and nobody knows how long a restore takes.
- Uploaded files (invoices, KYC documents, images) are not in the backup at all.
- Nobody has ever restored a backup into a fresh environment.
There is also a compliance angle. CERT-In's directions of 28 April 2022 require organisations to keep logs of their ICT systems for a rolling 180 days within India, and the Digital Personal Data Protection Act, 2023 expects data fiduciaries to protect personal data with reasonable security safeguards. Losing customer data because backups never worked is a hard position to defend.
A restore-testing routine for a small team
Set the targets first
- RPO (recovery point objective): how much data can you afford to lose? Six hours, one hour, five minutes? This decides whether nightly dumps are enough or you need continuous WAL archiving / point-in-time recovery.
- RTO (recovery time objective): how long can you be down? This decides whether an 18-hour copy is acceptable. For most businesses it is not.
Build the backups
- Use at least two independent methods, for example managed snapshots plus logical dumps or WAL archiving.
- Keep one copy in a separate account or provider, with delete protection or immutability, so an attacker or a bad script cannot remove it.
- Include files and object storage, not only the database. Include configuration and secrets needed to rebuild.
- Match backup tool versions to the database version, and pin them in code.
Monitor them properly
- Alert on absence of success, not only on failure. If no fresh backup of reasonable size arrived in 26 hours, page someone.
- Check the size of each backup against the previous one. A 0-byte or suddenly tiny file is an incident.
- Send alerts to a channel someone reads, and test the alert path itself.
Restore on a schedule
- Weekly, automated: restore the latest backup into a throwaway environment, run a few sanity queries (row counts, latest record timestamp) and record the restore time.
- Quarterly, manual: a full drill. Someone who did not write the scripts follows the runbook to bring the application up from backups alone. Time it against your RTO.
- After every major change (database upgrade, migration, new storage): run the restore test again.
Reduce the chance of the mistake
- Make production terminals visibly different (prompt colour, hostname in the prompt).
- Prefer runbook scripts that check which host they are on before destructive steps.
- Avoid single-person, late-night recovery sessions when a second pair of eyes is available.
If your database is part of a larger migration or modernisation project, build the backup and restore plan before the move, not after.
How Cehpoint can help
Cehpoint's cloud and DevOps team designs backups against your RPO and RTO, sets up off-account copies and point-in-time recovery, adds monitoring that alerts when a backup does not arrive, and automates weekly restore tests with a written runbook your team can follow. If you want an outside check of your current setup first, book a consultation with a senior engineer.