免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 7004 | 回复: 3
打印 上一主题 下一主题

DB2数据复制、迁移方法介绍 [复制链接]

论坛徽章:
4
2015年亚洲杯之乌兹别克斯坦
日期:2015-02-05 15:38:372015年迎新春徽章
日期:2015-03-04 10:16:532015元宵节徽章
日期:2015-03-06 15:52:302015年亚洲杯之科威特
日期:2015-04-01 16:23:36
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-01-24 14:11 |只看该作者 |倒序浏览

     数据复制以及迁移是DB2数据库操纵经常用到的,下面多备份为大家介绍DB2数据库数据复制、迁移的方法。
  以下方法经测试,在环境IBM x346,3.2G×2,4G,RAID 1,DB2 V8.2.4,Win2000 Adv Server,DMS表空间中,数据的load速度在60-100万条/min左右。
  背景:需要更改数据库表空间,或者需要将数据库中所有表的数据迁移到一个新的数据库中。
  步骤:
  1.通过db2控制台(db2cc)选中源数据库中的所有表,将其导出成DDL脚本;
  2.根据需要对脚本进行必要的修改,譬如更改表空间为GATHER;
  3.新建数据库,新建DMS表空间:GATHER;
  4.将DDL脚本在此数据库中执行;
  5.编写代码查询源数据库中的所有表,自动生成export脚本;
  6.编写代码查询源数据库中的所有表,自动生成import脚本;
  7.连接源数据库执行export脚本;
  8.连接目标数据库执行import脚本;
 生成export脚本代码示例:
  /**
  * 创建导出脚本
  * @param conn
  * @param 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);
  }
 生成import脚本代码示例:
  /**
  * 创建装载脚本
  * @param conn
  * @param 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);
  }
 export脚本示例
  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
import脚本示例
  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
  以上就是有关db2的数据复制和迁移的内容了,大家都收藏起来吧以备不时之需。
   多多备份,多多安心 【文章来源:多备份】

论坛徽章:
0
2 [报告]
发表于 2015-02-08 17:23 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
3 [报告]
发表于 2015-02-09 14:38 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:48:00
4 [报告]
发表于 2015-02-09 18:16 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP