[Bug 44190] New: koha-dump reports success and leaves an empty database dump when mysqldump fails
&2\nexit 2\n' > /tmp/fakebin/mysqldump chmod +x /tmp/fakebin/mysqldump (or set a wrong <pass> in koha-conf.xml)
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44190 Bug ID: 44190 Summary: koha-dump reports success and leaves an empty database dump when mysqldump fails Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: major Priority: P5 - low Component: Command-line Utilities Assignee: koha-bugs@lists.koha-community.org Reporter: babarjunaid1122@gmail.com QA Contact: testopia@bugs.koha-community.org CC: jake.deery@openfifth.co.uk, robin@catalyst.net.nz Target Milestone: --- debian/scripts/koha-dump pipes mysqldump into gzip: mysqldump $dbflag --host=... --user=... --password=... "$mysqldb" | gzip > "$dbdump" The script runs under set -e, but without pipefail the exit status of a pipeline is gzip's. When mysqldump fails (wrong password in koha-conf.xml, missing privilege, server down, disk full), gzip still succeeds, so koha-dump carries on, writes the configs tarball, prints "Done." and exits 0. The .sql.gz it leaves is about 20 bytes: an empty gzip stream. koha-run-backups and any cron or monitoring that checks the exit status therefore report a good backup every night while no database is being saved. Nobody finds out until a restore is needed. To reproduce (koha-testing-docker, main): 1. Make mysqldump fail. For example put a stand-in first on the PATH: mkdir /tmp/fakebin printf '#!/bin/sh\necho "mysqldump: Got error: 1045: Access denied" 2. PATH=/tmp/fakebin:$PATH koha-dump kohadev ; echo "exit=$?" 3. Output: the mysqldump error, then "* configs, logs to ...", "Done." and exit=0. 4. ls -l /var/spool/koha/kohadev/: the .sql.gz is 20 bytes. Expected: koha-dump stops with a non-zero exit status and says the database dump failed (and does not leave an empty .sql.gz that looks like a backup). The same applies to --schema-only (mysqldump | sed). Reproduced on main (6ff8078) and on Koha 26.05.02. Related but different: bug 41353 (the PROCESS privilege error itself). -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44190 --- Comment #1 from babar junaid <babarjunaid1122@gmail.com> --- Created attachment 212182 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212182&action=edit Bug 44190: Stop koha-dump when mysqldump fails Bug 44190: Stop koha-dump when mysqldump fails koha-dump piped mysqldump into gzip (or sed for --schema-only). The exit status of a pipeline is the last command's, so set -e never saw a failed mysqldump: the script went on, printed "Done.", exited 0 and left an empty .sql.gz that looked like a backup. The script is /bin/sh, so instead of pipefail mysqldump writes its exit status to a temporary file; when it failed, koha-dump removes the empty dump, prints an error and exits 1. Test plan: 1. Make mysqldump fail, e.g. put a stand-in first on the PATH: mkdir /tmp/fakebin printf '#!/bin/sh\necho "mysqldump: Got error: 1045" >&2\nexit 2\n' > /tmp/fakebin/mysqldump chmod +x /tmp/fakebin/mysqldump 2. PATH=/tmp/fakebin:$PATH sh debian/scripts/koha-dump kohadev ; echo $? Without the patch: "Done.", 0, and a 20 byte .sql.gz in /var/spool/koha/kohadev. With the patch: "Error: mysqldump failed (exit status 2); no database dump was written.", 1, no .sql.gz. 3. Same with --schema-only: error and 1, no schema file. 4. sh debian/scripts/koha-dump kohadev (real mysqldump): "Done.", 0, and zcat of the .sql.gz ends with "-- Dump completed". Sponsored-by: Koha Solutions -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44190 babar junaid <babarjunaid1122@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Assignee|koha-bugs@lists.koha-commun |babarjunaid1122@gmail.com |ity.org | -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org