also looking at this
fix(db): name a dump once, so the file written is the file reported
#186
2 files
+37
-2
| @@ -440,11 +440,19 @@ export function buildBackupScript( | ||
| 440 | 440 | destDir: string = DB_BACKUP_DIR, |
| 441 | 441 | database?: DatabaseConfig, |
| 442 | 442 | ): 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` | |
| 444 | 451 | const mkdir = `mkdir -p ${destDir}` |
| 445 | 452 | if (engine === 'postgres') |
| 446 | 453 | return [ |
| 447 | 454 | mkdir, |
| 455 | stamp, | |
| 448 | 456 | `${pgAdminCommand(database, 'pg_dump')} ${name} | gzip > "${file}"`, |
| 449 | 457 | `echo "BACKUP=${file}"`, |
| 450 | 458 | `ls -l "${file}"`, |
| @@ -452,6 +460,7 @@ export function buildBackupScript( | ||
| 452 | 460 | const sock = engine === 'mariadb' ? SOCKETS.mariadb : SOCKETS.mysql |
| 453 | 461 | return [ |
| 454 | 462 | mkdir, |
| 463 | stamp, | |
| 455 | 464 | `mysqldump --socket=${sock} -u root ${name} | gzip > "${file}"`, |
| 456 | 465 | `echo "BACKUP=${file}"`, |
| 457 | 466 | `ls -l "${file}"`, |