#At file:///localhome/jl208045/mysql/mysql-6.0-backup-34579/
2727 Jorgen Loland 2008-11-05
Bug#34579 - Backup: Restore overwrites the new / modified data without warning
Preliminary patch - should not be seen in any branch
modified:
sql/backup/backup_kernel.h
sql/backup/kernel.cc
sql/share/errmsg.txt
sql/sql_lex.h
sql/sql_yacc.yy
=== modified file 'sql/backup/backup_kernel.h'
--- a/sql/backup/backup_kernel.h 2008-10-30 17:53:24 +0000
+++ b/sql/backup/backup_kernel.h 2008-11-05 14:25:46 +0000
@@ -74,7 +74,7 @@ class Backup_restore_ctx: public backup:
const char*);
int do_backup();
- int do_restore();
+ int do_restore(bool restore_force);
int fatal_error(int, ...);
int log_error(int, ...);
=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc 2008-10-30 20:02:15 +0000
+++ b/sql/backup/kernel.cc 2008-11-05 14:25:46 +0000
@@ -226,7 +226,7 @@ execute_backup_command(THD *thd, LEX *le
DEBUG_SYNC(thd, "after_backup_start_restore");
- res= context.do_restore();
+ res= context.do_restore(lex->restore_force);
DEBUG_SYNC(thd, "restore_before_end");
@@ -1203,7 +1203,7 @@ int Backup_restore_ctx::restore_triggers
@todo Remove the @c reset_diagnostic_area() hack.
*/
-int Backup_restore_ctx::do_restore()
+int Backup_restore_ctx::do_restore(bool restore_force)
{
DBUG_ENTER("do_restore");
@@ -1225,6 +1225,23 @@ int Backup_restore_ctx::do_restore()
disable_fkey_constraints(); // Never errors
+ // unless RESTORE... FORCE: return error if database to restore exists
+ if (!restore_force) {
+ Image_info::Db_iterator *dbit= info.get_dbs();
+
+ if (!dbit) {
+ DBUG_RETURN(fatal_error(ER_OUT_OF_RESOURCES));
+ }
+
+ Image_info::Db *mydb;
+ while (mydb= static_cast<Image_info::Db*>((*dbit)++)) {
+ if (!obs::check_db_existence(&mydb->name())) {
+ DBUG_RETURN(fatal_error(ER_RESTORE_DB_EXISTS, mydb->name().ptr()));
+ }
+ }
+ delete dbit;
+ }
+
if (read_meta_data(info, s))
{
m_thd->main_da.reset_diagnostics_area(); // Never errors
=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt 2008-10-30 17:53:24 +0000
+++ b/sql/share/errmsg.txt 2008-11-05 14:25:46 +0000
@@ -6418,3 +6418,5 @@ ER_RESTORE_ON_MASTER
eng "A restore operation was initiated on the master."
ER_RESTORE_ON_SLAVE
eng "A restore operation was attempted on a slave during replication. You must stop the slave prior to running a restore."
+ER_RESTORE_DB_EXISTS
+ eng "Database \'%-.64s\' already exists and can therefore not be restored without using FORCE flag."
=== modified file 'sql/sql_lex.h'
--- a/sql/sql_lex.h 2008-10-28 14:17:05 +0000
+++ b/sql/sql_lex.h 2008-11-05 14:25:46 +0000
@@ -1528,6 +1528,7 @@ struct LEX: public Query_tables_list
char *help_arg;
LEX_STRING backup_dir; /* For RESTORE/BACKUP */
bool backup_compression;
+ bool restore_force;
char* to_log; /* For PURGE MASTER LOGS TO */
ulonglong backup_id; /* For PURGE BACKUP LOGS */
char* x509_subject,*x509_issuer,*ssl_cipher;
=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy 2008-10-28 14:17:05 +0000
+++ b/sql/sql_yacc.yy 2008-11-05 14:25:46 +0000
@@ -6424,6 +6424,7 @@ restore:
RESTORE_SYM
FROM
TEXT_STRING_sys
+ opt_restore_force
{
LEX *lex= Lex;
if (lex->sphead)
@@ -6437,6 +6438,14 @@ restore:
}
;
+opt_restore_force:
+ /* empty */ { Lex->restore_force= false; }
+ | FORCE_SYM
+ {
+ Lex->restore_force= true;
+ }
+ ;
+
backup:
BACKUP_SYM
DATABASE
| Thread |
|---|
| • bzr commit into mysql-6.0-backup branch (jorgen.loland:2727) Bug#34579 | Jorgen Loland | 5 Nov |