ReviewOS

also looking at this

stacks/ts-cloud

fix(db): name a dump once, so the file written is the file reported

#186
Merged glennmichael123 wants to merge fix/backup-dump-timestamp into main
2 files +37 -2

A real bug, found by the end-to-end test from #184. It's currently making main's CI red.

What's wrong

buildBackupScript embedded the timestamp as a command substitution inside the filename:

/var/backups/ts-cloud/databases/<name>-$(date +%Y%m%d-%H%M%S).sql.gz

The commands run in one shell, so that substitution is evaluated again in every command that mentions the path — once for the redirect that creates the dump, again for echo "BACKUP=…", again for the ls. A dump that crosses a second boundary writes one file and then reports, and lists, a different one:

BACKUP=/tmp/bughq-20260824-163357.sql.gz
ls: cannot access '/tmp/bughq-20260824-163357.sql.gz': No such file or directory

Why it matters

The failure mode is the bad kind. The dump itself is fine and sitting on disk; db:backup just reports the wrong path for it. Anything parsing BACKUP= gets a filename that isn't there, the closing ls fails against a backup that actually succeeded, and site:move — which locates the dump it's about to carry — can't find it.

The fix

Take the timestamp once into a variable. Same shell, so it holds across the commands, and postgres/mysql/mariadb all route through it.

How it surfaced

The Docker end-to-end test added in #184 runs on CI hardware slower than a laptop, so it actually crossed the second boundary. Every local run of that same test passed. That's the harness doing exactly what it was built for — this is a latent bug that predates all of this work and would otherwise have shown up as a mystifying "backup succeeded but the file isn't there" in production.

The unit regression test asserts the property, not the symptom: exactly one $(date in the script, and the write, the report and the listing all naming the same thing, checked across all three engines.

Verification

31 unit tests in dashboard-database.test.ts and the 7 database e2e cases both green locally.

Note this also unblocks #185 (and therefore #181) — their test job is failing on this, not on anything in those changes.

2 changed files on the files tab, with 0 review threads.