--source include/not_embedded.inc disable_query_log; call mtr.add_suppression("Backup:"); call mtr.add_suppression("Restore:"); enable_query_log; connect (root_user,localhost,root,,); --disable_warnings DROP DATABASE IF EXISTS backup_test; --enable_warnings # # Test 1 - Only users with BACKUP and RESTORE privilege can run backup # and restore. # --echo # --echo # Create database and data to test. --echo # Create 2 users and grants rights as follows: --echo # bup_no_rights - denied everything (poor chap) --echo # bup_with_rights - super user account (like root) --echo # CREATE DATABASE backup_test; CREATE TABLE backup_test.t1 (a char(30)) ENGINE=MEMORY; INSERT INTO backup_test.t1 VALUES ("01 Test #1 - privilege"); INSERT INTO backup_test.t1 VALUES ("02 Test #1 - privilege"); INSERT INTO backup_test.t1 VALUES ("03 Test #1 - privilege"); INSERT INTO backup_test.t1 VALUES ("04 Test #1 - privilege"); INSERT INTO backup_test.t1 VALUES ("05 Test #1 - privilege"); INSERT INTO backup_test.t1 VALUES ("06 Test #1 - privilege"); INSERT INTO backup_test.t1 VALUES ("07 Test #1 - privilege"); CREATE TABLE backup_test.t2 (a char(30)) ENGINE=MEMORY; INSERT INTO backup_test.t2 VALUES ("01 Test #2 - privilege"); INSERT INTO backup_test.t2 VALUES ("02 Test #2 - privilege"); INSERT INTO backup_test.t2 VALUES ("03 Test #2 - privilege"); INSERT INTO backup_test.t2 VALUES ("04 Test #2 - privilege"); INSERT INTO backup_test.t2 VALUES ("05 Test #2 - privilege"); INSERT INTO backup_test.t2 VALUES ("06 Test #2 - privilege"); INSERT INTO backup_test.t2 VALUES ("07 Test #2 - privilege"); --echo # --echo # Now create more database objects for test. --echo # CREATE PROCEDURE backup_test.p1(p1 CHAR(20)) INSERT INTO backup_test.t1 VALUES ("50"); CREATE TRIGGER backup_test.trg AFTER INSERT ON backup_test.t1 FOR EACH ROW INSERT INTO backup_test.t1 VALUES('Test objects count'); CREATE FUNCTION backup_test.f1() RETURNS INT RETURN (SELECT 1); CREATE VIEW backup_test.v1 as SELECT * FROM backup_test.t1; CREATE EVENT backup_test.e1 ON SCHEDULE EVERY 1 YEAR DO DELETE FROM backup_test.t1 WHERE a = "not there"; CREATE USER 'bup_some_rights'@'localhost'; CREATE USER 'bup_with_rights'@'localhost'; REVOKE ALL ON *.* FROM 'bup_some_rights'@'localhost'; REVOKE ALL ON *.* FROM 'bup_with_rights'@'localhost'; GRANT SELECT ON backup_test.t1 TO 'bup_some_rights'@'localhost'; GRANT BACKUP ON backup_test.* TO 'bup_some_rights'@'localhost'; GRANT ALL ON *.* TO 'bup_with_rights'@'localhost'; GRANT SELECT ON mysql.* TO 'bup_some_rights'@'localhost'; FLUSH PRIVILEGES; --replace_column 1 # BACKUP DATABASE backup_test to 'orig.bak'; SHOW FULL TABLES FROM backup_test; SELECT event_name FROM INFORMATION_SCHEMA.EVENTS WHERE event_schema = 'backup_test'; SELECT routine_name FROM INFORMATION_SCHEMA.ROUTINES WHERE routine_schema = 'backup_test'; SELECT trigger_name FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'backup_test'; # # Now connect with bup_with_rights # disconnect root_user; connect (with_rights,localhost,bup_with_rights,,); --replace_column 1 # BACKUP DATABASE backup_test to 'bup_with_rights.bak'; # # Now connect with bup_some_rights # disconnect with_rights; connect (some_rights,localhost,bup_some_rights,,); --replace_column 1 # BACKUP DATABASE backup_test to 'bup_some_rights.bak'; # # Now connect root. # disconnect some_rights; connect (root_user,localhost,root,,); --replace_column 1 # RESTORE FROM 'orig.bak' OVERWRITE; SHOW FULL TABLES FROM backup_test; SELECT event_name FROM INFORMATION_SCHEMA.EVENTS WHERE event_schema = 'backup_test'; SELECT routine_name FROM INFORMATION_SCHEMA.ROUTINES WHERE routine_schema = 'backup_test'; SELECT trigger_name FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'backup_test'; --replace_column 1 # RESTORE FROM 'bup_with_rights.bak' OVERWRITE; SHOW FULL TABLES FROM backup_test; SELECT event_name FROM INFORMATION_SCHEMA.EVENTS WHERE event_schema = 'backup_test'; SELECT routine_name FROM INFORMATION_SCHEMA.ROUTINES WHERE routine_schema = 'backup_test'; SELECT trigger_name FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'backup_test'; --replace_column 1 # RESTORE FROM 'bup_some_rights.bak' OVERWRITE; SHOW FULL TABLES FROM backup_test; SELECT event_name FROM INFORMATION_SCHEMA.EVENTS WHERE event_schema = 'backup_test'; SELECT routine_name FROM INFORMATION_SCHEMA.ROUTINES WHERE routine_schema = 'backup_test'; SELECT trigger_name FROM INFORMATION_SCHEMA.TRIGGERS WHERE trigger_schema = 'backup_test'; DROP USER 'bup_some_rights'@'localhost'; DROP USER 'bup_with_rights'@'localhost'; DROP DATABASE backup_test; FLUSH PRIVILEGES; let $MYSQLD_BACKUPDIR= `select @@backupdir`; remove_file $MYSQLD_BACKUPDIR/bup_with_rights.bak; remove_file $MYSQLD_BACKUPDIR/bup_some_rights.bak; remove_file $MYSQLD_BACKUPDIR/orig.bak;