September 28, 2026 路 #12
The green build that dropped rows
This backup job exits 0 even when the database dump fails. Which line explains that?
#!/usr/bin/env bash
set -e
pg_dump "$DATABASE_URL" | gzip > /backups/db.sql.gz
aws s3 cp /backups/db.sql.gz "s3://acme-backups/db.sql.gz"
echo "backup complete"Next puzzle in UTC
One try. The first answer sticks.
How to fix it
Without set -o pipefail, the exit status of a pipeline is the status of the last command. gzip succeeds, so the script uploads an empty or partial archive.
set -e stops the script when a simple command fails. A pipeline is not a simple command. The exit status is the status of gzip, which is happy to compress whatever arrived, including nothing. The next line uploads that file and the log says the backup completed.
set -o pipefail makes the pipeline fail if any stage fails. set -u catches an empty DATABASE_URL before pg_dump runs. Together they are the default you want at the top of every deploy script.
Fix
#!/usr/bin/env bash
set -euo pipefail
pg_dump "$DATABASE_URL" | gzip > /backups/db.sql.gz
Check the archive before you copy it. A one-line gzip -t after the dump, and a failure alert when the object size drops, catches the day pipefail is missing from a different script.