#At file:///export/home/tmp/wl-4229/mysql-6.0-backup/ based on
revid:charles.bell@stripped
2744 Hema Sridharan 2008-12-22
WL#4229. New patch with some modifications.
added:
mysql-test/include/blackhole.inc
modified:
mysql-test/suite/backup/r/backup_errors.result
mysql-test/suite/backup/r/backup_logs.result
mysql-test/suite/backup/t/backup_errors.test
mysql-test/suite/backup/t/backup_logs.test
=== added file 'mysql-test/include/blackhole.inc'
--- a/mysql-test/include/blackhole.inc 1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/blackhole.inc 2008-12-22 21:14:06 +0000
@@ -0,0 +1,5 @@
+disable_query_log;
+--require r/true.require
+select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines
where engine = 'blackhole';
+enable_query_log;
+
=== modified file 'mysql-test/suite/backup/r/backup_errors.result'
--- a/mysql-test/suite/backup/r/backup_errors.result 2008-12-15 12:18:24 +0000
+++ b/mysql-test/suite/backup/r/backup_errors.result 2008-12-22 21:14:06 +0000
@@ -2,6 +2,21 @@ DROP DATABASE IF EXISTS adb;
DROP DATABASE IF EXISTS bdb;
RESTORE FROM 'test.bak';
ERROR HY000: File 'MYSQLTEST_VARDIR/master-data/test.bak' not found (Errcode: #)
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "RESTORE FROM 'test%";
+verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+backup_state operation backup_file
+error restore test.bak
+SELECT notes FROM mysql.backup_progress
+WHERE backup_id=@bup_id;
+notes
+starting
+running
+Can't read backup location 'test.bak'
+error
CREATE DATABASE adb;
CREATE DATABASE bdb;
CREATE TABLE bdb.t1(a int) ENGINE=MEMORY;
@@ -10,6 +25,21 @@ ERROR HY000: Malformed file path ''
SHOW WARNINGS;
Level Code Message
Error # Malformed file path ''
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE adb TO%";
+verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+backup_state operation backup_file
+error backup
+SELECT notes FROM mysql.backup_progress
+WHERE backup_id=@bup_id;
+notes
+starting
+running
+Malformed file path ''
+error
BACKUP DATABASE adb TO "bdb/t1.frm";
ERROR HY000: Can't create/write to file 'MYSQLTEST_VARDIR/master-data/bdb/t1.frm'
(Errcode: #)
SHOW WARNINGS;
@@ -25,13 +55,28 @@ SHOW WARNINGS;
Level Code Message
Error # Can't create/write to file 'MYSQLTEST_VARDIR/master-data/test.bak' (Errcode: #)
Error # Can't write to backup location 'test.bak'
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE adb TO%";
+verify backup history and progress logs for backup_state.
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+backup_state operation backup_file
+error backup test.bak
+SELECT notes FROM mysql.backup_progress
+WHERE backup_id=@bup_id;
+notes
+starting
+running
+Can't write to backup location 'test.bak'
+error
DROP DATABASE IF EXISTS foo;
DROP DATABASE IF EXISTS bar;
BACKUP DATABASE foo TO 'test.bak';
ERROR 42000: Unknown database 'foo'
SHOW WARNINGS;
Level Code Message
-Error 1049 Unknown database 'foo'
+Error # Unknown database 'foo'
BACKUP DATABASE test,foo,bdb,bar TO 'test.bak';
ERROR 42000: Unknown database 'foo,bar'
SHOW WARNINGS;
@@ -39,6 +84,21 @@ Level Code Message
Error # Unknown database 'foo,bar'
BACKUP DATABASE foo,test,bar,foo TO 'test.bak';
ERROR 42000: Not unique database: 'foo'
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE test,foo,bdb,bar TO%";
+verify backup history and progress logs:
+SELECT backup_state,operation,backup_file FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+backup_state operation backup_file
+error backup test.bak
+SELECT notes FROM mysql.backup_progress
+WHERE backup_id=@bup_id;
+notes
+starting
+running
+Unknown database 'foo,bar'
+error
use adb;
create table t1 (a int);
create procedure p1() backup database test to 'test.bak';
@@ -69,24 +129,84 @@ ERROR HY000: Database 'mysql' cannot be
SHOW WARNINGS;
Level Code Message
Error # Database 'mysql' cannot be included in a backup
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE mysql TO%";
+verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+backup_state operation backup_file
+error backup t.bak
+SELECT notes FROM mysql.backup_progress
+WHERE backup_id=@bup_id;
+notes
+starting
+running
+Database 'mysql' cannot be included in a backup
+error
Backup of mysql, information_schema scenario 2
BACKUP DATABASE information_schema TO 't.bak';
ERROR HY000: Database 'information_schema' cannot be included in a backup
SHOW WARNINGS;
Level Code Message
Error # Database 'information_schema' cannot be included in a backup
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE information_schema TO%";
+verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+backup_state operation backup_file
+error backup t.bak
+SELECT notes FROM mysql.backup_progress
+WHERE backup_id=@bup_id;
+notes
+starting
+running
+Database 'information_schema' cannot be included in a backup
+error
Backup of mysql, information_schema scenario 3
BACKUP DATABASE mysql, information_schema TO 't.bak';
ERROR HY000: Database 'mysql' cannot be included in a backup
SHOW WARNINGS;
Level Code Message
Error # Database 'mysql' cannot be included in a backup
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE mysql, information_schema TO%";
+verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+backup_state operation backup_file
+error backup t.bak
+SELECT notes FROM mysql.backup_progress
+WHERE backup_id=@bup_id;
+notes
+starting
+running
+Database 'mysql' cannot be included in a backup
+error
Backup of mysql, information_schema scenario 4
BACKUP DATABASE mysql, test TO 't.bak';
ERROR HY000: Database 'mysql' cannot be included in a backup
SHOW WARNINGS;
Level Code Message
Error # Database 'mysql' cannot be included in a backup
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE mysql, test TO%";
+verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+backup_state operation backup_file
+error backup t.bak
+SELECT notes FROM mysql.backup_progress
+WHERE backup_id=@bup_id;
+notes
+starting
+running
+Database 'mysql' cannot be included in a backup
+error
Backup of mysql, information_schema scenario 5
BACKUP DATABASE information_schema, test TO 't.bak';
ERROR HY000: Database 'information_schema' cannot be included in a backup
@@ -99,6 +219,21 @@ ERROR HY000: Database 'mysql' cannot be
SHOW WARNINGS;
Level Code Message
Error # Database 'mysql' cannot be included in a backup
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE mysql, information_schema, test TO%";
+verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+backup_state operation backup_file
+error backup t.bak
+SELECT notes FROM mysql.backup_progress
+WHERE backup_id=@bup_id;
+notes
+starting
+running
+Database 'mysql' cannot be included in a backup
+error
Making copies of progress tables.
CREATE TABLE IF NOT EXISTS test.ob_copy LIKE mysql.backup_history;
CREATE TABLE IF NOT EXISTS test.obp_copy LIKE mysql.backup_progress;
@@ -166,6 +301,21 @@ trigger metadata
SET SESSION DEBUG='+d,backup_fail_add_trigger';
BACKUP DATABASE db1 TO 'bup_db1.bak';
ERROR HY000: Failed to obtain meta-data for trigger `db1`.`trg`
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE db1 TO%";
+verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+backup_state operation backup_file
+error backup bup_db1.bak
+SELECT notes FROM mysql.backup_progress
+WHERE backup_id=@bup_id;
+notes
+starting
+running
+Failed to obtain meta-data for trigger `db1`.`trg`
+error
SET DEBUG_SYNC= 'reset';
DROP DATABASE db1;
=== modified file 'mysql-test/suite/backup/r/backup_logs.result'
--- a/mysql-test/suite/backup/r/backup_logs.result 2008-11-17 09:57:51 +0000
+++ b/mysql-test/suite/backup/r/backup_logs.result 2008-12-22 21:14:06 +0000
@@ -32,11 +32,78 @@ Now starting real tests
DROP DATABASE IF EXISTS backup_logs;
PURGE BACKUP LOGS;
+Check backup logs when log_backup_output is TABLE and FILE
+SET @@global.log_backup_output = 'TABLE,FILE';
+CREATE USER 'tom'@'localhost' IDENTIFIED BY 'abc';
+GRANT ALL ON *.* TO 'tom'@'localhost' WITH GRANT OPTION;
+SHOW GRANTS FOR 'tom'@'localhost';
+Grants for tom@localhost
+GRANT ALL PRIVILEGES ON *.* TO 'tom'@'localhost' IDENTIFIED BY PASSWORD
'*0D3CED9BEC10A777AEC23CCC353A8C08A633045E' WITH GRANT OPTION
+SELECT user, host, password FROM mysql.user WHERE user='tom';
+user host password
+tom localhost *0D3CED9BEC10A777AEC23CCC353A8C08A633045E
+SELECT CURRENT_USER();
+CURRENT_USER()
+tom@localhost
CREATE DATABASE backup_logs;
-con1: Create table and new users.
+Perform backup
+BACKUP DATABASE backup_logs TO 'backup_logs1.bak'
+Get last backup_id
+SELECT MAX(backup_id) INTO @backup_id_history FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE backup_logs TO%";
+Verify the result
+LET =`SELECT @backup_id_history = 270 AS are_identical`
+
+Verification of backup_id from history table and command is:
+1
+We can notice that, if result is 1 then backup_id
+from backup_history log and from backup_command is same.
+con1: Activate sync points for the backup statement.
+SET DEBUG_SYNC= 'after_backup_log_init SIGNAL started WAIT_FOR do_run';
+SET DEBUG_SYNC= 'after_backup_start_backup SIGNAL running WAIT_FOR finish';
+Perform backup database operation with database alone.
+BACKUP DATABASE backup_logs TO 'backup_logs1.bak';
+con default: Wait for the backup to be started.
+SET DEBUG_SYNC= 'now WAIT_FOR started';
+Let backup step to running state.
+SET DEBUG_SYNC= 'now SIGNAL do_run WAIT_FOR running';
+con default: Let backup finish.
+SET DEBUG_SYNC= 'now SIGNAL finish';
+con1: Finish backup command
+backup_id
+#
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE backup_logs TO%";
+SELECT operation,num_objects, username, command FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+operation num_objects username command
+backup 0 tom BACKUP DATABASE backup_logs TO 'backup_logs1.bak'
+SELECT CURRENT_USER();
+CURRENT_USER()
+root@localhost
+Perform Backup and verify the username as 'root' in backup history log
+BACKUP DATABASE backup_logs TO 'backup_logs1.bak';
+backup_id
+#
+Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE backup_logs TO%";
+SELECT operation,num_objects, username, command FROM mysql.backup_history
+WHERE backup_id=@bup_id;
+operation num_objects username command
+backup 0 root BACKUP DATABASE backup_logs TO 'backup_logs1.bak'
+
+From the above tables we can notice that num_objects shows '0' if only DB
+is included in backup image(BUG#39109)
+
+Include all objects in database(Databases, tables, procedures and
+functions, views, triggers and events) and perform backup operation.
+con1: Create tables
CREATE TABLE backup_logs.t1 (a char(30)) ENGINE=MYISAM;
CREATE TABLE backup_logs.t2 (a char(30)) ENGINE=INNODB;
CREATE TABLE backup_logs.t3 (a char(30)) ENGINE=MEMORY;
+CREATE TABLE backup_logs.t4(id INT, name CHAR(20))ENGINE=BLACKHOLE;
INSERT INTO backup_logs.t1 VALUES ("01 Test #1 - progress");
INSERT INTO backup_logs.t1 VALUES ("02 Test #1 - progress");
INSERT INTO backup_logs.t1 VALUES ("03 Test #1 - progress");
@@ -54,6 +121,35 @@ INSERT INTO backup_logs.t3 VALUES ("01 T
INSERT INTO backup_logs.t3 VALUES ("02 Test #1 - progress");
INSERT INTO backup_logs.t3 VALUES ("03 Test #1 - progress");
INSERT INTO backup_logs.t3 VALUES ("04 Test #1 - progress");
+INSERT INTO backup_logs.t4 VALUES(1,'aa1'),(2,'aa2'),(3,'aa3');
+SELECT * FROM backup_logs.t4;
+id name
+create all objects like views, procedures, functions, triggers
+and events.
+** create view **
+CREATE VIEW backup_logs.v1 AS SELECT * FROM backup_logs.t1;
+CREATE VIEW backup_logs.vv AS SELECT * FROM backup_logs.v1;
+** create triggers **
+CREATE TRIGGER backup_logs.trg AFTER INSERT ON backup_logs.t1 FOR EACH ROW
+BEGIN
+INSERT INTO backup_logs.t3 VALUES('Test objects count');
+END;||
+** create procedures **
+CREATE PROCEDURE backup_logs.p1()
+BEGIN
+SELECT * FROM backup_logs.t1;
+END;
+||
+** create functions **
+CREATE FUNCTION backup_logs.f1() RETURNS INTEGER
+BEGIN
+RETURN (SELECT COUNT(*) FROM backup_logs.t1);
+END;
+||
+** create event **
+CREATE EVENT backup_logs.e1 ON SCHEDULE EVERY 1 YEAR DO
+DELETE FROM objects.t4 WHERE id=10;
+
Do backup of database
con2: Activate sync points for the backup statement.
SET DEBUG_SYNC= 'after_backup_log_init SIGNAL started WAIT_FOR do_run';
@@ -65,37 +161,47 @@ SET SESSION debug="+d,set_backup_id";
con2: Send backup command.
con2: Backup id = 500.
BACKUP DATABASE backup_logs to 'backup_logs_orig.bak';
+SET time_zone='+0:00';
+SELECT now() INTO @start_backup;
con1: Wait for the backup to be started.
SET DEBUG_SYNC= 'now WAIT_FOR started';
+
con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 500;
-notes
-starting
+backup progress tables will always show start_time, stop_time,total_bytes
+and progress as '0' for all phases of backup operation.
+BUG#39356 Backup progress table details aren't updated properly
+SELECT total_bytes, progress, notes FROM mysql.backup_progress
+WHERE backup_id = 500;
+total_bytes progress notes
+0 0 starting
con1: Let backup step to running state.
SET DEBUG_SYNC= 'now SIGNAL do_run WAIT_FOR phase1';
con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 500;
-notes
-starting
-running
+SELECT total_bytes, progress, notes FROM mysql.backup_progress
+WHERE backup_id = 500;
+total_bytes progress notes
+0 0 starting
+0 0 running
con1: Let backup do the backup phase1.
SET DEBUG_SYNC= 'now SIGNAL backup WAIT_FOR validated';
con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 500;
-notes
-starting
-running
-validity point
+SELECT total_bytes, progress, notes FROM mysql.backup_progress
+WHERE backup_id = 500;
+total_bytes progress notes
+0 0 starting
+0 0 running
+0 0 validity point
con1: Let backup do the backup phase2.
SET DEBUG_SYNC= 'now SIGNAL do_phase2 WAIT_FOR phase2';
con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 500;
-notes
-starting
-running
-validity point
-vp time
-running
+SELECT total_bytes, progress, notes FROM mysql.backup_progress
+WHERE backup_id = 500;
+total_bytes progress notes
+0 0 starting
+0 0 running
+0 0 validity point
+0 0 vp time
+0 0 running
con1: Let backup finish.
SET DEBUG_SYNC= 'now SIGNAL finish';
con2: Finish backup command
@@ -104,6 +210,42 @@ backup_id
FLUSH BACKUP LOGS;
Turn off debugging session.
SET SESSION debug="-d";
+SET time_zone='+0:00';
+SELECT now() INTO @stop_backup;
+We calculate the timedifference between backup start time and stop
+time. If this difference is '0', then backup start time and stop time
+are same.
+SELECT timediff(@stop_backup, @start_backup) > 5;
+timediff(@stop_backup, @start_backup) > 5
+0
+
+Now verify actual start time / stop time of backup and start time /
+stop time from backup_history table. If the both times are same,
+the timediff will be '0'
+
+SELECT timediff(start_time, @start_backup) > 0 from mysql.backup_history
+WHERE backup_id=500;
+timediff(start_time, @start_backup) > 0
+0
+SELECT timediff(stop_time, @stop_backup) > 0 from mysql.backup_history
+WHERE backup_id=500;
+timediff(stop_time, @stop_backup) > 0
+0
+Now verify that start_time <= vp_time <= stop_time
+SELECT timediff(validity_point_time, start_time) >= 0,
+timediff(stop_time, validity_point_time) >=0
+from mysql.backup_history WHERE backup_id=500;
+timediff(validity_point_time, start_time) >= 0 timediff(stop_time,
validity_point_time) >=0
+1 1
+
+From backup_history log we will notice that "drivers" column will show
+Myisam, snapshot, default and no-data drivers
+"error_num" will be '0' as both backup and restore was successful
+"num_objects" count is always 5(as there are 5 tables in database).
+It does not list other objects from the backup image(BUG#39109)
+SHOW VARIABLES LIKE 'log_backup_output';
+Variable_name Value
+log_backup_output FILE,TABLE
SELECT * FROM mysql.backup_history WHERE backup_id = 500;;
backup_id #
process_id #
@@ -112,18 +254,18 @@ binlog_file #
backup_state complete
operation backup
error_num 0
-num_objects 3
-total_bytes 3971
+num_objects 4
+total_bytes 5215
validity_point_time #
start_time #
stop_time #
host_or_server_name localhost
-username root
+username tom
backup_file #
backup_file_path #
user_comment
command BACKUP DATABASE backup_logs to 'backup_logs_orig.bak'
-drivers MyISAM, Snapshot, Default
+drivers MyISAM, Snapshot, Default, Nodata
SELECT * FROM mysql.backup_progress WHERE backup_id = 500;
backup_id object start_time stop_time total_bytes progress error_num notes
# backup kernel # # 0 0 0 starting
@@ -132,33 +274,47 @@ backup_id object start_time stop_time to
# backup kernel # # 0 0 0 vp time
# backup kernel # # 0 0 0 running
# backup kernel # # 0 0 0 complete
+File sizes are not identical
+
+The actual backup file size and from backup_history logs are different
+because of bug#37980. Once this bug is fixed, both should show
+same bytes.
con2: Activate sync points for the backup statement.
SET DEBUG_SYNC= 'after_backup_log_init SIGNAL started WAIT_FOR do_run';
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' OVERWRITE;
+SELECT now() INTO @start_restore;
con1: Wait for the restore to be started.
SET DEBUG_SYNC= 'now WAIT_FOR started';
con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 501;
-notes
-starting
+SELECT total_bytes, progress,notes FROM mysql.backup_progress
+WHERE backup_id = 501;
+total_bytes progress notes
+0 0 starting
con1: Let restore step to running state.
SET DEBUG_SYNC= 'now SIGNAL do_run WAIT_FOR running';
con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 501;
-notes
-starting
-running
+SELECT total_bytes, progress,notes FROM mysql.backup_progress
+WHERE backup_id = 501;
+total_bytes progress notes
+0 0 starting
+0 0 running
con1: Let restore do its job and finish.
SET DEBUG_SYNC= 'now SIGNAL finish';
con2: Finish restore command
backup_id
-501
+#
FLUSH BACKUP LOGS;
SET DEBUG_SYNC= 'now SIGNAL complete';
SET DEBUG_SYNC= 'now WAIT_FOR complete';
+We calculate the time difference between restore start time and stop
+time. If this difference is '0', then restore start time and stop time
+are same.
+SELECT timediff(now(),@start_restore) > 5;
+timediff(now(),@start_restore) > 5
+0
SELECT * FROM mysql.backup_history WHERE backup_id = 501;;
backup_id #
process_id #
@@ -167,18 +323,18 @@ binlog_file #
backup_state complete
operation restore
error_num 0
-num_objects 3
+num_objects 4
total_bytes 1483
validity_point_time #
start_time #
stop_time #
host_or_server_name localhost
-username root
+username tom
backup_file #
backup_file_path #
user_comment
command RESTORE FROM 'backup_logs_orig.bak' OVERWRITE
-drivers MyISAM, Snapshot, Default
+drivers MyISAM, Snapshot, Default, Nodata
SELECT * FROM mysql.backup_progress WHERE backup_id = 501;
backup_id object start_time stop_time total_bytes progress error_num notes
# backup kernel # # 0 0 0 starting
=== modified file 'mysql-test/suite/backup/t/backup_errors.test'
--- a/mysql-test/suite/backup/t/backup_errors.test 2008-12-15 12:18:24 +0000
+++ b/mysql-test/suite/backup/t/backup_errors.test 2008-12-22 21:14:06 +0000
@@ -3,9 +3,7 @@
--source include/have_debug_sync.inc
# Check that BACKUP/RESTORE commands correctly report errors
-#
-# TODO: When we know how to do that, check that the backup progress table
-# contains appropriate rows when errors have been detected.
+# and are updated in backup history and progress logs
--disable_warnings
DROP DATABASE IF EXISTS adb;
@@ -20,6 +18,16 @@ DROP DATABASE IF EXISTS bdb;
--error 29
RESTORE FROM 'test.bak';
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "RESTORE FROM 'test%";
+
+--echo verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+SELECT notes FROM mysql.backup_progress
+ WHERE backup_id=@bup_id;
+
CREATE DATABASE adb;
CREATE DATABASE bdb;
CREATE TABLE bdb.t1(a int) ENGINE=MEMORY;
@@ -30,6 +38,16 @@ BACKUP DATABASE adb TO '';
--replace_column 2 #
SHOW WARNINGS;
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE adb TO%";
+
+--echo verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+SELECT notes FROM mysql.backup_progress
+ WHERE backup_id=@bup_id;
+
# don't overwrite existing files
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
--replace_regex /Errcode: [0-9]+/Errcode: #/
@@ -43,7 +61,7 @@ SHOW WARNINGS;
--replace_column 1 #
BACKUP DATABASE adb TO "test.bak";
--replace_column 2 #
-# Reenable when bug#41468 has been fixed. There should not be warnings
+# Reenable when bug#41468 has been fixed. There should not be warnings
#SHOW WARNINGS;
# don't overwrite existing backup image
@@ -56,6 +74,16 @@ BACKUP DATABASE adb TO "test.bak";
--replace_regex /Errcode: [0-9]+/Errcode: #/
SHOW WARNINGS;
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE adb TO%";
+
+--echo verify backup history and progress logs for backup_state.
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+SELECT notes FROM mysql.backup_progress
+ WHERE backup_id=@bup_id;
+
--remove_file $MYSQLTEST_VARDIR/master-data/test.bak
# non-existent database
@@ -66,7 +94,9 @@ DROP DATABASE IF EXISTS bar;
-- error ER_BAD_DB_ERROR
BACKUP DATABASE foo TO 'test.bak';
+--replace_column 2 #
SHOW WARNINGS;
+
-- error ER_BAD_DB_ERROR
BACKUP DATABASE test,foo,bdb,bar TO 'test.bak';
--replace_column 2 #
@@ -76,6 +106,16 @@ SHOW WARNINGS;
-- error ER_NONUNIQ_DB
BACKUP DATABASE foo,test,bar,foo TO 'test.bak';
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE test,foo,bdb,bar TO%";
+
+--echo verify backup history and progress logs:
+SELECT backup_state,operation,backup_file FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+SELECT notes FROM mysql.backup_progress
+ WHERE backup_id=@bup_id;
+
# Test that BACKUP/RESTORE statements are disable inside stored routines,
# triggers and events.
@@ -142,6 +182,16 @@ BACKUP DATABASE mysql TO 't.bak';
--replace_column 2 #
SHOW WARNINGS;
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE mysql TO%";
+
+--echo verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+SELECT notes FROM mysql.backup_progress
+ WHERE backup_id=@bup_id;
+
--error 0, 1
--remove_file $MYSQLTEST_VARDIR/master-data/t.bak
@@ -152,6 +202,16 @@ BACKUP DATABASE information_schema TO 't
--replace_column 2 #
SHOW WARNINGS;
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE information_schema TO%";
+
+--echo verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+SELECT notes FROM mysql.backup_progress
+ WHERE backup_id=@bup_id;
+
--error 0, 1
--remove_file $MYSQLTEST_VARDIR/master-data/t.bak
@@ -162,6 +222,16 @@ BACKUP DATABASE mysql, information_schem
--replace_column 2 #
SHOW WARNINGS;
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE mysql, information_schema TO%";
+
+--echo verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+SELECT notes FROM mysql.backup_progress
+ WHERE backup_id=@bup_id;
+
--error 0, 1
--remove_file $MYSQLTEST_VARDIR/master-data/t.bak
@@ -172,6 +242,16 @@ BACKUP DATABASE mysql, test TO 't.bak';
--replace_column 2 #
SHOW WARNINGS;
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE mysql, test TO%";
+
+--echo verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+SELECT notes FROM mysql.backup_progress
+ WHERE backup_id=@bup_id;
+
--error 0, 1
--remove_file $MYSQLTEST_VARDIR/master-data/t.bak
@@ -192,6 +272,16 @@ BACKUP DATABASE mysql, information_schem
--replace_column 2 #
SHOW WARNINGS;
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE mysql, information_schema, test TO%";
+
+--echo verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+SELECT notes FROM mysql.backup_progress
+ WHERE backup_id=@bup_id;
+
--error 0, 1
--remove_file $MYSQLTEST_VARDIR/master-data/t.bak
#
@@ -238,6 +328,7 @@ DROP TABLE mysql.backup_progress;
--echo Backup the database;
--error ER_BACKUP_PROGRESS_TABLES
BACKUP DATABASE test_ob_error TO 'ob_err.bak';
+
--error 0,1
--remove_file $MYSQLTEST_VARDIR/master-data/ob_err.bak
--replace_column 2 #
@@ -250,7 +341,6 @@ DROP TABLE test.obp_copy;
DROP DATABASE test_ob_error;
-
--echo
--echo Bug#38624
--echo Test that backup fails with error if database files are removed
@@ -323,14 +413,23 @@ SET SESSION DEBUG='+d,backup_fail_add_tr
--error ER_BACKUP_GET_META_TRIGGER
BACKUP DATABASE db1 TO 'bup_db1.bak';
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE db1 TO%";
+
+--echo verify backup history and progress logs:
+SELECT backup_state,operation, backup_file FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+SELECT notes FROM mysql.backup_progress
+ WHERE backup_id=@bup_id;
+
SET DEBUG_SYNC= 'reset';
DROP DATABASE db1;
--echo
--echo Done testing for Bug#38624
-
---echo
+--echo
--echo Testing RESTORE ... OVERWRITE functionality
--echo See bug#34579
--echo
@@ -343,38 +442,37 @@ USE db1;
CREATE TABLE table1 (text VARCHAR(20));
INSERT INTO table1 VALUES ('Inserted before');
---echo
+--echo
--echo Backup database
--replace_column 1 #
BACKUP DATABASE db1 TO 'overwrite.bak';
---echo
+--echo
--echo Insert more data and display
INSERT INTO table1 VALUES ('Inserted after');
SELECT * FROM table1;
---echo
+--echo
--echo Restore without OVERWRITE flag; will fail
--error ER_RESTORE_DB_EXISTS
RESTORE FROM 'overwrite.bak';
---echo
+--echo
--echo Restore with OVERWRITE flag; will succeed
--replace_column 1 #
RESTORE FROM 'overwrite.bak' OVERWRITE;
---echo
+--echo
--echo Show that inserted value 2 is not there
SELECT * FROM table1;
DROP DATABASE db1;
---echo
+--echo
--echo Restore after deleting db; will succeed
--replace_column 1 #
RESTORE FROM 'overwrite.bak';
-
---echo
+--echo
--echo Show that inserted value 2 is not there
SELECT * FROM table1;
@@ -395,5 +493,5 @@ BACKUP DATABASE db1 TO 'overwrite1.bak';
SET SESSION DEBUG='-d';
--echo
-
DROP DATABASE db1;
+
=== modified file 'mysql-test/suite/backup/t/backup_logs.test'
--- a/mysql-test/suite/backup/t/backup_logs.test 2008-11-17 09:57:51 +0000
+++ b/mysql-test/suite/backup/t/backup_logs.test 2008-12-22 21:14:06 +0000
@@ -1,5 +1,5 @@
#
-# This test includes tests for ensuring the backup progress tables
+# This test includes tests for ensuring the backup progress and history tables
# are updated.
#
@@ -8,6 +8,7 @@
--source include/have_innodb.inc
--source include/not_embedded.inc
--source include/have_debug.inc
+--source include/blackhole.inc
SET DEBUG_SYNC= 'RESET';
@@ -46,22 +47,120 @@ DROP DATABASE IF EXISTS backup_logs;
PURGE BACKUP LOGS;
-connect (con1,localhost,root,,);
-connect (con2,localhost,root,,);
+--echo Check backup logs when log_backup_output is TABLE and FILE
+SET @@global.log_backup_output = 'TABLE,FILE';
+
+#Create users and assign privileges
+CREATE USER 'tom'@'localhost' IDENTIFIED BY 'abc';
+GRANT ALL ON *.* TO 'tom'@'localhost' WITH GRANT OPTION;
+
+#Checking the grant privileges
+SHOW GRANTS FOR 'tom'@'localhost';
+SELECT user, host, password FROM mysql.user WHERE user='tom';
+
+# Verify different username entry in backup_history logs.
+
+connect (con1,localhost,tom,abc);
+connect (con2,localhost,tom,abc);
+connect (con3,localhost,root,);
+
+connection con1;
+SELECT CURRENT_USER();
+CREATE DATABASE backup_logs;
+
+# Test 1: Verifying backupid
+
+--echo Perform backup
+--echo BACKUP DATABASE backup_logs TO 'backup_logs1.bak'
+
+Let $backup_id=`BACKUP DATABASE backup_logs TO 'backup_logs1.bak'`;
+
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @backup_id_history FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE backup_logs TO%";
+
+--echo Verify the result
+--echo LET $result=`SELECT @backup_id_history = $backup_id AS are_identical`
+LET $result=`SELECT @backup_id_history = $backup_id AS are_identical`;
+
+--echo
+--echo Verification of backup_id from history table and command is:
+--echo $result
+
+--echo We can notice that, if result is 1 then backup_id
+--echo from backup_history log and from backup_command is same.
+--remove_file $MYSQLTEST_VARDIR/master-data/backup_logs1.bak
#
-# Test 1 - Check output of backup.
+# Test 2 - Check output of backup and verify different columns in
+# backup history and progress logs.
#
+--echo con1: Activate sync points for the backup statement.
+SET DEBUG_SYNC= 'after_backup_log_init SIGNAL started WAIT_FOR do_run';
+SET DEBUG_SYNC= 'after_backup_start_backup SIGNAL running WAIT_FOR finish';
+
+--echo Perform backup database operation with database alone.
+send BACKUP DATABASE backup_logs TO 'backup_logs1.bak';
+
+connection default;
+
+--echo con default: Wait for the backup to be started.
+SET DEBUG_SYNC= 'now WAIT_FOR started';
+--echo Let backup step to running state.
+SET DEBUG_SYNC= 'now SIGNAL do_run WAIT_FOR running';
+
+--echo con default: Let backup finish.
+SET DEBUG_SYNC= 'now SIGNAL finish';
+
connection con1;
+--echo con1: Finish backup command
+--replace_column 1 #
+reap;
-CREATE DATABASE backup_logs;
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE backup_logs TO%";
+SELECT operation,num_objects, username, command FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+--remove_file $MYSQLTEST_VARDIR/master-data/backup_logs1.bak
+
+connection con3;
+SELECT CURRENT_USER();
+--echo Perform Backup and verify the username as 'root' in backup history log
+--replace_column 1 #
+BACKUP DATABASE backup_logs TO 'backup_logs1.bak';
+
+--echo Get last backup_id
+SELECT MAX(backup_id) INTO @bup_id FROM mysql.backup_history
+WHERE command LIKE "BACKUP DATABASE backup_logs TO%";
+SELECT operation,num_objects, username, command FROM mysql.backup_history
+ WHERE backup_id=@bup_id;
+--remove_file $MYSQLTEST_VARDIR/master-data/backup_logs1.bak
+
+--echo
+--echo From the above tables we can notice that num_objects shows '0' if only DB
+--echo is included in backup image(BUG#39109)
+--echo
+
+# BUG#39109: Mysql Online Backup table doesn't show correct num_object count
+# Once BUG#39109 is fixed, all the objects should be listed in the num_object
+# count of backup_history log
---echo con1: Create table and new users.
+--echo Include all objects in database(Databases, tables, procedures and
+--echo functions, views, triggers and events) and perform backup operation.
+
+connection con1;
+--echo con1: Create tables
+
+# Tables are created using Myisam(Native driver), Innodb(Consistent Snapshot
+# driver), Memory(Default driver) and Blackhole(no-data driver). Ensure that
+# drivers column indicates all types of drivers for backup database operation.
CREATE TABLE backup_logs.t1 (a char(30)) ENGINE=MYISAM;
CREATE TABLE backup_logs.t2 (a char(30)) ENGINE=INNODB;
CREATE TABLE backup_logs.t3 (a char(30)) ENGINE=MEMORY;
+CREATE TABLE backup_logs.t4(id INT, name CHAR(20))ENGINE=BLACKHOLE;
INSERT INTO backup_logs.t1 VALUES ("01 Test #1 - progress");
INSERT INTO backup_logs.t1 VALUES ("02 Test #1 - progress");
@@ -83,6 +182,43 @@ INSERT INTO backup_logs.t3 VALUES ("02 T
INSERT INTO backup_logs.t3 VALUES ("03 Test #1 - progress");
INSERT INTO backup_logs.t3 VALUES ("04 Test #1 - progress");
+INSERT INTO backup_logs.t4 VALUES(1,'aa1'),(2,'aa2'),(3,'aa3');
+SELECT * FROM backup_logs.t4;
+
+--echo create all objects like views, procedures, functions, triggers
+--echo and events.
+
+--echo ** create view **
+CREATE VIEW backup_logs.v1 AS SELECT * FROM backup_logs.t1;
+CREATE VIEW backup_logs.vv AS SELECT * FROM backup_logs.v1;
+
+--echo ** create triggers **
+delimiter ||;
+CREATE TRIGGER backup_logs.trg AFTER INSERT ON backup_logs.t1 FOR EACH ROW
+BEGIN
+ INSERT INTO backup_logs.t3 VALUES('Test objects count');
+END;||
+
+--echo ** create procedures **
+CREATE PROCEDURE backup_logs.p1()
+BEGIN
+ SELECT * FROM backup_logs.t1;
+END;
+||
+
+--echo ** create functions **
+CREATE FUNCTION backup_logs.f1() RETURNS INTEGER
+BEGIN
+RETURN (SELECT COUNT(*) FROM backup_logs.t1);
+END;
+||
+delimiter ;||
+
+--echo ** create event **
+CREATE EVENT backup_logs.e1 ON SCHEDULE EVERY 1 YEAR DO
+ DELETE FROM objects.t4 WHERE id=10;
+
+--echo
--echo Do backup of database
connection con2;
@@ -102,29 +238,47 @@ send BACKUP DATABASE backup_logs to 'bac
connection con1;
+# Record the time when BACKUP has started.
+# Set the time_zone to +0:00 to have same server timezone as of
+# backup history table.
+
+SET time_zone='+0:00';
+SELECT now() INTO @start_backup;
+
--echo con1: Wait for the backup to be started.
SET DEBUG_SYNC= 'now WAIT_FOR started';
+--echo
--echo con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 500;
+--echo backup progress tables will always show start_time, stop_time,total_bytes
+--echo and progress as '0' for all phases of backup operation.
+--echo BUG#39356 Backup progress table details aren't updated properly
+# Correct backup/restore times and progress should be indicated in the backup
+# logs once this bug is fixed
+
+SELECT total_bytes, progress, notes FROM mysql.backup_progress
+ WHERE backup_id = 500;
--echo con1: Let backup step to running state.
SET DEBUG_SYNC= 'now SIGNAL do_run WAIT_FOR phase1';
--echo con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 500;
+SELECT total_bytes, progress, notes FROM mysql.backup_progress
+ WHERE backup_id = 500;
--echo con1: Let backup do the backup phase1.
SET DEBUG_SYNC= 'now SIGNAL backup WAIT_FOR validated';
--echo con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 500;
+SELECT total_bytes, progress, notes FROM mysql.backup_progress
+ WHERE backup_id = 500;
--echo con1: Let backup do the backup phase2.
SET DEBUG_SYNC= 'now SIGNAL do_phase2 WAIT_FOR phase2';
--echo con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 500;
+SELECT total_bytes, progress, notes FROM mysql.backup_progress
+ WHERE backup_id = 500;
--echo con1: Let backup finish.
SET DEBUG_SYNC= 'now SIGNAL finish';
@@ -140,12 +294,79 @@ SET SESSION debug="-d";
connection con1;
+SET time_zone='+0:00';
+SELECT now() INTO @stop_backup;
+
+--echo We calculate the timedifference between backup start time and stop
+--echo time. If this difference is '0', then backup start time and stop time
+--echo are same.
+
+SELECT timediff(@stop_backup, @start_backup) > 5;
+
+--echo
+--echo Now verify actual start time / stop time of backup and start time /
+--echo stop time from backup_history table. If the both times are same,
+--echo the timediff will be '0'
+--echo
+
+SELECT timediff(start_time, @start_backup) > 0 from mysql.backup_history
+WHERE backup_id=500;
+
+SELECT timediff(stop_time, @stop_backup) > 0 from mysql.backup_history
+WHERE backup_id=500;
+
+--echo Now verify that start_time <= vp_time <= stop_time
+
+SELECT timediff(validity_point_time, start_time) >= 0,
+timediff(stop_time, validity_point_time) >=0
+from mysql.backup_history WHERE backup_id=500;
+
+--echo
+--echo From backup_history log we will notice that "drivers" column will show
+--echo Myisam, snapshot, default and no-data drivers
+--echo "error_num" will be '0' as both backup and restore was successful
+--echo "num_objects" count is always 5(as there are 5 tables in database).
+--echo It does not list other objects from the backup image(BUG#39109)
+
#Show results
+
+SHOW VARIABLES LIKE 'log_backup_output';
--replace_column 1 # 2 # 3 # 4 # 10 # 11 # 12 # 15 # 16 #
--query_vertical SELECT * FROM mysql.backup_history WHERE backup_id = 500;
--replace_column 1 # 3 # 4 #
SELECT * FROM mysql.backup_progress WHERE backup_id = 500;
+# Check the backup file size and compare it from backup_history
+# logs. Note that total_bytes in backup_progress is always
+# '0' and backup_history shows different file size because of bug#37980
+
+LET FILE_SIZE_HISTORY = `SELECT total_bytes FROM mysql.backup_history WHERE
backup_id = 500`;
+
+perl;
+my $filename = "var/master-data/backup_logs_orig.bak";
+my $filesize = -s $filename;
+
+if ($filesize ne $ENV{FILE_SIZE_HISTORY})
+{
+print "File sizes are not identical\n";
+}
+else
+{
+print "File sizes are identical\n";
+}
+EOF
+
+--echo
+--echo The actual backup file size and from backup_history logs are different
+--echo because of bug#37980. Once this bug is fixed, both should show
+--echo same bytes.
+
+--file_exists $MYSQLTEST_VARDIR/master-data/backup_history.log
+--file_exists $MYSQLTEST_VARDIR/master-data/backup_progress.log
+
+#cat_file $MYSQLTEST_VARDIR/master-data/backup_history.log;
+#cat_file $MYSQLTEST_VARDIR/master-data/backup_progress.log;
+
connection con2;
--echo con2: Activate sync points for the backup statement.
@@ -158,23 +379,29 @@ send RESTORE FROM 'backup_logs_orig.bak'
connection con1;
+# Record the time when RESTORE has started.
+SELECT now() INTO @start_restore;
+
--echo con1: Wait for the restore to be started.
SET DEBUG_SYNC= 'now WAIT_FOR started';
--echo con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 501;
+SELECT total_bytes, progress,notes FROM mysql.backup_progress
+ WHERE backup_id = 501;
--echo con1: Let restore step to running state.
SET DEBUG_SYNC= 'now SIGNAL do_run WAIT_FOR running';
--echo con1: Display progress
-SELECT notes FROM mysql.backup_progress WHERE backup_id = 501;
+SELECT total_bytes, progress,notes FROM mysql.backup_progress
+ WHERE backup_id = 501;
--echo con1: Let restore do its job and finish.
SET DEBUG_SYNC= 'now SIGNAL finish';
connection con2;
--echo con2: Finish restore command
+--replace_column 1 #
reap;
FLUSH BACKUP LOGS;
@@ -185,12 +412,27 @@ connection con1;
SET DEBUG_SYNC= 'now WAIT_FOR complete';
+--echo We calculate the time difference between restore start time and stop
+--echo time. If this difference is '0', then restore start time and stop time
+--echo are same.
+
+SELECT timediff(now(),@start_restore) > 5;
+
#Show results
--replace_column 1 # 2 # 3 # 4 # 10 # 11 # 12 # 15 # 16 #
--query_vertical SELECT * FROM mysql.backup_history WHERE backup_id = 501;
+
+# Correct backup/restore times and progress should be indicated in the backup
+# logs once this bug 39356 is fixed
+
--replace_column 1 # 3 # 4 #
SELECT * FROM mysql.backup_progress WHERE backup_id = 501;
+--file_exists $MYSQLTEST_VARDIR/master-data/backup_history.log
+--file_exists $MYSQLTEST_VARDIR/master-data/backup_progress.log
+#cat_file $MYSQLTEST_VARDIR/master-data/backup_history.log;
+#cat_file $MYSQLTEST_VARDIR/master-data/backup_progress.log;
+
SET DEBUG_SYNC= 'RESET';
--remove_file $MYSQLTEST_VARDIR/master-data/backup_logs_orig.bak