Data Replication and migration methods of IBM DB2 at Taobao level

Source: Internet
Author: User
Tags db2 connect db2 connect to ibm db2






This article mainly describes the data replication and migration methods of IBM DB2. The following describes the data replication and migration methods of IBM DB2, we hope that you will have a better understanding of data replication and migration in IBM DB2.


IBM, Data, migration, explanation of IBM, Data, migration, explanation




Key words: Migration, replication, method, IBM, DB2, Data






The following methods are tested in the following table space: IBM x346, 3.2G × 2, 4G, RAID 1, DB2 V8.2.4, Win2000 Adv Server, and DMS, the data load speed is about 60-entries per minute.


Background:


You need to change the tablespace of the database, or migrate data from all tables in the database to a new database.




Data Replication and migration steps for IBM DB2:


1. Select all tables in the source database through the db2 Console (db2cc) and export them as DDL scripts;




2. Make necessary modifications to the script as needed, such as changing the tablespace to GATHER;




3. Create a database and create a DMS tablespace: GATHER;




4. Run the DDL script in this database;




5. write code to query all tables in the source database and generate an export script automatically;




6. write code to query all tables in the source database and generate an import script automatically;




7. Connect to the source database and execute the export script;




8. connect to the target database and execute the import script;




Appendix 1: Sample Code for generating an export script:



/**

* Create an export script

* @ Param conn

* @ Param creator: Table creator

* @ Param filePath

*/

Public void createExportFile (Connection conn, String creator, String filePath) throws Exception {

DBBase dbBase = new DBBase (conn );

String selectTableSql = "select name from sysibm. Variables Ables where creator = '" + creator + "' and type = 'T '";

Try {

DbBase.exe cuteQuery (selectTableSql );

} Catch (Exception ex ){

Throw ex;

} Finally {

DbBase. close ();

}

DBResult result = dbBase. getSelectDBResult ();

List list = new ArrayList ();

While (result. next ()){

String table = result. getString (1 );

List. add (table );

}

StringBuffer sb = new StringBuffer ();

String enterFlag = "\ r \ n ";

For (int I = 0; I <list. size (); I ++ ){

String tableName = (String) list. get (I );

Sb. append ("db2 \" export to aa "+ String. valueOf (I + 1) +". ixf of ixf select * from "+ tableName + "\"");

Sb. append (enterFlag );

}

String str = sb. toString ();

FileUtility. saveStringToFile (filePath, str, false );

}

Appendix 2: Sample Code for generating an import script:



/**

* Create a load script

* @ Param conn

* @ Param creator: Table creator

* @ Param filePath

*/

Public void createLoadFile (Connection conn, String creator, String filePath) throws Exception {

DBBase dbBase = new DBBase (conn );

String selectTableSql = "select name from sysibm. Variables Ables where creator = '" + creator + "' and type = 'T '";

Try {

DbBase.exe cuteQuery (selectTableSql );

} Catch (Exception ex ){

Throw ex;

} Finally {

DbBase. close ();

}

DBResult result = dbBase. getSelectDBResult ();

List list = new ArrayList ();

While (result. next ()){

String table = result. getString (1 );

List. add (table );

}

StringBuffer sb = new StringBuffer ();

String enterFlag = "\ r \ n ";

For (int I = 0; I <list. size (); I ++ ){

String tableName = (String) list. get (I );

Sb. append ("db2 \" load from aa "+ String. valueOf (I + 1) + ". ixf of ixf into "+ tableName +" copy no without prompting \ ""); sb. append (enterFlag );

}

String str = sb. toString ();

FileUtility. saveStringToFile (filePath, str, false );

}

Appendix 3: export script example



db2 connect to testdb user test password test  

db2 "export to aa1.ixf of ixf select * from table1"  

db2 "export to aa2.ixf of ixf select * from table2"  

db2 connect reset  

Appendix 4: import script example



db2 connect to testdb user test password test  

db2 "load from aa1.ixf of ixf replace into table1 COPY NO without prompting "  

db2 "load from aa2.ixf of ixf replace into table2 COPY NO without prompting "  

db2 connect reset  

The above content is an introduction to the data replication and migration methods of IBM DB2. I hope you will have some gains.








Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.