Incident report · 2024
When an update silently purged our chat history (and nobody noticed for weeks)
A blameless post-mortem: Rocket.Chat on Kubernetes, MongoDB outside the cluster, and a restoration with two dumps.
- Kubernetes
- FluxCD
- MongoDB
- Blameless
- Summer 2024
this happened in summer 2024, in the IT department of a large French university (tens of thousands of users). Everything below is sanitized: hostnames, paths and identifiers are generic.
TL;DR
- A Rocket.Chat update silently overwrote the message retention policy (configured at 6 months) with a value of 1 month, which put about five months of history at risk.
- The purge started around June 24-25, during a period when the university was nearly empty. It went unnoticed until around August 20, when users came back and opened many “missing messages” tickets.
- Two independent safety nets (a dump taken before every update, and a monthly dump that is kept) allowed a full restoration, performed live on production with no service interruption, except for about 2 days of messages covered by neither.
- The root cause was not a person: the qualification environment could not reveal this behavior, and detection depended on human usage.
Architecture
- Rocket.Chat runs on Kubernetes. Its manifests live in a GitLab repository, and FluxCD reconciles the cluster against it (GitOps).
- MongoDB (replica set) is hosted outside the cluster. It holds messages and the metadata of uploaded files.
- Uploaded files themselves live on a PersistentVolumeClaim backed by an NFS storage server, which is copied to a separate NFS backup server.
- Backups: automatic MongoDB dumps with an 8-day retention (local and S3), plus manual dumps: one before every update, and one monthly (last Friday of the month), both kept.
The key point: messages and attachments live in two different places (MongoDB and NFS), so restoring one without the other leaves broken messages.
Timeline
| When | What happened |
|---|---|
| Before June 25 | Pre-update dump taken (standard practice), then the update. Retention silently becomes 1 month. |
| ~June 24-25 | The purge of messages older than one month begins. |
| ~July 25 - ~August 20 | Summer closure: almost nobody connects, so nobody sees messages disappearing. |
| July 26 | Monthly dump (last Friday of July). It only contains about one month of messages, because of the purge. |
| ~August 20 | Users return, many “missing messages” tickets arrive. |
| Right after | Diagnosis, then restoration. |
Detection and diagnosis
The tickets all said the same thing: old messages were gone. Looking at the data, every message older than one month was missing, a suspiciously round number. The retention settings of Rocket.Chat showed the cause: the configured value had been overwritten and set to 1 month during the update.
Why staging did not catch it
The update had been qualified in staging, but this behavior was invisible there: the test dataset was deliberately truncated to less than 2 months to keep its size manageable. A retention behavior can only be observed on data older than the retention window, so the test could not have revealed it. In addition, the retention setting itself was not compared before and after the update.
Restoration
Two dumps, two restorations, in this order:
- The July 26 monthly dump, for the most recent messages (up to the start of what production still held).
- The pre-update dump, for the older messages (before about June 25).
For each dump the procedure was the same (commands in the appendix):
- Restore the
rocketchat_messagecollection into a test database withmongorestore, never directly into production. - Filter by
_updatedAtwith an aggregation and write the result into a new collection. - Export it as JSON, then import it into the production collection with
mongoimport --mode=upsert, so that anything production had kept is not duplicated. The import ran against the live database, without any service interruption, after extensive testing on the test database.
Then the attachments:
- Query the uploads collection over the same period and export the list of file IDs.
- On the NFS backup server, a script copies every file whose name matches a listed ID into an archive and reports missing files.
- Extract the archive on the NFS storage server, in the PVC directory.
- Import the uploads metadata into production, again with
upsert.
Note: the retention purge only deleted message documents from MongoDB. The uploaded files themselves stayed on the storage server, so the older period (before June 25) did not require recovering files or their metadata. The files of the window restored from the July dump (June 25 – July 24) were, however, recovered from the backup server along with their uploads metadata, as a precaution, to start again from a clean state.
What was lost
About 2 days of messages: those between the date of the pre-update dump and the start of what the July 26 dump covered (purged in between, and present in neither).
Limits of the method
- Filtering on
_updatedAtis approximate. Editing a message changes this date, so a message can fall on the wrong side of the cutoff. upsertreplaces by_id. Because the older dump was restored second, any document present in both ranges would end up in its older version. In practice the ranges were meant to be disjoint, but it is a property worth knowing.- Attachments are matched by file name only. A file absent from the backup is reported in the log but not recovered.
- The restoration was manual and run as root on production servers. It worked, but it deserves a rehearsal, not an improvisation.
What I would do differently
- A test dataset must cover the longest time window being tested. Truncating for size is reasonable, but then retention behavior is untestable, and that limit should be explicit.
- Qualify an update by comparing settings before and after, not only by checking that the application works.
- Alert on a metric, not on users. A simple “number of messages in the database” alert would have fired within days, summer closure or not.
- Backup retention must exceed detection time. An 8-day retention does not protect against a problem found after 4 weeks. The kept dumps (pre-update and monthly) are what saved us.
- Keep taking a dump before every update. It is cheap, it was decisive here, and it is the reason the loss stayed at about 2 days.
Appendix: commands (sanitized)
Messages
# On the MongoDB primary, in the dumps directory
# Restore only the messages collection from the dump into a test database
mongorestore --db=test <dump-dir>/rocketchat/rocketchat_message.bson -v
# Filter by date into a new collection
mongosh
> use test
> db.rocketchat_message.aggregate([
{ $match: { "_updatedAt": { $lt: new Date('2024-07-24') } } },
{ $out: "msgbefore24" }
])
# Export, then import into production (upsert)
mongoexport --jsonFormat=canonical --db=test --collection=msgbefore24 --out=msgbefore24.json
mongoimport --db=<prod-db> --collection=rocketchat_message --file=msgbefore24.json --mode=upsertAttachments
# 1. Uploads over the same period, then the list of file IDs
mongosh
> use test
> db.rocketchat_uploads.aggregate([
{ $match: { "_updatedAt": { $lt: new Date('2024-07-24'), $gt: new Date('2024-06-25') } } },
{ $out: "uploadsbefore24" }
])
mongoexport --jsonFormat=canonical --db=test --collection=uploadsbefore24 --out=uploadsbefore24.json
jq -r ._id uploadsbefore24.json > uploads_id# 2. On the NFS backup server: copy the matching files into an archive
#!/bin/bash
list="/root/uploads_id"
source="<backup-path>/<pvc-directory>"
archive="/root/uploads"
mkdir -p "$archive"
while read -r id; do
if [[ -f "$source/$id" ]]; then
cp "$source/$id" "$archive/"
echo "$(date +%T) - Added: $id"
else
echo "Missing file: $id"
fi
done < "$list"
tar -cf /root/uploads.tar -C "$archive" .# 3. Copy the archive to the NFS storage server and extract it in the PVC directory
scp uploads.tar root@<nfs-storage>:/<data-path>/
cd /<data-path>/<pvc-directory>/ && tar -xvf ../uploads.tar
# 4. Import the uploads metadata into production
mongoimport --db=<prod-db> --collection=rocketchat_uploads --file=uploadsbefore24.json --mode=upsertThe attachments script above is a cleaned-up version of the one used at the time (loop reading the list line by line, explicit archive contents instead of a filename glob).