List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:November 17 2008 3:01pm
Subject:bzr push into mysql-6.0-backup branch (jorgen.loland:2735)
View as plain text  
 2735 Jorgen Loland	2008-11-17 [merge]
      Merge with mysql-6.0-backup for push
modified:
  mysql-test/lib/mtr_report.pl
  mysql-test/suite/backup/r/backup_logs_output.result
  mysql-test/suite/backup/t/backup_logs_output-master.opt
  sql/mysqld.cc

=== modified file 'mysql-test/suite/backup/r/backup.result'
--- a/mysql-test/suite/backup/r/backup.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup.result	2008-11-17 09:57:51 +0000
@@ -562,7 +562,7 @@ id	ccode
 2	bb
 4	dd
 do restore
-RESTORE FROM 'bup_delete.bak';
+RESTORE FROM 'bup_delete.bak' OVERWRITE;
 backup_id
 #
 show the data
@@ -597,7 +597,7 @@ BACKUP DATABASE bup_default TO 'bup_defa
 backup_id
 #
 Restore the database.
-RESTORE FROM 'bup_default_timestamp.bak';
+RESTORE FROM 'bup_default_timestamp.bak' OVERWRITE;
 backup_id
 #
 Show data after restore (timestamp should be same as above).

=== modified file 'mysql-test/suite/backup/r/backup_backupdir.result'
--- a/mysql-test/suite/backup/r/backup_backupdir.result	2008-10-24 15:37:11 +0000
+++ b/mysql-test/suite/backup/r/backup_backupdir.result	2008-11-17 09:57:51 +0000
@@ -15,7 +15,7 @@ backup_id
 Ensure backup image file went to the correct location
 /backup/bup_backupdir.bak
 Perform restore
-RESTORE FROM 'bup_backupdir1.bak';
+RESTORE FROM 'bup_backupdir1.bak' OVERWRITE;
 backup_id
 #
 Now do the backup and restore by specifying a path.
@@ -25,7 +25,7 @@ backup_id
 #
 Ensure backup image file went to the correct location
 Perform restore
-RESTORE FROM '../bup_backupdir2.bak';
+RESTORE FROM '../bup_backupdir2.bak' OVERWRITE;
 backup_id
 #
 Perform backup

=== modified file 'mysql-test/suite/backup/r/backup_commit_backup.result'
--- a/mysql-test/suite/backup/r/backup_commit_backup.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_commit_backup.result	2008-11-17 09:57:51 +0000
@@ -299,7 +299,7 @@ SELECT release_lock("sync");
 release_lock("sync")
 1
 Checking contents of the backup image
-RESTORE FROM 'db1.bak';
+RESTORE FROM 'db1.bak' OVERWRITE;
 backup_id
 #
 SELECT * FROM db1.t1;

=== modified file 'mysql-test/suite/backup/r/backup_commit_blocker.result'
--- a/mysql-test/suite/backup/r/backup_commit_blocker.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_commit_blocker.result	2008-11-17 09:57:51 +0000
@@ -129,7 +129,7 @@ DROP TABLE bup_commit_blocker.t1;
 DROP TABLE bup_commit_blocker.t2;
 DROP TABLE bup_commit_blocker.t3;
 con1: Restoring the database
-RESTORE FROM "bup_commit_blocker.bak";
+RESTORE FROM "bup_commit_blocker.bak" OVERWRITE;
 backup_id
 #
 con1: Showing the data (no new data should be here).
@@ -229,7 +229,7 @@ col_a
 con1: Dropping the database
 DROP TABLE bup_commit_blocker.t5;
 con1: Restoring the database
-RESTORE FROM "bup_commit_blocker.bak";
+RESTORE FROM "bup_commit_blocker.bak" OVERWRITE;
 backup_id
 #
 con1: Showing the data (no new data should be here).
@@ -411,7 +411,7 @@ DROP TABLE bup_commit_blocker.t2;
 DROP TABLE bup_commit_blocker.t3;
 DROP TABLE bup_commit_blocker.t5;
 con1: Restoring the database
-RESTORE FROM "bup_commit_blocker.bak";
+RESTORE FROM "bup_commit_blocker.bak" OVERWRITE;
 backup_id
 #
 con1: Showing the data (no new data should be here).

=== modified file 'mysql-test/suite/backup/r/backup_commit_restore.result'
--- a/mysql-test/suite/backup/r/backup_commit_restore.result	2008-10-23 08:13:54 +0000
+++ b/mysql-test/suite/backup/r/backup_commit_restore.result	2008-11-17 09:57:51 +0000
@@ -6,7 +6,7 @@ INSERT INTO t1 VALUES ('a1');
 BACKUP DATABASE commit_test TO '81';
 backup_id
 #
-RESTORE FROM '81';
+RESTORE FROM '81' OVERWRITE;
 backup_id
 #
 SELECT * FROM t1;
@@ -24,7 +24,7 @@ INSERT INTO t2 VALUES ('a2');
 BACKUP DATABASE commit_test TO '82';
 backup_id
 #
-RESTORE FROM '82';
+RESTORE FROM '82' OVERWRITE;
 backup_id
 #
 SELECT * FROM t1;
@@ -51,7 +51,7 @@ INSERT INTO t3 VALUES ('a3');
 BACKUP DATABASE commit_test TO '83';
 backup_id
 #
-RESTORE FROM '83';
+RESTORE FROM '83' OVERWRITE;
 backup_id
 #
 SELECT * FROM t1;
@@ -89,7 +89,7 @@ INSERT INTO t4 VALUES ('a4');
 BACKUP DATABASE commit_test TO '84';
 backup_id
 #
-RESTORE FROM '84';
+RESTORE FROM '84' OVERWRITE;
 backup_id
 #
 SELECT * FROM t1;
@@ -138,7 +138,7 @@ INSERT INTO t4 VALUES ('a5');
 BACKUP DATABASE commit_test TO '85';
 backup_id
 #
-RESTORE FROM '85';
+RESTORE FROM '85' OVERWRITE;
 backup_id
 #
 SELECT * FROM t1;
@@ -198,7 +198,7 @@ BACKUP DATABASE commit_test TO '86';
 backup_id
 #
 SET @@autocommit=0;
-RESTORE FROM '86';
+RESTORE FROM '86' OVERWRITE;
 backup_id
 #
 DROP TABLE t5;
@@ -265,7 +265,7 @@ BACKUP DATABASE commit_test TO '87';
 backup_id
 #
 SET @@autocommit=1;
-RESTORE FROM '87';
+RESTORE FROM '87' OVERWRITE;
 backup_id
 #
 SELECT * FROM t1;

=== modified file 'mysql-test/suite/backup/r/backup_compression.result'
--- a/mysql-test/suite/backup/r/backup_compression.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_compression.result	2008-11-17 09:57:51 +0000
@@ -7,13 +7,13 @@ CREATE TABLE db1.t2(a INT);
 BACKUP DATABASE db1 TO 'db2.bak.gz' WITH COMPRESSION COMPRESSION_ALGORITHM=gzip;
 backup_id
 #
-RESTORE FROM 'db1.bak.gz';
+RESTORE FROM 'db1.bak.gz' OVERWRITE;
 backup_id
 #
 SHOW TABLES FROM db1;
 Tables_in_db1
 t1
-RESTORE FROM 'db2.bak.gz';
+RESTORE FROM 'db2.bak.gz' OVERWRITE;
 backup_id
 #
 SHOW TABLES FROM db1;

=== modified file 'mysql-test/suite/backup/r/backup_concurrent.result'
--- a/mysql-test/suite/backup/r/backup_concurrent.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_concurrent.result	2008-11-17 09:57:51 +0000
@@ -49,7 +49,7 @@ Testing starting backup/restore restore 
 ---------------------------------------------------
 Starting restore
 SET DEBUG_SYNC= 'after_backup_start_restore SIGNAL running WAIT_FOR restore';
-RESTORE FROM 'backup1';
+RESTORE FROM 'backup1' OVERWRITE;
 Waiting for restore to get going
 SET DEBUG_SYNC= 'now WAIT_FOR running';
 Starting backup in another connection.  

=== modified file 'mysql-test/suite/backup/r/backup_db_grants.result'
--- a/mysql-test/suite/backup/r/backup_db_grants.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_db_grants.result	2008-11-17 09:57:51 +0000
@@ -64,7 +64,7 @@ SHOW GRANTS FOR 'bup_user3'@'%';
 Grants for bup_user3@%
 GRANT USAGE ON *.* TO 'bup_user3'@'%'
 Run Restore
-RESTORE FROM 'bup_db_grants.bak';
+RESTORE FROM 'bup_db_grants.bak' OVERWRITE;
 backup_id
 #
 SHOW TABLES FROM bup_db_grants;
@@ -96,7 +96,7 @@ FLUSH PRIVILEGES;
 CREATE USER 'bup_user1'@'%';
 CREATE USER 'bup_user1'@'nosuchhost';
 Run Restore
-RESTORE FROM 'bup_db_grants.bak';
+RESTORE FROM 'bup_db_grants.bak' OVERWRITE;
 backup_id
 #
 SHOW TABLES FROM bup_db_grants;
@@ -166,7 +166,7 @@ EXECUTE stmt3;
 Grants for �@@%
 GRANT USAGE ON *.* TO '�@'@'%'
 Run restore.
-RESTORE FROM 'bup_db_grants.bak';
+RESTORE FROM 'bup_db_grants.bak' OVERWRITE;
 backup_id
 #
 FLUSH PRIVILEGES;

=== modified file 'mysql-test/suite/backup/r/backup_errors.result'
--- a/mysql-test/suite/backup/r/backup_errors.result	2008-11-05 09:41:15 +0000
+++ b/mysql-test/suite/backup/r/backup_errors.result	2008-11-17 09:57:51 +0000
@@ -135,3 +135,50 @@ SET DEBUG_SYNC= 'reset';
 DROP DATABASE db1;
 
 Done testing for Bug#38624
+
+Testing RESTORE ... OVERWRITE functionality
+See bug#34579
+
+Initialize
+CREATE DATABASE db1;
+USE db1;
+CREATE TABLE table1 (text VARCHAR(20));
+INSERT INTO table1 VALUES ('Inserted before');
+
+Backup database
+BACKUP DATABASE db1 TO 'overwrite.bak';
+backup_id
+#
+
+Insert more data and display
+INSERT INTO table1 VALUES ('Inserted after');
+SELECT * FROM table1;
+text
+Inserted before
+Inserted after
+
+Restore without OVERWRITE flag; will fail
+RESTORE FROM 'overwrite.bak';
+ERROR HY000: Database 'db1' already exists. Use OVERWRITE flag to overwrite.
+
+Restore with OVERWRITE flag; will succeed
+RESTORE FROM 'overwrite.bak' OVERWRITE;
+backup_id
+#
+
+Show that inserted value 2 is not there
+SELECT * FROM table1;
+text
+Inserted before
+DROP DATABASE db1;
+
+Restore after deleting db; will succeed
+RESTORE FROM 'overwrite.bak';
+backup_id
+#
+
+Show that inserted value 2 is not there
+SELECT * FROM table1;
+text
+Inserted before
+DROP DATABASE db1;

=== modified file 'mysql-test/suite/backup/r/backup_fkey.result'
--- a/mysql-test/suite/backup/r/backup_fkey.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_fkey.result	2008-11-17 09:57:51 +0000
@@ -43,10 +43,10 @@ SHOW VARIABLES LIKE 'foreign_key_checks%
 Variable_name	Value
 foreign_key_checks	ON
 Now restore the database.
-RESTORE FROM 'backup_fkey.bak';
+RESTORE FROM 'backup_fkey.bak' OVERWRITE;
 backup_id
 #
-RESTORE FROM 'backup_fkey_orig.bak';
+RESTORE FROM 'backup_fkey_orig.bak' OVERWRITE;
 backup_id
 #
 Show data
@@ -84,7 +84,7 @@ SHOW VARIABLES LIKE 'foreign_key_checks%
 Variable_name	Value
 foreign_key_checks	ON
 Restoring data
-RESTORE FROM 'backup_fkey.bak';
+RESTORE FROM 'backup_fkey.bak' OVERWRITE;
 backup_id
 #
 Verify foreign_key_checks = ON
@@ -97,7 +97,7 @@ SHOW VARIABLES LIKE 'foreign_key_checks%
 Variable_name	Value
 foreign_key_checks	OFF
 Restoring data
-RESTORE FROM 'backup_fkey.bak';
+RESTORE FROM 'backup_fkey.bak' OVERWRITE;
 backup_id
 #
 Verify foreign_key_checks = OFF

=== modified file 'mysql-test/suite/backup/r/backup_lock_myisam.result'
--- a/mysql-test/suite/backup/r/backup_lock_myisam.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_lock_myisam.result	2008-11-17 09:57:51 +0000
@@ -54,7 +54,7 @@ DROP DATABASE db1;
 now start the restore and while the restore is running, fire the trigger
 activate synchronization points for restore.
 SET DEBUG_SYNC= 'restore_in_progress SIGNAL wait_for_restore WAIT_FOR finish';
-RESTORE FROM 'db1.bak';
+RESTORE FROM 'db1.bak' OVERWRITE;;
 From breakpoints:
 Wait for restore to reach its synchronization point.
 SET DEBUG_SYNC= 'now WAIT_FOR wait_for_restore';
@@ -92,7 +92,7 @@ DELETE FROM db2.t2;
 now start the restore and while the restore is running, fire the trigger
 activate synchronization points for restore.
 SET DEBUG_SYNC= 'restore_in_progress SIGNAL wait_for_restore WAIT_FOR finish';
-RESTORE FROM 'db1.bak';
+RESTORE FROM 'db1.bak' OVERWRITE;;
 From breakpoints:
 Wait for restore to reach its synchronization point.
 SET DEBUG_SYNC= 'now WAIT_FOR wait_for_restore';

=== modified file 'mysql-test/suite/backup/r/backup_logs.result'
--- a/mysql-test/suite/backup/r/backup_logs.result	2008-11-07 10:40:48 +0000
+++ b/mysql-test/suite/backup/r/backup_logs.result	2008-11-17 09:57:51 +0000
@@ -137,7 +137,7 @@ SET DEBUG_SYNC= 'after_backup_log_init  
 SET DEBUG_SYNC= 'after_backup_start_restore SIGNAL running WAIT_FOR finish';
 con2: Send restore command.
 con2: Backup id = 501.
-RESTORE FROM 'backup_logs_orig.bak';
+RESTORE FROM 'backup_logs_orig.bak' OVERWRITE;
 con1: Wait for the restore to be started.
 SET DEBUG_SYNC= 'now WAIT_FOR started';
 con1: Display progress
@@ -177,7 +177,7 @@ username	root
 backup_file	#
 backup_file_path	#
 user_comment	
-command	RESTORE FROM 'backup_logs_orig.bak'
+command	RESTORE FROM 'backup_logs_orig.bak' OVERWRITE
 drivers	MyISAM, Snapshot, Default
 SELECT * FROM mysql.backup_progress WHERE backup_id = 501;
 backup_id	object	start_time	stop_time	total_bytes	progress	error_num	notes

=== modified file 'mysql-test/suite/backup/r/backup_logs_purge.result'
--- a/mysql-test/suite/backup/r/backup_logs_purge.result	2008-10-28 14:17:05 +0000
+++ b/mysql-test/suite/backup/r/backup_logs_purge.result	2008-11-17 09:57:51 +0000
@@ -45,19 +45,19 @@ BACKUP DATABASE backup_logs to 'backup4.
 backup_id
 503
 Do restore of database
-RESTORE from 'backup1.bak';
+RESTORE from 'backup1.bak' OVERWRITE;
 backup_id
 504
 Do restore of database
-RESTORE from 'backup2.bak';
+RESTORE from 'backup2.bak' OVERWRITE;
 backup_id
 505
 Do restore of database
-RESTORE from 'backup3.bak';
+RESTORE from 'backup3.bak' OVERWRITE;
 backup_id
 506
 Do restore of database
-RESTORE from 'backup4.bak';
+RESTORE from 'backup4.bak' OVERWRITE;
 backup_id
 507
 Display results from backup logs
@@ -149,20 +149,20 @@ backup_id
 503
 SET SESSION debug="-d";
 Do restore of database
-RESTORE from 'backup1.bak';
+RESTORE from 'backup1.bak' OVERWRITE;
 backup_id
 504
 Do restore of database
-RESTORE from 'backup2.bak';
+RESTORE from 'backup2.bak' OVERWRITE;
 backup_id
 505
 Do restore of database
-RESTORE from 'backup3.bak';
+RESTORE from 'backup3.bak' OVERWRITE;
 backup_id
 506
 SET SESSION debug="+d,set_log_time";
 Do restore of database
-RESTORE from 'backup4.bak';
+RESTORE from 'backup4.bak' OVERWRITE;
 backup_id
 507
 SET SESSION debug="-d";
@@ -286,16 +286,16 @@ progress	0
 error_num	0
 notes	complete
 Now do the same test for restore.
-RESTORE FROM 'backup1.bak';
+RESTORE FROM 'backup1.bak' OVERWRITE;
 backup_id
 #
-RESTORE FROM 'backup2.bak';
+RESTORE FROM 'backup2.bak' OVERWRITE;
 backup_id
 #
-RESTORE FROM 'backup3.bak';
+RESTORE FROM 'backup3.bak' OVERWRITE;
 backup_id
 #
-RESTORE FROM 'backup4.bak';
+RESTORE FROM 'backup4.bak' OVERWRITE;
 backup_id
 #
 SELECT count(*) FROM mysql.backup_history;
@@ -306,7 +306,7 @@ count(*)
 13
 con2: Activate sync points for the backup statement.
 SET DEBUG_SYNC= 'before_restore_done SIGNAL ready WAIT_FOR proceed';
-RESTORE FROM 'backup5.bak';
+RESTORE FROM 'backup5.bak' OVERWRITE;
 con1: Wait for the backup to be ready.
 SET DEBUG_SYNC= 'now WAIT_FOR ready';
 PURGE BACKUP LOGS;
@@ -320,7 +320,7 @@ count(*)
 1
 SELECT backup_id, command FROM mysql.backup_history;
 backup_id	command
-505	RESTORE FROM 'backup5.bak'
+505	RESTORE FROM 'backup5.bak' OVERWRITE
 There should be one row in this table: the backup id from last
 restore (505). We should only see the complete progress 
 statement because all others were deleted while restore was

=== modified file 'mysql-test/suite/backup/r/backup_no_be.result'
--- a/mysql-test/suite/backup/r/backup_no_be.result	2008-10-30 10:41:48 +0000
+++ b/mysql-test/suite/backup/r/backup_no_be.result	2008-11-17 09:57:51 +0000
@@ -32,7 +32,7 @@ WHERE command LIKE 'BACKUP DATABASE db1 
 SELECT drivers FROM mysql.backup_history WHERE backup_id=@id;
 drivers
 Default
-RESTORE FROM 'db1.bak';
+RESTORE FROM 'db1.bak' OVERWRITE;
 backup_id
 #
 SHOW TABLES IN db1;

=== modified file 'mysql-test/suite/backup/r/backup_nodata_driver.result'
--- a/mysql-test/suite/backup/r/backup_nodata_driver.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_nodata_driver.result	2008-11-17 09:57:51 +0000
@@ -139,7 +139,7 @@ SELECT * FROM bup_nodata.e1;
 Period	Vapor_period
 DROP DATABASE bup_nodata;
 Restoring nodata database.
-RESTORE FROM 'bup_nodata.bak';
+RESTORE FROM 'bup_nodata.bak' OVERWRITE;
 backup_id
 #
 show data

=== modified file 'mysql-test/suite/backup/r/backup_security.result'
--- a/mysql-test/suite/backup/r/backup_security.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_security.result	2008-11-17 09:57:51 +0000
@@ -49,7 +49,7 @@ BACKUP DATABASE backup_test to 'bup_with
 backup_id
 #
 no_rights: Attempting restore. Should succeed
-RESTORE FROM 'bup_with_rights.bak';
+RESTORE FROM 'bup_with_rights.bak' OVERWRITE;
 backup_id
 #
 SELECT * FROM backup_test.t1;
@@ -62,7 +62,7 @@ a
 06 Test #1 - super privilege
 07 Test #1 - super privilege
 default: Do restore to ensure it still works with default test user.
-RESTORE FROM 'backup_test_orig.bak';
+RESTORE FROM 'backup_test_orig.bak' OVERWRITE;
 backup_id
 #
 SELECT * FROM backup_test.t1;

=== modified file 'mysql-test/suite/backup/r/backup_snapshot.result'
--- a/mysql-test/suite/backup/r/backup_snapshot.result	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/r/backup_snapshot.result	2008-11-17 09:57:51 +0000
@@ -60,7 +60,7 @@ backup_id
 con1: Dropping the database
 DROP TABLE bup_snapshot.t1;
 con1: Restoring the database
-RESTORE FROM "bup_snapshot.bak";
+RESTORE FROM "bup_snapshot.bak" OVERWRITE;
 backup_id
 #
 con1: Showing the data (no new data should be here).
@@ -106,7 +106,7 @@ backup_id
 con1: Dropping the database
 DROP TABLE bup_snapshot.t1;
 con1: Restoring the database
-RESTORE FROM "bup_snapshot.bak";
+RESTORE FROM "bup_snapshot.bak" OVERWRITE;
 backup_id
 #
 con1: Showing the data (no new data should be here).

=== modified file 'mysql-test/suite/backup/t/backup.test'
--- a/mysql-test/suite/backup/t/backup.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup.test	2008-11-17 09:57:51 +0000
@@ -434,7 +434,7 @@ SELECT * FROM bup_delete.me;
 
 --echo do restore
 --replace_column 1 #
-RESTORE FROM 'bup_delete.bak';
+RESTORE FROM 'bup_delete.bak' OVERWRITE;
 
 --echo show the data
 SELECT * FROM bup_delete.me;
@@ -472,7 +472,7 @@ BACKUP DATABASE bup_default TO 'bup_defa
 
 --echo Restore the database.
 --replace_column 1 #
-RESTORE FROM 'bup_default_timestamp.bak';
+RESTORE FROM 'bup_default_timestamp.bak' OVERWRITE;
 
 --echo Show data after restore (timestamp should be same as above).
 SELECT * FROM bup_default.time_t1;

=== modified file 'mysql-test/suite/backup/t/backup_backupdir.test'
--- a/mysql-test/suite/backup/t/backup_backupdir.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_backupdir.test	2008-11-17 09:57:51 +0000
@@ -41,7 +41,7 @@ BACKUP DATABASE bup_backupdir TO 'bup_ba
 
 --echo Perform restore
 --replace_column 1 #
-RESTORE FROM 'bup_backupdir1.bak';
+RESTORE FROM 'bup_backupdir1.bak' OVERWRITE;
 
 --echo Now do the backup and restore by specifying a path.
 
@@ -54,7 +54,7 @@ BACKUP DATABASE bup_backupdir TO '../bup
 
 --echo Perform restore
 --replace_column 1 #
-RESTORE FROM '../bup_backupdir2.bak';
+RESTORE FROM '../bup_backupdir2.bak' OVERWRITE;
 
 --echo Perform backup
 --replace_column 1 #

=== modified file 'mysql-test/suite/backup/t/backup_commit_backup.test'
--- a/mysql-test/suite/backup/t/backup_commit_backup.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_commit_backup.test	2008-11-17 09:57:51 +0000
@@ -216,7 +216,7 @@ SELECT release_lock("sync");
 echo Checking contents of the backup image;
 
 replace_column 1 #;
-RESTORE FROM 'db1.bak';
+RESTORE FROM 'db1.bak' OVERWRITE;
 
 SELECT * FROM db1.t1;
 SELECT * FROM db1.t2;

=== modified file 'mysql-test/suite/backup/t/backup_commit_blocker.test'
--- a/mysql-test/suite/backup/t/backup_commit_blocker.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_commit_blocker.test	2008-11-17 09:57:51 +0000
@@ -292,7 +292,7 @@ DROP TABLE bup_commit_blocker.t3;
 
 --echo con1: Restoring the database
 --replace_column 1 #
- RESTORE FROM "bup_commit_blocker.bak";
+ RESTORE FROM "bup_commit_blocker.bak" OVERWRITE;
 
 --echo con1: Showing the data (no new data should be here).
 SELECT * FROM bup_commit_blocker.t1;
@@ -458,7 +458,7 @@ DROP TABLE bup_commit_blocker.t5;
 
 --echo con1: Restoring the database
 --replace_column 1 #
- RESTORE FROM "bup_commit_blocker.bak";
+ RESTORE FROM "bup_commit_blocker.bak" OVERWRITE;
 
 --echo con1: Showing the data (no new data should be here).
 #SELECT * FROM bup_commit_blocker.t4;
@@ -764,7 +764,7 @@ DROP TABLE bup_commit_blocker.t5;
 
 --echo con1: Restoring the database
 --replace_column 1 #
-RESTORE FROM "bup_commit_blocker.bak";
+RESTORE FROM "bup_commit_blocker.bak" OVERWRITE;
 
 --echo con1: Showing the data (no new data should be here).
 SELECT * FROM bup_commit_blocker.t1;

=== modified file 'mysql-test/suite/backup/t/backup_commit_restore.test'
--- a/mysql-test/suite/backup/t/backup_commit_restore.test	2008-10-23 08:13:54 +0000
+++ b/mysql-test/suite/backup/t/backup_commit_restore.test	2008-11-17 09:57:51 +0000
@@ -20,7 +20,7 @@ replace_column 1 #;
 BACKUP DATABASE commit_test TO '81';
 
 replace_column 1 #;
-RESTORE FROM '81';
+RESTORE FROM '81' OVERWRITE;
 
 SELECT * FROM t1;
 ROLLBACK;
@@ -37,7 +37,7 @@ replace_column 1 #;
 BACKUP DATABASE commit_test TO '82';
 
 replace_column 1 #;
-RESTORE FROM '82';
+RESTORE FROM '82' OVERWRITE;
 
 SELECT * FROM t1;
 SELECT * FROM t2;
@@ -58,7 +58,7 @@ replace_column 1 #;
 BACKUP DATABASE commit_test TO '83';
 
 replace_column 1 #;
-RESTORE FROM '83';
+RESTORE FROM '83' OVERWRITE;
 
 SELECT * FROM t1;
 SELECT * FROM t2;
@@ -81,7 +81,7 @@ replace_column 1 #;
 BACKUP DATABASE commit_test TO '84';
 
 replace_column 1 #;
-RESTORE FROM '84';
+RESTORE FROM '84' OVERWRITE;
 
 SELECT * FROM t1;
 SELECT * FROM t2;
@@ -106,7 +106,7 @@ replace_column 1 #;
 BACKUP DATABASE commit_test TO '85';
 
 replace_column 1 #;
-RESTORE FROM '85';
+RESTORE FROM '85' OVERWRITE;
 
 SELECT * FROM t1;
 SELECT * FROM t2;
@@ -133,7 +133,7 @@ BACKUP DATABASE commit_test TO '86';
 
 SET @@autocommit=0;
 replace_column 1 #;
-RESTORE FROM '86';
+RESTORE FROM '86' OVERWRITE;
 
 #Test of scenario from BUG#34205
 DROP TABLE t5;
@@ -162,7 +162,7 @@ BACKUP DATABASE commit_test TO '87';
 
 SET @@autocommit=1;
 replace_column 1 #;
-RESTORE FROM '87';
+RESTORE FROM '87' OVERWRITE;
 
 SELECT * FROM t1;
 SELECT * FROM t2;

=== modified file 'mysql-test/suite/backup/t/backup_compression.test'
--- a/mysql-test/suite/backup/t/backup_compression.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_compression.test	2008-11-17 09:57:51 +0000
@@ -12,11 +12,11 @@ replace_column 1 #;
 BACKUP DATABASE db1 TO 'db2.bak.gz' WITH COMPRESSION COMPRESSION_ALGORITHM=gzip;
 
 replace_column 1 #;
-RESTORE FROM 'db1.bak.gz';
+RESTORE FROM 'db1.bak.gz' OVERWRITE;
 SHOW TABLES FROM db1;
 
 replace_column 1 #;
-RESTORE FROM 'db2.bak.gz';
+RESTORE FROM 'db2.bak.gz' OVERWRITE;
 SHOW TABLES FROM db1;
 
 DROP DATABASE db1;

=== modified file 'mysql-test/suite/backup/t/backup_concurrent.test'
--- a/mysql-test/suite/backup/t/backup_concurrent.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_concurrent.test	2008-11-17 09:57:51 +0000
@@ -79,7 +79,7 @@ reap;
 --echo ---------------------------------------------------
 --echo Starting restore
 SET DEBUG_SYNC= 'after_backup_start_restore SIGNAL running WAIT_FOR restore';
-send RESTORE FROM 'backup1';
+send RESTORE FROM 'backup1' OVERWRITE;
 
 connection default;
 --echo Waiting for restore to get going

=== modified file 'mysql-test/suite/backup/t/backup_db_grants.test'
--- a/mysql-test/suite/backup/t/backup_db_grants.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_db_grants.test	2008-11-17 09:57:51 +0000
@@ -63,7 +63,7 @@ SHOW GRANTS FOR 'bup_user3'@'%';
 
 --echo Run Restore
 --replace_column 1 #
-RESTORE FROM 'bup_db_grants.bak';
+RESTORE FROM 'bup_db_grants.bak' OVERWRITE;
 
 SHOW TABLES FROM bup_db_grants;
 
@@ -90,7 +90,7 @@ CREATE USER 'bup_user1'@'nosuchhost';
 
 --echo Run Restore
 --replace_column 1 #
-RESTORE FROM 'bup_db_grants.bak';
+RESTORE FROM 'bup_db_grants.bak' OVERWRITE;
 
 SHOW TABLES FROM bup_db_grants;
 
@@ -178,7 +178,7 @@ EXECUTE stmt3;
 
 --echo Run restore.
 --replace_column 1 #
-RESTORE FROM 'bup_db_grants.bak';
+RESTORE FROM 'bup_db_grants.bak' OVERWRITE;
 
 FLUSH PRIVILEGES;
 

=== modified file 'mysql-test/suite/backup/t/backup_errors.test'
--- a/mysql-test/suite/backup/t/backup_errors.test	2008-11-05 09:41:15 +0000
+++ b/mysql-test/suite/backup/t/backup_errors.test	2008-11-17 09:57:51 +0000
@@ -294,3 +294,54 @@ DROP DATABASE db1;
 
 --echo
 --echo Done testing for Bug#38624
+
+
+--echo 
+--echo Testing RESTORE ... OVERWRITE functionality
+--echo See bug#34579
+--echo
+
+--source include/not_embedded.inc
+
+--echo Initialize
+CREATE DATABASE db1;
+USE db1;
+CREATE TABLE table1 (text VARCHAR(20));
+INSERT INTO table1 VALUES ('Inserted before');
+
+--echo 
+--echo Backup database
+--replace_column 1 #
+BACKUP DATABASE db1 TO 'overwrite.bak';
+
+--echo 
+--echo Insert more data and display
+INSERT INTO table1 VALUES ('Inserted after');
+SELECT * FROM table1;
+
+--echo 
+--echo Restore without OVERWRITE flag; will fail
+--error ER_RESTORE_DB_EXISTS
+RESTORE FROM 'overwrite.bak';
+
+--echo 
+--echo Restore with OVERWRITE flag; will succeed
+--replace_column 1 #
+RESTORE FROM 'overwrite.bak' OVERWRITE;
+
+--echo 
+--echo Show that inserted value 2 is not there
+SELECT * FROM table1;
+
+DROP DATABASE db1;
+
+--echo 
+--echo Restore after deleting db; will succeed
+--replace_column 1 #
+RESTORE FROM 'overwrite.bak';
+
+--echo 
+--echo Show that inserted value 2 is not there
+SELECT * FROM table1;
+
+DROP DATABASE db1;

=== modified file 'mysql-test/suite/backup/t/backup_fkey.test'
--- a/mysql-test/suite/backup/t/backup_fkey.test	2008-10-24 08:25:48 +0000
+++ b/mysql-test/suite/backup/t/backup_fkey.test	2008-11-17 09:57:51 +0000
@@ -79,12 +79,12 @@ SHOW VARIABLES LIKE 'foreign_key_checks%
 # Restore the database and ensure there are no errors.
 --echo Now restore the database.
 --replace_column 1 #
-RESTORE FROM 'backup_fkey.bak';
+RESTORE FROM 'backup_fkey.bak' OVERWRITE;
 
 # Now restore the original files to show there are no problems
 # restoring valid fkey relationships.
 --replace_column 1 #
-RESTORE FROM 'backup_fkey_orig.bak';
+RESTORE FROM 'backup_fkey_orig.bak' OVERWRITE;
 
 --echo Show data
 SELECT * FROM backup_fkey.parent;
@@ -120,7 +120,7 @@ SHOW VARIABLES LIKE 'foreign_key_checks%
 
 --echo Restoring data
 --replace_column 1 #
-RESTORE FROM 'backup_fkey.bak';
+RESTORE FROM 'backup_fkey.bak' OVERWRITE;
 
 --echo Verify foreign_key_checks = ON
 SHOW VARIABLES LIKE 'foreign_key_checks%';
@@ -131,7 +131,7 @@ SHOW VARIABLES LIKE 'foreign_key_checks%
 
 --echo Restoring data
 --replace_column 1 #
-RESTORE FROM 'backup_fkey.bak';
+RESTORE FROM 'backup_fkey.bak' OVERWRITE;
 
 --echo Verify foreign_key_checks = OFF
 SHOW VARIABLES LIKE 'foreign_key_checks%';

=== modified file 'mysql-test/suite/backup/t/backup_lock_myisam.test'
--- a/mysql-test/suite/backup/t/backup_lock_myisam.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_lock_myisam.test	2008-11-17 09:57:51 +0000
@@ -98,7 +98,7 @@ DROP DATABASE db1;
 --echo now start the restore and while the restore is running, fire the trigger
 --echo activate synchronization points for restore.
 SET DEBUG_SYNC= 'restore_in_progress SIGNAL wait_for_restore WAIT_FOR finish';
---send RESTORE FROM 'db1.bak'
+--send RESTORE FROM 'db1.bak' OVERWRITE;
 
 --echo From breakpoints:
 --connection breakpoints
@@ -147,7 +147,7 @@ DELETE FROM db2.t2;
 --echo now start the restore and while the restore is running, fire the trigger
 --echo activate synchronization points for restore.
 SET DEBUG_SYNC= 'restore_in_progress SIGNAL wait_for_restore WAIT_FOR finish';
---send RESTORE FROM 'db1.bak'
+--send RESTORE FROM 'db1.bak' OVERWRITE;
 
 --echo From breakpoints:
 --connection breakpoints

=== modified file 'mysql-test/suite/backup/t/backup_logs.test'
--- a/mysql-test/suite/backup/t/backup_logs.test	2008-11-07 10:40:48 +0000
+++ b/mysql-test/suite/backup/t/backup_logs.test	2008-11-17 09:57:51 +0000
@@ -154,7 +154,7 @@ SET DEBUG_SYNC= 'after_backup_start_rest
 
 --echo con2: Send restore command.
 --echo con2: Backup id = 501.
-send RESTORE FROM 'backup_logs_orig.bak';
+send RESTORE FROM 'backup_logs_orig.bak' OVERWRITE;
 
 connection con1;
 

=== modified file 'mysql-test/suite/backup/t/backup_logs_purge.test'
--- a/mysql-test/suite/backup/t/backup_logs_purge.test	2008-10-28 14:17:05 +0000
+++ b/mysql-test/suite/backup/t/backup_logs_purge.test	2008-11-17 09:57:51 +0000
@@ -74,16 +74,16 @@ BACKUP DATABASE backup_logs to 'backup3.
 BACKUP DATABASE backup_logs to 'backup4.bak';
 
 --echo Do restore of database
-RESTORE from 'backup1.bak';
+RESTORE from 'backup1.bak' OVERWRITE;
 
 --echo Do restore of database
-RESTORE from 'backup2.bak';
+RESTORE from 'backup2.bak' OVERWRITE;
 
 --echo Do restore of database
-RESTORE from 'backup3.bak';
+RESTORE from 'backup3.bak' OVERWRITE;
 
 --echo Do restore of database
-RESTORE from 'backup4.bak';
+RESTORE from 'backup4.bak' OVERWRITE;
 
 --file_exists $MYSQLTEST_VARDIR/master-data/backup1.bak
 --file_exists $MYSQLTEST_VARDIR/master-data/backup2.bak
@@ -148,18 +148,18 @@ BACKUP DATABASE backup_logs to 'backup4.
 SET SESSION debug="-d";
 
 --echo Do restore of database
-RESTORE from 'backup1.bak';
+RESTORE from 'backup1.bak' OVERWRITE;
 
 --echo Do restore of database
-RESTORE from 'backup2.bak';
+RESTORE from 'backup2.bak' OVERWRITE;
 
 --echo Do restore of database
-RESTORE from 'backup3.bak';
+RESTORE from 'backup3.bak' OVERWRITE;
 
 SET SESSION debug="+d,set_log_time";
 
 --echo Do restore of database
-RESTORE from 'backup4.bak';
+RESTORE from 'backup4.bak' OVERWRITE;
 
 SET SESSION debug="-d";
 
@@ -310,13 +310,13 @@ SELECT count(*) FROM mysql.backup_progre
 --echo Now do the same test for restore.
 
 --replace_column 1 #
-RESTORE FROM 'backup1.bak';
+RESTORE FROM 'backup1.bak' OVERWRITE;
 --replace_column 1 #
-RESTORE FROM 'backup2.bak';
+RESTORE FROM 'backup2.bak' OVERWRITE;
 --replace_column 1 #
-RESTORE FROM 'backup3.bak';
+RESTORE FROM 'backup3.bak' OVERWRITE;
 --replace_column 1 #
-RESTORE FROM 'backup4.bak';
+RESTORE FROM 'backup4.bak' OVERWRITE;
 
 SELECT count(*) FROM mysql.backup_history;
 SELECT count(*) FROM mysql.backup_progress;
@@ -329,7 +329,7 @@ connection con2;
 #
 --echo con2: Activate sync points for the backup statement.
 SET DEBUG_SYNC= 'before_restore_done SIGNAL ready WAIT_FOR proceed';
-SEND RESTORE FROM 'backup5.bak';
+SEND RESTORE FROM 'backup5.bak' OVERWRITE;
 
 connection con1;
 

=== modified file 'mysql-test/suite/backup/t/backup_no_be.test'
--- a/mysql-test/suite/backup/t/backup_no_be.test	2008-10-30 10:41:48 +0000
+++ b/mysql-test/suite/backup/t/backup_no_be.test	2008-11-17 09:57:51 +0000
@@ -84,7 +84,7 @@ SELECT drivers FROM mysql.backup_history
 # check that we can restore from the created image.
 
 --replace_column 1 #
-RESTORE FROM 'db1.bak';
+RESTORE FROM 'db1.bak' OVERWRITE;
 SHOW TABLES IN db1;
 
 

=== modified file 'mysql-test/suite/backup/t/backup_nodata_driver.test'
--- a/mysql-test/suite/backup/t/backup_nodata_driver.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_nodata_driver.test	2008-11-17 09:57:51 +0000
@@ -127,7 +127,7 @@ DROP DATABASE bup_nodata;
 # Now restore the nodata database and see if it is the same as above.
 --echo Restoring nodata database.
 --replace_column 1 #
-RESTORE FROM 'bup_nodata.bak';
+RESTORE FROM 'bup_nodata.bak' OVERWRITE;
 
 # Show the data
 --echo show data

=== modified file 'mysql-test/suite/backup/t/backup_security.test'
--- a/mysql-test/suite/backup/t/backup_security.test	2008-10-24 08:25:48 +0000
+++ b/mysql-test/suite/backup/t/backup_security.test	2008-11-17 09:57:51 +0000
@@ -72,7 +72,7 @@ BACKUP DATABASE backup_test to 'bup_with
 
 --echo no_rights: Attempting restore. Should succeed
 --replace_column 1 #
-RESTORE FROM 'bup_with_rights.bak';
+RESTORE FROM 'bup_with_rights.bak' OVERWRITE;
 
 SELECT * FROM backup_test.t1;
 
@@ -82,7 +82,7 @@ disconnect with_rights;
 connection default;
 
 --replace_column 1 #
-RESTORE FROM 'backup_test_orig.bak';
+RESTORE FROM 'backup_test_orig.bak' OVERWRITE;
 
 SELECT * FROM backup_test.t1;
 

=== modified file 'mysql-test/suite/backup/t/backup_snapshot.test'
--- a/mysql-test/suite/backup/t/backup_snapshot.test	2008-10-07 17:15:44 +0000
+++ b/mysql-test/suite/backup/t/backup_snapshot.test	2008-11-17 09:57:51 +0000
@@ -116,7 +116,7 @@ DROP TABLE bup_snapshot.t1;
 
 --echo con1: Restoring the database
 --replace_column 1 #
-RESTORE FROM "bup_snapshot.bak";
+RESTORE FROM "bup_snapshot.bak" OVERWRITE;
 
 --echo con1: Showing the data (no new data should be here).
 SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';
@@ -175,7 +175,7 @@ DROP TABLE bup_snapshot.t1;
 
 --echo con1: Restoring the database
 --replace_column 1 #
-RESTORE FROM "bup_snapshot.bak";
+RESTORE FROM "bup_snapshot.bak" OVERWRITE;
 
 --echo con1: Showing the data (no new data should be here).
 SELECT * FROM bup_snapshot.t1 WHERE word LIKE '-%';

=== modified file 'mysql-test/suite/backup_engines/include/backup_ptr_commit.inc'
--- a/mysql-test/suite/backup_engines/include/backup_ptr_commit.inc	2008-10-08 04:26:25 +0000
+++ b/mysql-test/suite/backup_engines/include/backup_ptr_commit.inc	2008-11-17 09:57:51 +0000
@@ -202,7 +202,7 @@ SELECT * FROM ptr.t3;
 
 --echo Perform restore operation
 --replace_column 1 #
-RESTORE FROM 'ptr_commit.bak';
+RESTORE FROM 'ptr_commit.bak' OVERWRITE;
 SHOW TABLES FROM ptr;
 SELECT * FROM ptr.t1;
 SELECT * FROM ptr.t2;

=== modified file 'mysql-test/suite/backup_engines/r/backup_ptr_commit_mixed.result'
--- a/mysql-test/suite/backup_engines/r/backup_ptr_commit_mixed.result	2008-10-08 04:26:25 +0000
+++ b/mysql-test/suite/backup_engines/r/backup_ptr_commit_mixed.result	2008-11-17 09:57:51 +0000
@@ -304,7 +304,7 @@ id	name
 Perform Restore and Recover committed data using mysqlbinlog position
 after backup.
 Perform restore operation
-RESTORE FROM 'ptr_commit.bak';
+RESTORE FROM 'ptr_commit.bak' OVERWRITE;
 backup_id
 #
 SHOW TABLES FROM ptr;

=== modified file 'mysql-test/suite/backup_engines/r/backup_ptr_commit_row.result'
--- a/mysql-test/suite/backup_engines/r/backup_ptr_commit_row.result	2008-10-08 04:26:25 +0000
+++ b/mysql-test/suite/backup_engines/r/backup_ptr_commit_row.result	2008-11-17 09:57:51 +0000
@@ -304,7 +304,7 @@ id	name
 Perform Restore and Recover committed data using mysqlbinlog position
 after backup.
 Perform restore operation
-RESTORE FROM 'ptr_commit.bak';
+RESTORE FROM 'ptr_commit.bak' OVERWRITE;
 backup_id
 #
 SHOW TABLES FROM ptr;

=== modified file 'mysql-test/suite/backup_engines/r/backup_ptr_commit_stmt.result'
--- a/mysql-test/suite/backup_engines/r/backup_ptr_commit_stmt.result	2008-10-08 04:26:25 +0000
+++ b/mysql-test/suite/backup_engines/r/backup_ptr_commit_stmt.result	2008-11-17 09:57:51 +0000
@@ -304,7 +304,7 @@ id	name
 Perform Restore and Recover committed data using mysqlbinlog position
 after backup.
 Perform restore operation
-RESTORE FROM 'ptr_commit.bak';
+RESTORE FROM 'ptr_commit.bak' OVERWRITE;
 backup_id
 #
 SHOW TABLES FROM ptr;

=== modified file 'mysql-test/suite/backup_engines/r/backup_tmp_tables.result'
--- a/mysql-test/suite/backup_engines/r/backup_tmp_tables.result	2008-10-30 12:29:54 +0000
+++ b/mysql-test/suite/backup_engines/r/backup_tmp_tables.result	2008-11-17 09:57:51 +0000
@@ -29,7 +29,7 @@ backup_id
 ** Drop and restore the database
 DROP TABLE t1;
 DROP TABLE t2;
-RESTORE FROM 'db.bkp';
+RESTORE FROM 'db.bkp' OVERWRITE;
 backup_id
 #
 ** Check definitions of the tables after restore

=== modified file 'mysql-test/suite/backup_engines/t/backup_tmp_tables.test'
--- a/mysql-test/suite/backup_engines/t/backup_tmp_tables.test	2008-11-12 17:42:23 +0000
+++ b/mysql-test/suite/backup_engines/t/backup_tmp_tables.test	2008-11-17 09:57:51 +0000
@@ -52,7 +52,7 @@ BACKUP DATABASE db TO 'db.bkp';
 DROP TABLE t1;
 DROP TABLE t2;
 --replace_column 1 #
-RESTORE FROM 'db.bkp';
+RESTORE FROM 'db.bkp' OVERWRITE;
 
 #
 # Note: Above DROP TABLE statements should be removed once BUG#30099 is fixed.

=== modified file 'mysql-test/suite/rpl/r/rpl_backup.result'
--- a/mysql-test/suite/rpl/r/rpl_backup.result	2008-10-31 15:31:52 +0000
+++ b/mysql-test/suite/rpl/r/rpl_backup.result	2008-11-17 09:57:51 +0000
@@ -169,7 +169,7 @@ CREATE TABLE rpl_backup.t2 (b int);
 INSERT INTO rpl_backup.t2 VALUES (888), (999);
 Get master's binlog position before restore.
 Backup_id = 502.
-RESTORE FROM 'rpl_bup_m2.bak';
+RESTORE FROM 'rpl_bup_m2.bak' OVERWRITE;
 backup_id
 502
 Show the incident event issued as a result of restore.
@@ -241,7 +241,7 @@ t1	BASE TABLE
 t2	BASE TABLE
 STOP SLAVE;
 Backup_id = 602.
-RESTORE FROM '../master-data/rpl_bup_m2.bak';
+RESTORE FROM '../master-data/rpl_bup_m2.bak' OVERWRITE;
 backup_id
 602
 Showing databases on slave.
@@ -258,11 +258,11 @@ BACKUP DATABASE rpl_backup TO 'rpl_bup_s
 backup_id
 603
 Test restore on slave while replication turned on.
-RESTORE FROM 'rpl_bup_s1.bak';
+RESTORE FROM 'rpl_bup_s1.bak' OVERWRITE;
 ERROR HY000: A restore operation was attempted on a slave during replication. You must stop the slave prior to running a restore.
 Stop slave and restart after restore.
 STOP SLAVE;
-RESTORE FROM 'rpl_bup_s3.bak';
+RESTORE FROM 'rpl_bup_s3.bak' OVERWRITE;
 backup_id
 #
 START SLAVE;
@@ -312,7 +312,7 @@ sql_log_bin	ON
 RESET MASTER;
 Get master's binlog position before restore.
 Backup_id = 504.
-RESTORE FROM 'rpl_bup_m3.bak';
+RESTORE FROM 'rpl_bup_m3.bak' OVERWRITE;
 backup_id
 504
 Get master's binlog position after restore.

=== modified file 'mysql-test/suite/rpl/t/rpl_backup.test'
--- a/mysql-test/suite/rpl/t/rpl_backup.test	2008-10-31 15:31:52 +0000
+++ b/mysql-test/suite/rpl/t/rpl_backup.test	2008-11-17 09:57:51 +0000
@@ -209,7 +209,7 @@ INSERT INTO rpl_backup.t2 VALUES (888), 
 let $master_before_pos = query_get_value("SHOW MASTER STATUS", Position, 1);
 
 --echo Backup_id = 502.
-RESTORE FROM 'rpl_bup_m2.bak';
+RESTORE FROM 'rpl_bup_m2.bak' OVERWRITE;
 
 --echo Show the incident event issued as a result of restore.
 --replace_column 2 # 5 #
@@ -266,7 +266,7 @@ STOP SLAVE;
 --source include/wait_for_slave_to_stop.inc
 
 --echo Backup_id = 602.
-RESTORE FROM '../master-data/rpl_bup_m2.bak';
+RESTORE FROM '../master-data/rpl_bup_m2.bak' OVERWRITE;
 
 --echo Showing databases on slave.
 SHOW DATABASES LIKE 'rpl_backup%';
@@ -289,13 +289,13 @@ connection slave;
 --echo Test restore on slave while replication turned on.
 
 --error ER_RESTORE_ON_SLAVE
-RESTORE FROM 'rpl_bup_s1.bak';
+RESTORE FROM 'rpl_bup_s1.bak' OVERWRITE;
 
 --echo Stop slave and restart after restore.
 STOP SLAVE;
 
 --replace_column 1 #
-RESTORE FROM 'rpl_bup_s3.bak';
+RESTORE FROM 'rpl_bup_s3.bak' OVERWRITE;
 
 START SLAVE;
 --source include/wait_for_slave_to_start.inc
@@ -354,7 +354,7 @@ RESET MASTER;
 let $master_before_pos = query_get_value("SHOW MASTER STATUS", Position, 1);
 
 --echo Backup_id = 504.
-RESTORE FROM 'rpl_bup_m3.bak';
+RESTORE FROM 'rpl_bup_m3.bak' OVERWRITE;
 
 --echo Get master's binlog position after restore.
 let $master_after_pos = query_get_value("SHOW MASTER STATUS", Position, 1);

=== modified file 'sql/backup/backup_kernel.h'
--- a/sql/backup/backup_kernel.h	2008-11-13 13:02:36 +0000
+++ b/sql/backup/backup_kernel.h	2008-11-17 09:57:51 +0000
@@ -30,7 +30,7 @@ void backup_shutdown();
   Called from the big switch in mysql_execute_command() to execute
   backup related statement
 */
-int execute_backup_command(THD*, LEX*, String*);
+int execute_backup_command(THD*, LEX*, String*, bool);
 
 // forward declarations
 
@@ -74,7 +74,7 @@ class Backup_restore_ctx: public backup:
                                    const char*);  
 
   int do_backup();
-  int do_restore();
+  int do_restore(bool overwrite);
   int fatal_error(int, ...);
   int log_error(int, ...);
 

=== modified file 'sql/backup/kernel.cc'
--- a/sql/backup/kernel.cc	2008-11-14 15:02:10 +0000
+++ b/sql/backup/kernel.cc	2008-11-17 09:57:51 +0000
@@ -121,6 +121,8 @@ static int send_reply(Backup_restore_ctx
   @param[IN] thd        current thread object reference.
   @param[IN] lex        results of parsing the statement.
   @param[IN] backupdir  value of the backupdir variable from server.
+  @param[IN] overwrite  whether or not restore should overwrite existing
+                        DB with same name as in backup image
 
   @note This function sends response to the client (ok, result set or error).
 
@@ -132,7 +134,7 @@ static int send_reply(Backup_restore_ctx
  */
 
 int
-execute_backup_command(THD *thd, LEX *lex, String *backupdir)
+execute_backup_command(THD *thd, LEX *lex, String *backupdir, bool overwrite)
 {
   int res= 0;
   
@@ -226,7 +228,7 @@ execute_backup_command(THD *thd, LEX *le
     
     DEBUG_SYNC(thd, "after_backup_start_restore");
 
-    res= context.do_restore();      
+    res= context.do_restore(overwrite);      
 
     DEBUG_SYNC(thd, "restore_before_end");
 
@@ -1198,11 +1200,14 @@ int Backup_restore_ctx::restore_triggers
 
   @pre @c prepare_for_restore() method was called.
 
+  @param[IN] overwrite whether or not restore should overwrite existing
+                       DB with same name as in backup image
+
   @returns 0 on success, error code otherwise.
 
   @todo Remove the @c reset_diagnostic_area() hack.
 */
-int Backup_restore_ctx::do_restore()
+int Backup_restore_ctx::do_restore(bool overwrite)
 {
   DBUG_ENTER("do_restore");
 
@@ -1222,6 +1227,23 @@ int Backup_restore_ctx::do_restore()
 
   DBUG_PRINT("restore", ("Restoring meta-data"));
 
+  // unless RESTORE... OVERWRITE: return error if database already exists
+  if (!overwrite) {
+    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;
+  }
+
   disable_fkey_constraints();                   // Never errors
 
   if (read_meta_data(info, s))

=== modified file 'sql/lex.h'
--- a/sql/lex.h	2008-07-09 07:12:43 +0000
+++ b/sql/lex.h	2008-11-17 09:57:51 +0000
@@ -389,6 +389,7 @@ static SYMBOL symbols[] = {
   { "OUT",              SYM(OUT_SYM)},
   { "OUTER",		SYM(OUTER)},
   { "OUTFILE",		SYM(OUTFILE)},
+  { "OVERWRITE",		SYM(OVERWRITE_SYM)},
   { "OWNER",		SYM(OWNER_SYM)},
   { "PACK_KEYS",	SYM(PACK_KEYS_SYM)},
   { "PARSER",           SYM(PARSER_SYM)},

=== modified file 'sql/share/errmsg.txt'
--- a/sql/share/errmsg.txt	2008-11-13 08:40:43 +0000
+++ b/sql/share/errmsg.txt	2008-11-17 09:57:51 +0000
@@ -6432,6 +6432,7 @@ 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_NONUNIQ_DB 42000 S1009
         eng "Not unique database: '%-.192s'"
+ER_RESTORE_DB_EXISTS
+  eng "Database \'%-.64s\' already exists. Use OVERWRITE flag to overwrite."
 ER_QUERY_CACHE_DISABLED
 	eng "Query cache is disabled; restart the server with query_cache_type=1 to enable it"
-

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2008-11-13 08:40:43 +0000
+++ b/sql/sql_parse.cc	2008-11-17 09:57:51 +0000
@@ -43,7 +43,7 @@
   @defgroup Runtime_Environment Runtime Environment
   @{
 */
-int execute_backup_command(THD*, LEX*, String*);
+int execute_backup_command(THD*, LEX*, String*, bool);
 
 /* Used in error handling only */
 #define SP_TYPE_STRING(LP) \
@@ -2312,11 +2312,29 @@ mysql_execute_command(THD *thd)
                         sys_var_backupdir.value_length);
     backupdir.length(sys_var_backupdir.value_length);
 
+    /* Used to specify if RESTORE should overwrite existing db with same name */
+    bool overwrite_restore= false;
+
+    Item *it= (Item *)lex->value_list.head();
+
+    // Item only set for RESTORE in sql_yacc.yy, no error checking of
+    // item necessary
+    if (it)
+    {
+      /*
+        it is OK to only emulate fix_fields, because we need only
+        value of constant
+      */
+      it->quick_fix_field();
+
+      if ((int8)it->val_int() == 1)
+        overwrite_restore= true;
+    }
     /*
       Note: execute_backup_command() sends a correct response to the client
       (either ok, result set or error message).
      */ 
-    if (execute_backup_command(thd, lex, &backupdir))
+    if (execute_backup_command(thd, lex, &backupdir, overwrite_restore))
       goto error;
     break;
   }

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2008-11-13 08:40:43 +0000
+++ b/sql/sql_yacc.yy	2008-11-17 09:57:51 +0000
@@ -974,6 +974,7 @@ bool my_yyoverflow(short **a, YYSTYPE **
 %token  OUTER
 %token  OUTFILE
 %token  OUT_SYM                       /* SQL-2003-R */
+%token  OVERWRITE_SYM
 %token  OWNER_SYM
 %token  PACK_KEYS_SYM
 %token  PAGE_SYM
@@ -6433,12 +6434,32 @@ restore:
             lex->clear_db_list();
           }
           FROM
-          TEXT_STRING_sys
+          TEXT_STRING_sys 
+          opt_overwrite
           {
             Lex->backup_dir = $4; 
           }
         ;
 
+opt_overwrite:
+          /* empty */ 
+          {         
+            LEX *lex= Lex;
+            Item *it= new Item_int((int8) 0);
+
+            lex->value_list.empty();
+            lex->value_list.push_front(it);
+          }
+        | OVERWRITE_SYM 
+          {
+            LEX *lex= Lex;
+            Item *it= new Item_int((int8) 1);
+
+            lex->value_list.empty();
+            lex->value_list.push_front(it);
+           }
+         ;
+
 backup:   
           BACKUP_SYM 
           {

Thread
bzr push into mysql-6.0-backup branch (jorgen.loland:2735) Jorgen Loland17 Nov