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
packages/ts-cloud/src/deploy/dashboard-database.tsmodified+10-1
Changes to packages/ts-cloud/src/deploy/dashboard-database.ts
@@ -440,11 +440,19 @@ export function buildBackupScript(
440440 destDir: string = DB_BACKUP_DIR,
441441 database?: DatabaseConfig,
442442): string[] {
443 const file = `${destDir}/${name}-$(date +%Y%m%d-%H%M%S).sql.gz`
443 // The timestamp is taken ONCE into a variable rather than embedded as a
444 // command substitution. Written inline, `$(date …)` runs again in every
445 // command that mentions the filename — so a dump that happens to cross a
446 // second boundary writes one file and then reports, and lists, a different
447 // one that does not exist. The backup succeeds and names a path nobody can
448 // find, which is the worst way for a backup to fail.
449 const stamp = 'TS_CLOUD_BACKUP_STAMP="$(date +%Y%m%d-%H%M%S)"'
450 const file = `${destDir}/${name}-$TS_CLOUD_BACKUP_STAMP.sql.gz`
444451 const mkdir = `mkdir -p ${destDir}`
445452 if (engine === 'postgres')
446453 return [
447454 mkdir,
455 stamp,
448456 `${pgAdminCommand(database, 'pg_dump')} ${name} | gzip > "${file}"`,
449457 `echo "BACKUP=${file}"`,
450458 `ls -l "${file}"`,
@@ -452,6 +460,7 @@ export function buildBackupScript(
452460 const sock = engine === 'mariadb' ? SOCKETS.mariadb : SOCKETS.mysql
453461 return [
454462 mkdir,
463 stamp,
455464 `mysqldump --socket=${sock} -u root ${name} | gzip > "${file}"`,
456465 `echo "BACKUP=${file}"`,
457466 `ls -l "${file}"`,