def copy_data(self, new_db, options, new_server=None, connections=1): """Copy the data for the tables. This method will copy the data for all of the tables to another, new database. The method will process an input file with INSERT statements if the option was selected by the caller. new_db[in] Name of the new database options[in] Options for copy e.g. force, etc. new_server[in] Connection to another server for copying the db Default is None (copy to same server - clone) connections[in] Number of threads(connections) to use for insert """ from mysql.utilities.common.table import Table # Must call init() first! # Guard for init() prerequisite assert self.init_called, "You must call db.init() before "+ \ "db.copy_data()." if self.skip_data: return self.destination = new_server # We know we're cloning if there is no new connection. self.cloning = (new_server == self.source) if self.cloning: self.destination = self.source quiet = options.get("quiet", False) tbl_options = { 'verbose' : self.verbose, 'get_cols' : True, 'quiet' : quiet } table_names = [obj[0] for obj in self.get_db_objects(_TABLE)] for tblname in table_names: if not quiet: print "# Copying data for TABLE %s.%s" % (self.db_name, tblname) tbl = Table(self.source, "%s.%s" % (self.q_db_name, quote_with_backticks(tblname)), tbl_options) if tbl is None: raise UtilDBError("Cannot create table object before copy.", -1, self.db_name) tbl.copy_data(self.destination, self.cloning, new_db, connections)
def copy_data(self, new_db, options, new_server=None, connections=1): """Copy the data for the tables. This method will copy the data for all of the tables to another, new database. The method will process an input file with INSERT statements if the option was selected by the caller. new_db[in] Name of the new database options[in] Options for copy e.g. force, etc. new_server[in] Connection to another server for copying the db Default is None (copy to same server - clone) connections[in] Number of threads(connections) to use for insert """ from mysql.utilities.common.table import Table # Must call init() first! # Guard for init() prerequisite assert self.init_called, "You must call db.init() before " + "db.copy_data()." if self.skip_data: return self.destination = new_server # We know we're cloning if there is no new connection. self.cloning = new_server == self.source if self.cloning: self.destination = self.source quiet = options.get("quiet", False) tbl_options = {"verbose": self.verbose, "get_cols": True, "quiet": quiet} # Turn off foreign keys if they were on at the start self.destination.disable_foreign_key_checks(True) table_names = [obj[0] for obj in self.get_db_objects(_TABLE)] for tblname in table_names: if not quiet: print "# Copying data for TABLE `%s`.`%s`" % (self.db_name, tblname) tbl = Table(self.source, "`%s`.`%s`" % (self.db_name, tblname), tbl_options) if tbl is None: raise UtilDBError("Cannot create table object before copy.", -1, self.db_name) tbl.copy_data(self.destination, self.cloning, new_db, connections) # Now, turn on foreign keys if they were on at the start self.destination.disable_foreign_key_checks(False)