Methods of DB2 data replication and migration

Source: Internet
Author: User
Tags copy db2 db2 connect db2 connect to connect reset stringbuffer

The following methods have been tested, in the environment IBM X346,3.2gx2,4g,raid 1,DB2 v8.2.4,win2000 ADV Server,dms tablespace, the data load speed is around 601 million/min.

Background: You need to change the database table space, or you need to migrate the data from all the tables in the database to a new database.

Steps:

1. Select all tables in the source database through the DB2 console (DB2CC) and export them as DDL scripts;

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

3. New database, new DMS table space: GATHER;

4. Execute the DDL script in this database;

5. Write code to query all tables in the source database, automatically generate export script;

6. Write code to query all tables in the source database and automatically generate import scripts;

7. Connect the source database to execute export script;

8. Connect the target database to execute the import script;

Appendix 1: Generate Export script code sample:

/**

* Create 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.systables where creator = '" + Creator + "' and type= ' T '";

try {

Dbbase.executequery (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: Generate an Import script code example:

/**

* Create Mount 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.systables where creator = '" + Creator + "' and type= ' T '";

try {

Dbbase.executequery (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 Sample

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 Sample

DB2 Connect to TESTDB user test password test

DB2 "Load from AA1.IXF of IXF to replace into table1 COPY NO without prompting"

DB2 "Load from AA2.IXF of IXF to replace into table2 COPY NO without prompting"

DB2 Connect Reset

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.