Bug #36635 Backup: errors should be warnings
Submitted: 9 May 2008 19:32 Modified: 24 Feb 2010 23:48
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Backup Severity:S3 (Non-critical)
Version:6.0.6-alpha-debug OS:Linux (SUSE 10 | 32-bit)
Assigned to: Anurag Shekhar CPU Architecture:Any

[9 May 2008 19:32] Peter Gulutzan
Description:
Currently backup of a nonexistent database causes ER_BAD_DB_ERROR:
  mysql> backup database no_such_database to '112';
  ERROR 1049 (42000): Unknown database 'no_such_database'

It should be a warning, not an error, for these reasons:
* BACKUP is comparable to utilities like zip and tar, which
generate warnings for missing files rather than errors
* BACKUP is comparable to some MySQL 'maintenance' statements
which generate warnings rather than errors,
* users tend to look at results carefully the first time when
they're making a script but could miss an error in an
unattended backup
* in general MySQL tries to do what it can
and that is a distinguishing product feature.

Therefore change this so that it causes a (new) warning instead.
So if there are multiple databases, then backup continues even
if some databases are not found.

For example, if database a exists, database b does not exist,
and database c exists, then:
BACKUP DATABASE a, b, c TO '1';
causes a warning, but database a and database c are backed up.

* In the mysql.online_backup table there is a relevant column:
backup_state. It will contain 'warning' instead of 'complete'
or 'error'. It would be possible to concatenate all warnings
about 'not found' into this column, but that isn't requested.
The error_num column is not affected because it's not an error.

* In the mysql.online_backup_progress table there is no
relevant column. The 'error_num' and 'notes' columns are
not affected.

* This change applies only for "database not found" errors.
All other error situations continue to cause error returns.
If later there is a need to consider "tablespace not found",
"table not found", etc., we'll worry about that later.

* In later MySQL-6,x versions it will be possible to say
CREATE PROCEDURE p ()
BEGIN
  DECLARE EXIT HANDLER FOR SQLWARNING
  SIGNAL SQLSTATE '55555' SET MESSAGE_TEXT = 'Error!';
  BACKUP DATABASE no_such_database TO '1';
  END
Thus users can themselves change any warnings to errors.

How to repeat:
mysql> backup database no_such_database to '112';
ERROR 1049 (42000): Unknown database 'no_such_database'
[11 May 2008 0:37] MySQL Verification Team
Thank you for the bug report.
[6 Jan 2010 12:24] 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/96114

2928 Anurag Shekhar	2010-01-06
      Bug #36635 Backup: errors should be warnings
      
      Backup was treating non existent database name in backup command as
      error hence stopping the operation even if one or more valid databases
      are specified in the backup command.
      
      Changed the treatment of non existing databases Backup_info::add_dbs,
      from error to warning to allow backup to continue with backup of other 
      valid databases (if any).
     @ mysql-test/suite/backup/r/backup_dbname_lctn1.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_errors.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_errors_compression.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_missing_db.result
        Result file for newly added test cases.
     @ mysql-test/suite/backup/r/backup_security.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/t/backup_dbname_lctn1.test
        Removed the test case which was testing the database name returned
        as part of error message of ER_BAD_DB_ERROR, as the error is now
        changed to ER_BACKUP_NOTHING_TO_BACKUP which doesn't have any 
        database name in message.
     @ mysql-test/suite/backup/t/backup_errors.test
        Changed expected error from ER_BAD_DB_ERROR to 
        ER_BACKUP_NOTHING_TO_BACKUP in case of wrong database name
        in BACKUP command.
     @ mysql-test/suite/backup/t/backup_missing_db.test
        New test cases added to test the behaviour of backup in case of invalid database name.
     @ mysql-test/suite/backup/t/backup_security.test
        Changed expected error from ER_BAD_DB_ERROR to 
        ER_BACKUP_NOTHING_TO_BACKUP in case of wrong database name
        in BACKUP command.
     @ sql/backup/backup_info.cc
        Removed code to check if any unknown database has been
        found and stop the processing of any more database in the
        list.
        
        Changed unknown databse to warning (from error).
[7 Jan 2010 13:47] Ingo Strüwing
With the current wording of the bug report, I deem the patch incomplete. Back to in-progress. Details by email.
[8 Jan 2010 11:14] 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/96366

2928 Anurag Shekhar	2010-01-08
      Bug #36635 Backup: errors should be warnings
      
      Backup was treating non existent database name in backup command as
      error hence stopping the operation even if one or more valid databases
      are specified in the backup command.
      
      Changed the treatment of non existing databases Backup_info::add_dbs,
      from error to warning to allow backup to continue with backup of other 
      valid databases (if any). If none of the databases listed in backup
      command are found valid, an empty backup image will be create (which
      can be restored) and the command will still succeed.
     @ mysql-test/suite/backup/r/backup_dbname_lctn1.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_errors.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_errors_compression.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_errors_debug_1.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_missing_db.result
        Result file for newly added tests.
     @ mysql-test/suite/backup/r/backup_security.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/t/backup_dbname_lctn1.test
        Change test case which was expecting error in case of invalid
        database to expect warning instead.
     @ mysql-test/suite/backup/t/backup_errors.test
        Change test case which was expecting error in case of invalid
        database to expect warning instead.
        Added instruction to remove backup image after the test case
        as the image name will be used by other test cases.
     @ mysql-test/suite/backup/t/backup_errors_debug_1.test
        Removed error injection test for 
        ER_BACKUP_NOTHING_TO_BACKUP as this error will not be
        returned any more.
        Changed test case numbers of subsequent test cases.
     @ mysql-test/suite/backup/t/backup_missing_db.test
        New tests for testing backup behaviour for missing database
        names.
     @ mysql-test/suite/backup/t/backup_security.test
        Removed suppression for "Backup: Nothing to backup" as this
        will never be returned.
        Changed the test case which was expecting error in case of invalid databse name to expect sussess and added 
        instruction to remove empty backup image.
        
        Retrieving the backup path at the begning of the test so it be used both within the test case and at cleanup.
     @ sql/backup/backup_info.cc
        Removed the code that stopped processing as soon as an unknown database has been found.
        Changed unknown databse to warning (from error).
     @ sql/backup/kernel.cc
        Removed code to return ER_BACKUP_NOTHING_TO_BACKUP
        in case of no valid database found to backup.
        If there is no valid database found in the backup 
        command, an empty image will be created.
[11 Jan 2010 14:21] Anurag Shekhar
Backup behaviour after the fix

The fix will change the missing databases in backup command from error
to a warning, which will not stop the backup from generating image.

Case 1: Backup command doesn't have any valid database

An empty backup image will be generated with the warning listing the 
missing databases. This empty backup image can be restored with no
effect on server instance.

Case 2: Backup command has at least one valid database.

Backup will proceed with the valid database and warning will be generated
listing missing databases.
[12 Jan 2010 12:08] Rafal Somla
Good to push after fixing few minor issues (see my review email).
[14 Jan 2010 17:22] Ingo Strüwing
Approved pending changes. Please see email for details.
[22 Jan 2010 9:52] 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/97824

2936 Anurag Shekhar	2010-01-22
      Bug #36635 Backup: errors should be warnings
      
      Backup was treating non existent database name in backup command as
      error hence stopping the operation even if one or more valid databases
      are specified in the backup command.
      
      Changed the treatment of non existing databases Backup_info::add_dbs,
      from error to warning to allow backup to continue with backup of other 
      valid databases (if any). If none of the databases listed in backup
      command are found valid, an empty backup image will be create (which
      can be restored) and the command will still succeed.
     @ mysql-test/suite/backup/r/backup_dbname_lctn1.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_errors.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_errors_compression.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_errors_debug_1.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_missing_db.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_pipe.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/r/backup_security.result
        Updated tests results according to changes in test case.
     @ mysql-test/suite/backup/t/backup_dbname_lctn1.test
        Change test case which was expecting error in case of invalid
        database to expect warning instead.
     @ mysql-test/suite/backup/t/backup_errors.test
        Change test case which was expecting error in case of invalid
        database to expect warning instead.
        Added instruction to remove backup image after the test case
        as the image name will be used by other test cases.
     @ mysql-test/suite/backup/t/backup_errors_debug_1.test
        Removed error injection test for 
        ER_BACKUP_NOTHING_TO_BACKUP as this error will not be
        returned any more.
     @ mysql-test/suite/backup/t/backup_missing_db.test
        New tests for testing backup behaviour for missing database
        names.
     @ mysql-test/suite/backup/t/backup_pipe.test
        Change test case which was expecting error in case of invalid
        database to expect warning instead.
     @ mysql-test/suite/backup/t/backup_security.test
        Removed suppression for "Backup: Nothing to backup" as this
        will never be returned.
        Changed the test case which was expecting error in case of invalid database
        name to expect success and added instruction to remove empty backup image.
                
        Retrieving the backup path at the beginning of the test so it be used both
        within the test case and at cleanup.
     @ sql/backup/backup_info.cc
        Removed the code that stopped processing as soon as an unknown 
        database has been found.
        Changed unknown database to warning (from error).
     @ sql/backup/kernel.cc
        Removed code to return ER_BACKUP_NOTHING_TO_BACKUP
        in case of no valid database found to backup.
        If there is no valid database found in the backup 
        command, an empty image will be created.
[26 Jan 2010 21:32] 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/98251

3073 Chuck Bell	2010-01-26
      BUG#36635 Backup: errors should be warnings
        
      Backup was treating non existent database name in backup command as
      error hence stopping the operation even if one or more valid databases
      are specified in the backup command.
      
      Changed the treatment of non existing databases Backup_info::add_dbs,
      from error to warning to allow backup to continue with backup of other 
      valid databases (if any). If none of the databases listed in backup
      command are found valid, an empty backup image will be create (which
      can be restored) and the command will still succeed.
      
      Original changeset: 2936 (mysql-6.0-backup)
[16 Feb 2010 7: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/100458

3829 Thava Alagu	2010-02-16
      Bug#36635 regression fix for backup.backup_dbname_lctn2 test failure
      
      Update the result file.
[16 Feb 2010 7:40] 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/100460

3830 Thava Alagu	2010-02-16 [merge]
      Merge regression fix for Bug#36635 backup_dbname_lctn2 test failure
[20 Feb 2010 9:19] Bugs System
Pushed into 6.0.14-alpha (revid:ingo.struewing@sun.com-20100218152520-s4v1ld76bif06eqn) (version source revid:thavamuni.alagu@sun.com-20100216074005-26gapt7vgyqp1oji) (merge vers: 6.0.14-alpha) (pib:16)
[24 Feb 2010 23:48] Paul DuBois
Noted in 6.0.14 changelog.

BACKUP DATABASE new treats a nonexistent database as a nonfatal 
condition and issues a warning rather than an error.