参看: [url]http://www.ibm.com/developerworks/cn/education/data/db2-cert7315/section6.html[/url] 和 [url]http://www.ibm.com/developerworks/cn/data/library/techarticles/dm-0712xiam/index.html?ca=drs[/url]
[b]The below is how to do the db2 data migration.[/b]
(1).Export source data from source DB

db2move <database_name> export -sn <database_schema> -u <DBA> -p <DBA_PASSWORD> > <logFile>



For example:


db2move GEHGAL export -sn GEH_ADMIN -u GEH_ADMIN -p GEH_ADMIN > mv.log



If you want to export the db DDL schema from source DB, you should use the below db2 commands:


db2look -d GEHGAL -e -o ddlfile -i GEH_ADMIN -w GEH_ADMIN



or


db2look -d GEHGAL -u GEH_ADMIN -e -o alltables.sql




(2).Create a 32k normal or large tablespace


db2 CREATE LARGE TABLESPACE LARGEGEHGAL32 PAGESIZE 32 K MANAGED BY DATABASE USING (FILE 'C:\DB2\NODE0000\SQL00001\largegehgal32' 20000) BUFFERPOOL IBMDEFAULT32K



(3).Create the db2 user that should be same name as exported <database_schema> that is from source DB in target DB2 database, assign the 32k tablespace to the user, and delete the other tablespaces


(4).Code page from target DB should be same as the code page of source DB. You should use the following command to check:


db2 get db cfg



If they are different, change the code page in target DB, use the following command:


db2set db2codepage=1252 (1252 is the page code of source DB)
 db2 terminate



[color=green]db2 terminate command must be executed(注意一定要进行terminate)[/color]


(5).Create a 16k or 32k temporary tablespace. It will be used when you view the Project Exception List from deployed GEH GUI


DB2 CREATE TEMPORARY TABLESPACE gehgalsystemtmp32 IN DATABASE PARTITION GROUP IBMTEMPGROUP PAGESIZE 32K MANAGED BY SYSTEM USING ('C:\DB2\NODE0000\SQL00001\gehgalsystemtmp32') EXTENTSIZE 32 PREFETCHSIZE 16 BUFFERPOOL IBMDEFAULT32K



(6).Import the data into the target DB


db2move <database_name> import -io create -u <DBA> -p <DBA_PASSWORD> > <logFile>



For example:


db2move GEHGAL import -io create -u GEH_MIGRATION -p Gal@pass > imp.log



Check the imp.log whether the import operation is successful.



If the table schema has been created/existed in target DB, so you can use the following command:


db2move GEHGAL import -io INSERT_UPDATE -u GEH_MIGRATION -p Gal@pass > imp.log




(7).If the export operation is successful, and you will find some tables in [color=green]userspace1 tablespace[/color], and the other tables in [color=green]LARGEGEHGAL32 tablespace[/color]


(8).If there are some procedures in your db schema, you should [color=green]execute the procedures that will not be imported into target database[/color]


(9).You should change the tables that have identify column if you want to store new messages in the target DB. The below is the commands that reset the identify value of EXCEPTION_MESSAGE table.


select max(EXCEPTION_MESSAGE_ID) from EXCEPTION_MESSAGE
$nextMessageId = max(EXCEPTION_MESSAGE_ID) + 1
alter table EXCEPTION_MESSAGE alter column EXCEPTION_MESSAGE_ID restart with $nextMessageId




[b]import usage:[/b]


db2move <database-name> <action> [<option> <value>]


首先,您必须指定数据库名(想要移动的表所在的数据库)和要执行的操作(export和import或load)。然后指定一个选项来定义操作的范围。例如,可以将一个操作限制在特定的表(-tn)、表空间(-ts)、表创建者(-tc)或模式名(-sn)范围内。指定表、表空间或表的创建者的一个子集只对export操作有效。如果指定多个值,就必须使用逗号将其分隔开;在值列表项之间不允许有空格。可以指定的项最多为10个。



另外,也可以指定-tf选项,此时要使用一个文件名作为参数,其中列出了要导出的表名;在该文件中,每行只能列出一个完整的表名。您还可以指定以下内容:



-io import-option


指定DB2的import工具可以运行的一种模式。有效的选项有:CREATE、INSERT、INSERT_UPDATE、REPLACE和REPLACE_CREATE。缺省值为REPLACE_CREATE。参看: [url]http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/core/r0008304.htm[/url]



-lo load-option


指定DB2的load工具可以运行的一种模式。有效的选项有:INSERT和REPLACE。缺省值为INSERT。



-l lobpaths


指定要创建或查找的LOB文件的位置。必须指定一个或多个绝对路径名。如果指定了多个绝对路径,就必须使用逗号将其分隔开;值之间不允许有空格。缺省值是当前目录。



-u userid


指定一个用户ID,该工具可以使用这个用户ID登录到远程系统上。



-p password


指定对该用户进行认证的密码;该工具需要使用一个有效的用户ID和密码登录到远程系统上。



[b]db2codepage 设置[/b]


1、db2 变量查看


db2set -all


(connect to dbanme ) get db cfg


db2pd -osinfo




2、db2c变量的设置用命令


db2set 变量=value


可以参考一下:


客户端:


db2codepage=1386(简体中文)


db2country=86(中国)


db2comm=tcpip



服务器端:


db2codepage=1386(简体中文)


db2country=86(中国)


db2comm=tcpip


一定要把缺省的db2codepage=819改为数据库的代码页设置