【赛迪网-IT技术报道】关于数据库迁移,如果操作系统相同,例如从 Windows 系统迁移到 Windows 系统,或者从 AIX 系统迁移到 AIX 系统都比较好处理,一般使用 BACKUP 和 RESTORE 命令就可以进行。当然,有些情况下需要注意表空间重定向的问题。
那么,如果数据库迁移涉及到的操作系统不相同该怎么办呢?BACKUP 和 RESTORE 这个方法就行不通了。DB2 UDB 提供了两个非常实用的工具,一个是数据迁移工具 db2move,另一个是数据字典获取工具 db2look。
目前,我进行了一次从 Windows 2003 到 Linux 的 DB2 数据库迁移,以下是详细的操作步骤和部分脚本。希望本文能为大家在不同操作系统之间迁移 DB2 数据库的提供一些指导和帮助。
步骤一:
登录 Windows ,使用 db2move 命令将源数据库(htdctr)数据导出至指定的文件夹 G:\db2move\htdctr 下。
命令清单 - 1:
C:\Documents and Settings\Administrator>cd /d G:\db2move\htdctr
G:\db2move\htdctr>db2move htdctr export -sn db2admin -u db2admin -p *****
***** DB2MOVE *****
Action: EXPORT
Start time: Fri Mar 02 10:58:05 2007
All schema names matching: DB2ADMIN;
Connecting to database HTDCTR ... successful! Server: DB2 Common Server V8.2.4
EXPORT: 3 rows from table "DB2ADMIN"."APP_REG"
EXPORT: 0 rows from table "DB2ADMIN"."APP_TEXT"
EXPORT: 45 rows from table "DB2ADMIN"."APP_TOOL_FUNC"
EXPORT: 263 rows from table "DB2ADMIN"."DC_DMDL_ACCT_EX_GRAN"
EXPORT: 208 rows from table "DB2ADMIN"."DC_DMDL_DIM"
EXPORT: 225 rows from table "DB2ADMIN"."DC_DMDL_GRAN"
…… ……
…… ……
Disconnecting from database ... successful!
End time: Fri Mar 02 10:58:09 2007
步骤二:
登录 Windows ,使用 db2look 命令将数据库 DDL 导出至指定的文件夹 G:\db2look\htdctr 下。
命令清单 - 2:
C:\Documents and Settings\Administrator>cd /d G:\db2look\htdctr
G:\db2look\htdctr>db2look -d htdctr -e -a -o db2look_htdctr.sql
-- 为所有创建程序生成统计信息
-- 创建表的 DDL
-- 输出被发送到文件: db2look_htdc.sql
警告:需要通过将 REMOTE_AUTHID 添加至 CREATE USER MAPPING
语句修改 db2look 输出脚本
步骤三:
登录 Windows ,使用 ftp 命令登录 Linux 服务器(IP:172.168.16.105),将 DDL 脚本 G:\db2look\htdctr\db2look_htdctr.sql 上传至 Linux 服务器的指定路径下:home/db2admin/dbback/db2look/htdctr,注意,上传 DDL 脚本的时候必须使用 ASCII (asc)模式进行数据传输,否则后面执行该脚本会报错:DB21007E 读取该命令时已到达文件末尾。
命令清单 - 3:
C:\Documents and Settings\Administrator>cd /d G:\db2look\htdctr
G:\db2look\htdctr>ftp 172.168.16.105
Connected to 172.168.16.105.
220 localhost.localdomain FTP server (Version 5.60) ready.
User (172.168.16.105:(none)): db2admin
331 Password required for db2admin.
Password:
230 User db2admin logged in.
ftp> cd dbback/db2look/htdctr
250 CWD command successful.
ftp> prompt
Interactive mode Off .
ftp> asc
200 Type set to A.
ftp> put db2look_htdctr.sql
200 PORT command successful.
150 Opening ASCII mode data connection for db2look_htdctr.sql.
226 Transfer complete.
ftp: 1798538 bytes sent in 0.16Seconds 11529.09Kbytes/sec.
ftp> bye
221 Goodbye.
步骤四:
登录 Windows ,使用 ftp 命令登录 Linux 服务器(IP:172.168.16.105),将 导出的数据文件 G:\db2move\htdctr\* 全部上传至 Linux 服务器的指定路径下:home/db2admin/dbback/db2move/htdctr,注意,上传 db2move.lst 脚本的时候必须使用 ASCII (asc)模式进行数据传输,否则后面执行该脚本会报错:DB21007E 读取该命令时已到达文件末尾。上传 *.ixf、*.001 和 *.msg 文件的时候必须使用二进制模式(bin)进行数据传输。
命令清单 - 4:
C:\Documents and Settings\Administrator>cd /d G:\db2move\htdctr
G:\db2move\htdctr>ftp 172.168.16.105
Connected to 172.168.16.105.
220 localhost.localdomain FTP server (Version 5.60) ready.
User (172.168.16.105:(none)): db2admin
331 Password required for db2admin.
Password:
230 User db2admin logged in.
ftp> cd dbback/db2move/htdctr
250 CWD command successful.
ftp> prompt
Interactive mode Off .
ftp> asc
200 Type set to A.
ftp> put db2move.lst
200 PORT command successful.
150 Opening ASCII mode data connection for db2move.lst.
226 Transfer complete.
ftp: 5271 bytes sent in 0.00Seconds 5271000.00Kbytes/sec.
ftp> bin
200 Type set to I.
ftp> mput *.ixf
ftp: 49814 bytes sent in 0.00Seconds 49814000.00Kbytes/sec.
200 PORT command successful.
150 Opening BINARY mode data connection for tab98.ixf.
226 Transfer complete.
…… ……
…… ……
ftp> mput *.msg
ftp: 110 bytes sent in 0.00Seconds 110000.00Kbytes/sec.
200 PORT command successful.
150 Opening BINARY mode data connection for tab97.msg.
226 Transfer complete.
…… ……
…… ……
ftp> mput *.001
150 Opening BINARY mode data connection for tab19a.001.
226 Transfer complete.
200 PORT command successful.
150 Opening BINARY mode data connection for tab1a.001.
226 Transfer complete.
ftp: 53382 bytes sent in 0.00Seconds 53382000.00Kbytes/sec.
200 PORT command successful.
…… ……
…… ……
ftp> bye
221 Goodbye.
1
2
下一页>>