#At file:///home/frazer/bzr/mysql-5.1-telco-6.4/
3244 Frazer Clement 2009-01-30 [merge]
Merge 6.3->6.4
modified:
mysql-test/suite/ndb/r/ndb_restore.result
mysql-test/suite/ndb/t/ndb_restore.test
storage/ndb/include/util/BaseString.hpp
storage/ndb/src/common/util/BaseString.cpp
storage/ndb/tools/restore/restore_main.cpp
=== modified file 'mysql-test/suite/ndb/r/ndb_restore.result'
--- a/mysql-test/suite/ndb/r/ndb_restore.result 2008-07-24 10:57:58 +0000
+++ b/mysql-test/suite/ndb/r/ndb_restore.result 2009-01-30 15:08:46 +0000
@@ -607,3 +607,294 @@ epoch
select epoch > (1 << 32) from mysql.ndb_apply_status where server_id=0;
epoch > (1 << 32)
1
+*************************************
+Creating various databases and tables
+*************************************
+create database db1;
+create database db2;
+use db1;
+create table tab1 (a int primary key) engine=ndb;
+create table tab2 (a int primary key,
+b varchar(20),
+c int,
+d text,
+unique(c)) engine=ndb;
+insert into tab1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(0);
+insert into tab2 values (1, "Donnington", 1, repeat("O", 1000)),
+(2, "Basingstoke", 2, repeat("P", 1000)),
+(3, "George", 3, repeat("Q", 1000)),
+(4, "Spottiswoode", 4, repeat("R", 1000)),
+(5, "Sciennes", 5, repeat("S", 1000)),
+(6, "Cairns", 6, repeat("T", 1000)),
+(7, "Highlea", 7, repeat("U", 1000));
+checksum table tab1;
+Table Checksum
+db1.tab1 994088853
+checksum table tab2;
+Table Checksum
+db1.tab2 1516475923
+use db2;
+create table tab1 (a int primary key) engine=ndb;
+create table tab2 (a int primary key, b varchar(20), c int, unique(c), d text) engine=ndb;
+insert into tab1 select * from db1.tab1;
+insert into tab2 select * from db1.tab2;
+checksum table tab1;
+Table Checksum
+db2.tab1 994088853
+checksum table tab2;
+Table Checksum
+db2.tab2 1516475923
+***********************
+Backing up created data
+***********************
+CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP;
+DELETE FROM test.backup_info;
+LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ',';
+SELECT @the_backup_id:=backup_id FROM test.backup_info;
+@the_backup_id:=backup_id
+<the_backup_id>
+DROP TABLE test.backup_info;
+drop table db1.tab1, db1.tab2, db2.tab1, db2.tab2;
+**************************************
+Check various include/exclude variants
+**************************************
+Normal full restore
+use db1;
+show tables;
+Tables_in_db1
+tab2
+tab1
+checksum table tab1, tab2;
+Table Checksum
+db1.tab1 994088853
+db1.tab2 1516475923
+use db2;
+show tables;
+Tables_in_db2
+tab2
+tab1
+checksum table tab1, tab2;
+Table Checksum
+db2.tab1 994088853
+db2.tab2 1516475923
+drop table db1.tab1, db1.tab2, db2.tab1, db2.tab2;
+****************
+Include only db2
+****************
+use db1;
+show tables;
+Tables_in_db1
+use db2;
+show tables;
+Tables_in_db2
+tab2
+tab1
+checksum table tab1, tab2;
+Table Checksum
+db2.tab1 994088853
+db2.tab2 1516475923
+drop table db2.tab1, db2.tab2;
+****************
+Exclude only db2
+****************
+use db1;
+show tables;
+Tables_in_db1
+tab2
+tab1
+checksum table tab1, tab2;
+Table Checksum
+db1.tab1 994088853
+db1.tab2 1516475923
+use db2;
+show tables;
+Tables_in_db2
+drop table db1.tab1, db1.tab2;
+************
+Exclude both
+************
+use db1;
+show tables;
+Tables_in_db1
+use db2;
+show tables;
+Tables_in_db2
+**********************************
+Include only db1.tab1 and db2.tab2
+**********************************
+use db1;
+show tables;
+Tables_in_db1
+tab1
+checksum table tab1;
+Table Checksum
+db1.tab1 994088853
+use db2;
+show tables;
+Tables_in_db2
+tab2
+checksum table tab2;
+Table Checksum
+db2.tab2 1516475923
+drop table db1.tab1, db2.tab2;
+*****************************
+Exclude db1.tab1 and db2.tab2
+*****************************
+Should result in db1.tab2 and db2.tab1 being restored
+use db1;
+show tables;
+Tables_in_db1
+tab2
+checksum table tab2;
+Table Checksum
+db1.tab2 1516475923
+use db2;
+show tables;
+Tables_in_db2
+tab1
+checksum table tab1;
+Table Checksum
+db2.tab1 994088853
+drop table db1.tab2, db2.tab1;
+*********************************
+Include db1.tab1, but exclude db1
+*********************************
+Should result in only db1.tab1 being restored
+use db1;
+show tables;
+Tables_in_db1
+tab1
+checksum table tab1;
+Table Checksum
+db1.tab1 994088853
+use db2;
+show tables;
+Tables_in_db2
+drop table db1.tab1;
+*********************************
+Exclude db1.tab1, but include db1
+*********************************
+Should result in only db1.tab2 being restored
+use db1;
+show tables;
+Tables_in_db1
+tab2
+checksum table tab2;
+Table Checksum
+db1.tab2 1516475923
+use db2;
+show tables;
+Tables_in_db2
+drop table db1.tab2;
+**************************************
+Exclude db1.tab1, and include db1.tab1
+**************************************
+Should result in db1.tab1 only restored.
+use db1;
+show tables;
+Tables_in_db1
+tab1
+checksum table tab1;
+Table Checksum
+db1.tab1 994088853
+use db2;
+show tables;
+Tables_in_db2
+drop table db1.tab1;
+****************************
+Exclude db2, and include db2
+****************************
+Should result in db2 only restored.
+use db1;
+show tables;
+Tables_in_db1
+use db2;
+show tables;
+Tables_in_db2
+tab2
+tab1
+checksum table tab1, tab2;
+Table Checksum
+db2.tab1 994088853
+db2.tab2 1516475923
+drop table db2.tab1, db2.tab2;
+*********************************
+Include db1, and include db2.tab1
+*********************************
+Should result in db2.tab1 only restored.
+use db1;
+show tables;
+Tables_in_db1
+use db2;
+show tables;
+Tables_in_db2
+tab1
+checksum table tab1;
+Table Checksum
+db2.tab1 994088853
+drop table db2.tab1;
+************************
+Include unknown database
+************************
+Should result in nothing restored
+show databases;
+Database
+information_schema
+db1
+db2
+mysql
+test
+use db1;
+show tables;
+Tables_in_db1
+use db2;
+show tables;
+Tables_in_db2
+*********************
+Exclude unknown table
+*********************
+Should result in everything restored
+show databases;
+Database
+information_schema
+db1
+db2
+mysql
+test
+use db1;
+show tables;
+Tables_in_db1
+tab2
+tab1
+checksum table tab1, tab2;
+Table Checksum
+db1.tab1 994088853
+db1.tab2 1516475923
+use db2;
+show tables;
+Tables_in_db2
+tab2
+tab1
+checksum table tab1, tab2;
+Table Checksum
+db2.tab1 994088853
+db2.tab2 1516475923
+drop table db1.tab1, db1.tab2;
+drop table db2.tab1, db2.tab2;
+*********************************************
+Check that last argument of each type is used
+*********************************************
+Should result in just db1.tab2 restored.
+use db1;
+show tables;
+Tables_in_db1
+tab2
+checksum table tab2;
+Table Checksum
+db1.tab2 1516475923
+use db2;
+show tables;
+Tables_in_db2
+drop table db1.tab2;
+drop database db1;
+drop database db2;
=== modified file 'mysql-test/suite/ndb/t/ndb_restore.test'
--- a/mysql-test/suite/ndb/t/ndb_restore.test 2008-10-22 10:12:53 +0000
+++ b/mysql-test/suite/ndb/t/ndb_restore.test 2009-01-30 15:35:05 +0000
@@ -484,3 +484,285 @@ select epoch from mysql.ndb_apply_status
--exec $NDB_RESTORE --no-defaults --core=0 -e -b $the_backup_id -n 1 $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
# should evaluate to true == 1
select epoch > (1 << 32) from mysql.ndb_apply_status where server_id=0;
+
+
+# Bug#40429 Ignore tables when restoring
+
+--echo *************************************
+--echo Creating various databases and tables
+--echo *************************************
+create database db1;
+create database db2;
+
+use db1;
+create table tab1 (a int primary key) engine=ndb;
+create table tab2 (a int primary key,
+ b varchar(20),
+ c int,
+ d text,
+ unique(c)) engine=ndb;
+insert into tab1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(0);
+insert into tab2 values (1, "Donnington", 1, repeat("O", 1000)),
+(2, "Basingstoke", 2, repeat("P", 1000)),
+(3, "George", 3, repeat("Q", 1000)),
+(4, "Spottiswoode", 4, repeat("R", 1000)),
+(5, "Sciennes", 5, repeat("S", 1000)),
+(6, "Cairns", 6, repeat("T", 1000)),
+(7, "Highlea", 7, repeat("U", 1000));
+
+checksum table tab1;
+checksum table tab2;
+
+use db2;
+
+create table tab1 (a int primary key) engine=ndb;
+create table tab2 (a int primary key, b varchar(20), c int, unique(c), d text) engine=ndb;
+
+insert into tab1 select * from db1.tab1;
+insert into tab2 select * from db1.tab2;
+
+checksum table tab1;
+checksum table tab2;
+
+--echo ***********************
+--echo Backing up created data
+--echo ***********************
+--source include/ndb_backup.inc
+
+drop table db1.tab1, db1.tab2, db2.tab1, db2.tab2;
+
+--echo **************************************
+--echo Check various include/exclude variants
+--echo **************************************
+--echo Normal full restore
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
+
+use db1;
+show tables;
+checksum table tab1, tab2;
+
+use db2;
+show tables;
+checksum table tab1, tab2;
+
+drop table db1.tab1, db1.tab2, db2.tab1, db2.tab2;
+
+--echo ****************
+--echo Include only db2
+--echo ****************
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-databases db2>> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-databases db2 >> $NDB_TOOLS_OUTPUT
+
+use db1;
+show tables;
+use db2;
+show tables;
+checksum table tab1, tab2;
+
+
+drop table db2.tab1, db2.tab2;
+
+--echo ****************
+--echo Exclude only db2
+--echo ****************
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-databases db2>> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-databases db2 >> $NDB_TOOLS_OUTPUT
+
+
+use db1;
+show tables;
+checksum table tab1, tab2;
+
+use db2;
+show tables;
+
+drop table db1.tab1, db1.tab2;
+
+--echo ************
+--echo Exclude both
+--echo ************
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-databases db2,db1>> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-databases db2,db1 >> $NDB_TOOLS_OUTPUT
+
+
+use db1;
+show tables;
+use db2;
+show tables;
+
+--echo **********************************
+--echo Include only db1.tab1 and db2.tab2
+--echo **********************************
+
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-tables db1.tab1,db2.tab2 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-tables db1.tab1,db2.tab2 >> $NDB_TOOLS_OUTPUT
+
+
+use db1;
+show tables;
+checksum table tab1;
+
+use db2;
+show tables;
+checksum table tab2;
+
+
+drop table db1.tab1, db2.tab2;
+
+--echo *****************************
+--echo Exclude db1.tab1 and db2.tab2
+--echo *****************************
+--echo Should result in db1.tab2 and db2.tab1 being restored
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-tables db1.tab1,db2.tab2 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-tables db1.tab1,db2.tab2 >> $NDB_TOOLS_OUTPUT
+
+
+use db1;
+show tables;
+checksum table tab2;
+
+use db2;
+show tables;
+checksum table tab1;
+
+drop table db1.tab2, db2.tab1;
+
+--echo *********************************
+--echo Include db1.tab1, but exclude db1
+--echo *********************************
+
+--echo Should result in only db1.tab1 being restored
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-tables db1.tab1 --exclude-databases db1 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-tables db1.tab1 --exclude-databases db1 >> $NDB_TOOLS_OUTPUT
+
+
+use db1;
+show tables;
+checksum table tab1;
+
+use db2;
+show tables;
+
+drop table db1.tab1;
+
+--echo *********************************
+--echo Exclude db1.tab1, but include db1
+--echo *********************************
+--echo Should result in only db1.tab2 being restored
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-tables db1.tab1 --include-databases db1 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-tables db1.tab1 --include-databases db1 >> $NDB_TOOLS_OUTPUT
+
+
+use db1;
+show tables;
+checksum table tab2;
+
+use db2;
+show tables;
+
+drop table db1.tab2;
+
+--echo **************************************
+--echo Exclude db1.tab1, and include db1.tab1
+--echo **************************************
+--echo Should result in db1.tab1 only restored.
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-tables db1.tab1 --include-tables db1.tab1 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-tables db1.tab1 --include-tables db1.tab1 >> $NDB_TOOLS_OUTPUT
+
+
+use db1;
+show tables;
+checksum table tab1;
+
+use db2;
+show tables;
+
+drop table db1.tab1;
+
+--echo ****************************
+--echo Exclude db2, and include db2
+--echo ****************************
+--echo Should result in db2 only restored.
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-databases db2 --include-databases db2 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-databases db2 --include-databases db2 >> $NDB_TOOLS_OUTPUT
+
+
+use db1;
+show tables;
+use db2;
+show tables;
+checksum table tab1, tab2;
+
+drop table db2.tab1, db2.tab2;
+
+--echo *********************************
+--echo Include db1, and include db2.tab1
+--echo *********************************
+--echo Should result in db2.tab1 only restored.
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-databases db1 --include-tables db2.tab1 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-databases db1 --include-tables db2.tab1 >> $NDB_TOOLS_OUTPUT
+
+
+use db1;
+show tables;
+use db2;
+show tables;
+checksum table tab1;
+
+drop table db2.tab1;
+
+
+--echo ************************
+--echo Include unknown database
+--echo ************************
+--echo Should result in nothing restored
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-databases unhappy_customer >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-databases unhappy_customer >> $NDB_TOOLS_OUTPUT
+
+show databases;
+use db1;
+show tables;
+use db2;
+show tables;
+
+--echo *********************
+--echo Exclude unknown table
+--echo *********************
+--echo Should result in everything restored
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-tables db1.unhappy_customer >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --exclude-tables db1.unhappy_customer >> $NDB_TOOLS_OUTPUT
+
+show databases;
+
+use db1;
+show tables;
+checksum table tab1, tab2;
+use db2;
+show tables;
+checksum table tab1, tab2;
+
+drop table db1.tab1, db1.tab2;
+drop table db2.tab1, db2.tab2;
+
+--echo *********************************************
+--echo Check that last argument of each type is used
+--echo *********************************************
+--echo Should result in just db1.tab2 restored.
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 1 -r -m $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-tables db1.tab1 --include-tables db1.tab2 >> $NDB_TOOLS_OUTPUT
+--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults -b $the_backup_id -n 2 -r $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id --include-tables db1.tab1 --include-tables db1.tab2 >> $NDB_TOOLS_OUTPUT
+
+use db1;
+show tables;
+checksum table tab2;
+
+use db2;
+show tables;
+
+drop table db1.tab2;
+
+
+drop database db1;
+drop database db2;
+
+# End of bug 40429
=== modified file 'storage/ndb/include/util/BaseString.hpp'
--- a/storage/ndb/include/util/BaseString.hpp 2008-10-24 11:00:37 +0000
+++ b/storage/ndb/include/util/BaseString.hpp 2009-01-30 15:08:46 +0000
@@ -129,7 +129,7 @@ public:
* @params c character to look for
* @returns index of character, of -1 if no character found
*/
- ssize_t indexOf(char c);
+ ssize_t indexOf(char c) const;
/**
* Returns the index of the last occurance of the character c.
@@ -137,7 +137,7 @@ public:
* @params c character to look for
* @returns index of character, of -1 if no character found
*/
- ssize_t lastIndexOf(char c);
+ ssize_t lastIndexOf(char c) const;
/**
* Returns a subset of a string
@@ -146,7 +146,7 @@ public:
* @param stop index of last character
* @return a new string
*/
- BaseString substr(ssize_t start, ssize_t stop = -1);
+ BaseString substr(ssize_t start, ssize_t stop = -1) const;
/**
* @brief Assignment operator
=== modified file 'storage/ndb/src/common/util/BaseString.cpp'
--- a/storage/ndb/src/common/util/BaseString.cpp 2008-11-20 16:36:23 +0000
+++ b/storage/ndb/src/common/util/BaseString.cpp 2009-01-30 15:08:46 +0000
@@ -274,7 +274,7 @@ BaseString::split(Vector<BaseString> &v,
}
ssize_t
-BaseString::indexOf(char c) {
+BaseString::indexOf(char c) const {
char *p;
p = strchr(m_chr, c);
if(p == NULL)
@@ -283,7 +283,7 @@ BaseString::indexOf(char c) {
}
ssize_t
-BaseString::lastIndexOf(char c) {
+BaseString::lastIndexOf(char c) const {
char *p;
p = strrchr(m_chr, c);
if(p == NULL)
@@ -292,7 +292,7 @@ BaseString::lastIndexOf(char c) {
}
BaseString
-BaseString::substr(ssize_t start, ssize_t stop) {
+BaseString::substr(ssize_t start, ssize_t stop) const {
if(stop < 0)
stop = length();
ssize_t len = stop-start;
=== modified file 'storage/ndb/tools/restore/restore_main.cpp'
--- a/storage/ndb/tools/restore/restore_main.cpp 2008-11-13 15:22:59 +0000
+++ b/storage/ndb/tools/restore/restore_main.cpp 2009-01-30 15:35:05 +0000
@@ -55,6 +55,8 @@ unsigned int opt_progress_frequency;
NDB_TICKS g_report_next;
Vector<BaseString> g_databases;
Vector<BaseString> g_tables;
+Vector<BaseString> g_include_tables, g_exclude_tables;
+Vector<BaseString> g_include_databases, g_exclude_databases;
NdbRecordPrintFormat g_ndbrecord_print_format;
unsigned int opt_no_binlog;
@@ -91,7 +93,11 @@ enum ndb_restore_options {
OPT_APPEND,
OPT_PROGRESS_FREQUENCY,
OPT_NO_BINLOG,
- OPT_VERBOSE
+ OPT_VERBOSE,
+ OPT_INCLUDE_TABLES,
+ OPT_EXCLUDE_TABLES,
+ OPT_INCLUDE_DATABASES,
+ OPT_EXCLUDE_DATABASES
};
static const char *opt_fields_enclosed_by= NULL;
static const char *opt_fields_terminated_by= NULL;
@@ -100,6 +106,10 @@ static const char *opt_lines_terminated_
static const char *tab_path= NULL;
static int opt_append;
+static const char *opt_exclude_tables= NULL;
+static const char *opt_include_tables= NULL;
+static const char *opt_exclude_databases= NULL;
+static const char *opt_include_databases= NULL;
static struct my_option my_long_options[] =
{
@@ -215,6 +225,23 @@ static struct my_option my_long_options[
"verbosity",
(uchar**) &opt_verbose, (uchar**) &opt_verbose, 0,
GET_INT, REQUIRED_ARG, 1, 0, 255, 0, 0, 0 },
+ { "include-databases", OPT_INCLUDE_DATABASES,
+ "Comma separated list of databases to restore. Example: db1,db3",
+ (uchar**) &opt_include_databases, (uchar**) &opt_include_databases, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
+ { "exclude-databases", OPT_EXCLUDE_DATABASES,
+ "Comma separated list of databases to not restore. Example: db1,db3",
+ (uchar**) &opt_exclude_databases, (uchar**) &opt_exclude_databases, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
+ { "include-tables", OPT_INCLUDE_TABLES, "Comma separated list of tables to "
+ "restore. Table name should include database name. Example: db1.t1,db3.t1",
+ (uchar**) &opt_include_tables, (uchar**) &opt_include_tables, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
+ { "exclude-tables", OPT_EXCLUDE_TABLES, "Comma separated list of tables to "
+ "not restore. Table name should include database name. "
+ "Example: db1.t1,db3.t1",
+ (uchar**) &opt_exclude_tables, (uchar**) &opt_exclude_tables, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@@ -384,10 +411,71 @@ get_one_option(int optid, const struct m
}
return 0;
}
+
+static const char* SCHEMA_NAME="/def/";
+static const int SCHEMA_NAME_SIZE= 5;
+
+int
+makeInternalTableName(const BaseString &externalName,
+ BaseString& internalName)
+{
+ // Make dbname.table1 into dbname/def/table1
+ Vector<BaseString> parts;
+
+ // Must contain a dot
+ if (externalName.indexOf('.') == -1)
+ return -1;
+ externalName.split(parts,".");
+ // .. and only 1 dot
+ if (parts.size() != 2)
+ return -1;
+ internalName.clear();
+ internalName.append(parts[0]); // db name
+ internalName.append(SCHEMA_NAME); // /def/
+ internalName.append(parts[1]); // table name
+ return 0;
+}
+
+void
+processTableList(const char* str, Vector<BaseString> &lst)
+{
+ // Process tables list like db1.t1,db2.t1 and exits when
+ // it finds problems.
+ unsigned int i;
+ /* Split passed string on comma into 2 BaseStrings in the vector */
+ BaseString(str).split(lst,",");
+ for (i=0; i < lst.size(); i++)
+ {
+ BaseString internalName;
+ if (makeInternalTableName(lst[i], internalName))
+ {
+ info << "`" << lst[i] << "` is not a valid tablename!" << endl;
+ exit(NDBT_ProgramExit(NDBT_WRONGARGS));
+ }
+ lst[i].assign(internalName);
+ }
+}
+
+BaseString
+makeExternalTableName(const BaseString &internalName)
+{
+ // Make dbname/def/table1 into dbname.table1
+ int idx;
+ BaseString externalName;
+
+ idx = internalName.indexOf('/');
+ externalName = internalName.substr(0,idx);
+ externalName.append(".");
+ externalName.append(internalName.substr(idx + SCHEMA_NAME_SIZE,
+ internalName.length()));
+ return externalName;
+}
+
bool
readArguments(int *pargc, char*** pargv)
{
Uint32 i;
+ BaseString tmp;
debug << "Load defaults" << endl;
const char *load_default_groups[]= { "mysql_cluster","ndb_restore",0 };
@@ -536,9 +624,13 @@ o verify nodegroup mapping
info << "backup path = " << ga_backupPath << endl;
if (g_databases.size() > 0)
{
+ info << "WARNING! Using deprecated syntax for selective object restoration." << endl;
+ info << "Please use --include-*/--exclude-* options in future." << endl;
info << "Restoring only from database " << g_databases[0].c_str() << endl;
if (g_tables.size() > 0)
- info << "Restoring only tables:";
+ {
+ info << "Restoring tables:";
+ }
for (unsigned i= 0; i < g_tables.size(); i++)
{
info << " " << g_tables[i].c_str();
@@ -546,6 +638,53 @@ o verify nodegroup mapping
if (g_tables.size() > 0)
info << endl;
}
+
+ if (opt_include_databases)
+ {
+ tmp = BaseString(opt_include_databases);
+ tmp.split(g_include_databases,",");
+ info << "Including Databases: ";
+ for (i= 0; i < g_include_databases.size(); i++)
+ {
+ info << g_include_databases[i] << " ";
+ }
+ info << endl;
+ }
+
+ if (opt_exclude_databases)
+ {
+ tmp = BaseString(opt_exclude_databases);
+ tmp.split(g_exclude_databases,",");
+ info << "Excluding databases: ";
+ for (i= 0; i < g_exclude_databases.size(); i++)
+ {
+ info << g_exclude_databases[i] << " ";
+ }
+ info << endl;
+ }
+
+ if (opt_include_tables)
+ {
+ processTableList(opt_include_tables, g_include_tables);
+ info << "Including tables: ";
+ for (i= 0; i < g_include_tables.size(); i++)
+ {
+ info << makeExternalTableName(g_include_tables[i]).c_str() << " ";
+ }
+ info << endl;
+ }
+
+ if (opt_exclude_tables)
+ {
+ processTableList(opt_exclude_tables, g_exclude_tables);
+ info << "Excluding tables: ";
+ for (i= 0; i < g_exclude_tables.size(); i++)
+ {
+ info << makeExternalTableName(g_exclude_tables[i]).c_str() << " ";
+ }
+ info << endl;
+ }
+
/*
the below formatting follows the formatting from mysqldump
do not change unless to adopt to changes in mysqldump
@@ -602,15 +741,20 @@ isIndex(const TableS* table)
}
static inline bool
-checkDbAndTableName(const TableS* table)
+isInList(BaseString &needle, Vector<BaseString> &lst)
{
- if (g_tables.size() == 0 &&
- g_databases.size() == 0)
- return true;
- if (g_databases.size() == 0)
- g_databases.push_back("TEST_DB");
+ unsigned int i= 0;
+ for (i= 0; i < lst.size(); i++)
+ {
+ if (strcmp(needle.c_str(), lst[i].c_str()) == 0)
+ return true;
+ }
+ return false;
+}
- // Filter on the main table name for indexes and blobs
+const char*
+getTableName(const TableS* table)
+{
const char *table_name;
if (isBlobTable(table))
table_name= table->getMainTable()->getTableName();
@@ -619,6 +763,67 @@ checkDbAndTableName(const TableS* table)
NdbTableImpl::getImpl(*table->m_dictTable).m_primaryTable.c_str();
else
table_name= table->getTableName();
+
+ return table_name;
+}
+
+static inline bool
+checkDoRestore(const TableS* table)
+{
+ int idx;
+ bool ret = true;
+ BaseString db, tbl;
+
+ tbl.assign(getTableName(table));
+ idx = tbl.indexOf('/');
+ db = tbl.substr(0, idx);
+
+ /* Included tables overrides
+ * Excluded tables which overrides
+ * Included databases which overrides
+ * Excluded databases.
+ * If any databases are included, then only
+ * included databases are restored.
+ * If any tables are included, then only
+ * included tables are restored.
+ */
+
+ if (g_exclude_databases.size() != 0) {
+ if (isInList(db, g_exclude_databases))
+ ret = false;
+ }
+ if (g_include_databases.size() != 0) {
+ ret= isInList(db, g_include_databases);
+ }
+
+ if (g_exclude_tables.size() != 0) {
+ if (isInList(tbl, g_exclude_tables))
+ ret = false;
+ }
+ if (g_include_tables.size() != 0) {
+ ret= isInList(tbl, g_include_tables);
+ }
+
+ return ret;
+}
+
+static inline bool
+checkDbAndTableName(const TableS* table)
+{
+ // If new options are given, ignore the old format
+ if (opt_include_tables || opt_exclude_tables ||
+ opt_include_databases || opt_exclude_databases ) {
+ return (checkDoRestore(table));
+ }
+
+ if (g_tables.size() == 0 && g_databases.size() == 0)
+ return true;
+
+ if (g_databases.size() == 0)
+ g_databases.push_back("TEST_DB");
+
+ // Filter on the main table name for indexes and blobs
+ const char *table_name= getTableName(table);
unsigned i;
for (i= 0; i < g_databases.size(); i++)
@@ -641,13 +846,11 @@ checkDbAndTableName(const TableS* table)
while (*table_name != '/') table_name++;
table_name++;
+ // Check if table should be restored
for (i= 0; i < g_tables.size(); i++)
{
if (strcmp(table_name, g_tables[i].c_str()) == 0)
- {
- // we have a match
return true;
- }
}
return false;
}
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-6.4 branch (frazer:3244) | Frazer Clement | 30 Jan |