Bug #34909 mysqldump returns a 0 status on error when using --master-data
Submitted: 27 Feb 2008 21:41 Modified: 3 Apr 2008 15:07
Reporter: Tim Soderstrom Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: mysqldump Command-line Client Severity:S3 (Non-critical)
Version:5.0.51, 5.0, 5.1 BK OS:Linux (RHEL4)
Assigned to: Georgi Kodinov CPU Architecture:Any
Tags: mysqldump binary log master-data
Triage: D2 (Serious)

[27 Feb 2008 21:41] Tim Soderstrom
Description:
The 'mysqldump' command is returning a status of 0 when it should return a status of 1:

rackdawg bin # mysqldump --master-data=2 test > test.sql
mysqldump: Error: Binlogging on server not active
rackdawg bin # echo $?
0

This happens when, as the error indicates, the binary log is not enabled but the --master-data option is being used. This error causes the backup to fail to complete, only writing header information to the resulting dump:

rackdawg bin # cat test.sql 
-- MySQL dump 10.11
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version       5.0.54

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2008-02-27 21:35:15

How to repeat:
* Disable binary logging in MySQL (remove 'log-bin' option in my.cnf)
* Attempt to run a 'mysqldump' using the --master-data option
* Check the return code of 'mysqldump' by running "echo $?" immediately after the dump
* Check the backup file to see if any table-data exists

Suggested fix:
Since 'mysqldump' outputs to STDERR a message suggesting that there was, indeed, and error, it should also return a value other than 0. Otherwise, any wrapper scripts which check for whether or not the command failed will not catch this error and assume the backup did complete when, in reality, it did not.

As to what specific value to return, I recommend having it return 1, although I am sure this could be subject to debate. For a concrete example, it should work like this:

ckdawg bin # mysqldump --master-data=2 test > test.sql
mysqldump: Error: Binlogging on server not active
rackdawg bin # echo $?
1
rackdawg bin #
[27 Feb 2008 22:49] Sveta Smirnova
Thank you for the report.

Verified as described.
[29 Feb 2008 16:03] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/43227

ChangeSet@1.2596, 2008-02-29 18:00:34+02:00, gkodinov@magare.gmz +4 -0
  Bug #34909: mysqldump returns a 0 status on error when using 
    --master-data
  
  No error code was returned by mysqldump if it detects that binary
  logging is not enabled on the server.
  Fixed by returning error code.
[6 Mar 2008 19:41] Sergey Petrunya
Feedback provided via email. 

Setting to Patch Approved assuming Joro will agree with the requested changes. Joro if you don't agree please change back to patch pending.
[7 Mar 2008 9:16] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/43564

ChangeSet@1.2596, 2008-03-07 11:15:49+02:00, gkodinov@magare.gmz +4 -0
  Bug #34909: mysqldump returns a 0 status on error when using 
    --master-data
  
  No error code was returned by mysqldump if it detects that binary
  logging is not enabled on the server.
  Fixed by returning error code.
[13 Mar 2008 19:29] Bugs System
Pushed into 6.0.5-alpha
[13 Mar 2008 19:36] Bugs System
Pushed into 5.1.24-rc
[13 Mar 2008 19:43] Bugs System
Pushed into 5.0.60
[3 Apr 2008 15:07] Jon Stephens
Documented in the 5.0.60, 5.1.23-ndb-6.3.11, 5.1.24, and 6.0.5 changelogs as follows:

        mysqldump failed to return an error code when using 
        --master-data but binary logging was not enabled on the server.