【AntDB数据库】AntDB数据库迁移(二)

118 篇文章 0 订阅
97 篇文章 2 订阅

导出导入数据

导出数据

编写配置文件

ora2pg 导出数据的配置文件如下:

cat > shcrm_so1_data.conf << EOF
ORACLE_HOME /home/postgres/oracle/instantclient_11_2  
ORACLE_DSN  dbi:Oracle:host=10.10.141.225;sid=shcrm1  
ORACLE_USER so1  
ORACLE_PWD  Csxt-123  
SCHEMA  so1 
TYPE COPY 
OUTPUT_DIR  /adbdata/ora2pg/data/so1
USER_GRANTS 1
FILE_PER_TABLE 1
SPLIT_FILE 1
DISABLE_SEQUENCE 1
STOP_ON_ERROR 0
ORACLE_COPIES 10
DATA_LIMIT  100000
SPLIT_LIMIT  10000000
WHERE expire_date >= to_date('2015/06/01 00:00:00','yyyy/MM/dd hh24:mi:ss') and expire_date < to_date('2016/07/01 00:00:00','yyyy/MM/dd hh24:mi:ss')
EOF

OUTPUT_DIR 指定了导出sql文件的存放目录。

WHERE 指定了导出时候对数据的过滤条件,如果需要全表数据导出,则去掉该参数。

创建相关目录

mkdir -p /adbdata/ora2pg/data/{so1,so2,party}/import_done

import_done 存放各个用户下,导入完成后的sql文件。

导出数据

在迁移涉及到的表数量比较多的时候,建议采用表的方式来记录迁移表的信息,方便查询表的迁移状态。

创建配置表

创建配置表用来存放迁移表的信息:

create table t_ora2adb_tableinfo
(
dbname text,
owner text,
tablename text,
batch_tag text,
o_cnt numeric,
a_cnt numeric,
o_cnt_time timestamp,
a_cnt_time timestamp,
o_minus_a numeric,
a_minus_o numeric,
o_size_m numeric,
a_size_m numeric,
is_export numeric,
export_time timestamp,
where_filter text
);

初始化配置表

insert into t_ora2adb_tableinfo
(dbname,owner,tablename,is_export)
select 'shhis',a.tableowner,a.tablename,0
from pg_tables a
where 1=1
and a.tableowner not in ('postgres','') 
and a.schemaname not in ('public','pg_catalog','information_schema')
and a.tablename like 'sec%';
;

更新配置表字段

字段is_export的值在初始化的时候设置为0,需要更新该字段为1或者更新其他字段,则通过update语句来操作:

update t_ora2adb_tableinfo set xx=xx where xx ..

编写导出脚本

vi ora2pg_export.sh
#!/bin/bash 
# ora2pg export 
# ora2pg config: shhis_data.conf
# sh ora2pg_export.sh owner tablenamelike tablecnt
# sh ora2pg_export.sh configfile username tablename  logdir tablecnt
 
function check_ora_conn
{
conn_tag=`sqlplus -S /nolog <<EOF
set heading off feedback off pagesize 0 verify off echo off
conn $oraconn
select * from dual;
exit
EOF`
if [ "x$conn_tag" = "x" ]; then
  echo "the oracle connection is invalid!"  
  exit(0)
else
  echo "the oracle connection is ok!" 
fi
}

function check_ora2pg
{
  which ora2pg
  if [ $? -eq 0 ]; then
        return 0
  else
        echo "ora2pg execute program not find!"
        exit        
  fi
}

function check_ora2pgcfg
{
  if [ -f "$configfile" ]; then
        return 0
  else
        echo "ora2pg config file does not exist!"
        exit        
  fi
}

function init_tablecnt
{
if [ "x$tablecnt" = "x" ]; then
  echo "tablecnt apply init value:10"
  tablecnt=10
fi
}

function ora2pg_background
{
selectsql="select tablename 
from t_ora2adb_tableinfo 
where dbname='$dbname' 
and owner='$tableowner' 
and tablename like '%$tablelike%'
and is_export=0
limit $tablecnt;"
tables=(`$psqlconn -c "$selectsql"`)
for t in ${tables[@]}
do
 updatesql="update t_ora2adb_tableinfo set is_export=1,export_time=now() where owner='$tableowner' and tablename='$t'"
 $psqlconn -c "$updatesql"
 ora2pg -c $configfile -n $tableowner -a"$t" -d > ${logdir}/"ora2pg_"$tableowner_$t.log 2>&1 &
 echo "ora2pg to export table: $tableowner.$t"
done
}
# init parameter
configfile=$1
username=$2
tablelike=$3
logdir=$4
tablecnt=$5
tableowner="$username"
dbname="shcrm1"
# Make sure this option is correct,If the oracle database is not connected, the program will exit 
oraconn="$username/Csxt-123@10.10.141.225/shcrm"
psqlconn="psql -d $dbname -U $tableowner -q -t"
check_ora2pg
check_ora2pgcfg
init_tablecnt
ora2pg_background

执行导出操作

sh ora2pg_export.sh /adbdata/ora2pg/conf/shcrm_so1_data.conf so1 ord_user_ext_f_210_201612 /adbdata/ora2pg/log 3

AntDB数据库始于2008年,在运营商的核心系统上,为全国24个省份的10亿多用户提供在线服务,具备高性能、弹性扩展、高可靠等产品特性,峰值每秒可处理百万笔电信核心交易,保障系统持续稳定运行近十年,并在通信、金融、交通、能源、物联网等行业成功商用落地。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值