http://blog.itpub.net/post/43125/523997

关键字:exp imp 导出导入schema

1导出

1.1源DB信息检查

1.1.1查源DB中指定username下所有对象所占空间。

select sum(bytes) / 1024 / 1024

from dba_segments d

where d.owner = '&username';

exp出的dmp文件大小不会比此处查询出的结果更大。

1.1.2获取源schema所有对象个数

select d.object_type, count(1)

from dba_objects d

where d.owner = 'ATS001'

group by d.object_type

order by d.object_type;

1.1.3检查磁盘空间

#df –g

选择一块足够大的空间存放exp出来的dmp文件

1.2exp导出源schema

根据上面查询的结果可以确定参数filesize和file,exp脚本如下

# vi exp.par

userid='/ as sysdba '

file=exp01.dmp,exp02.dmp

filesize=4000M

owner=username

log=exp.log

direct=y

RESUMABLE=y

RESUMABLE_NAME=exp_myname

RESUMABLE_TIMEOUT=9999999

#exp parfile=exp.par

2导入

2.1目标DB信息检查

2.1.1检查磁盘空间

#df –g

选择一块可以存放dmp文件的路径,将exp出来的dmp文件从源主机传过来。

2.1.2检查目标schema上的活动session

select *

from v$session v

where v.username = '&username'

and v.STATUS = 'ACTIVE';

通知用户停止session或者手动kill掉

alter system kill session ‘&sid,&serial#’;

2.2备份目标schema信息

2.2.1备份目标schema创建和授权脚本

密码

select * from dba_users d where d.username=&username;

系统权限授权脚本

select * from dba_sys_privs d where d.grantee='&username';

对象权限授权脚本

select * from dba_tab_privs d where d.grantee='&username';

2.2.2备份schema私有dblink创建脚本

select * from dba_db_links where owner='&USERNAME';

系统表sys.link$下存有dblink连接用户的密码。

2.2.3检查其他schema下是否有FK是否关联目标schema的对象

select *

from dba_constraints d

where d.owner <> 'ATS001'

and d.constraint_type = 'R'

and d.r_owner = 'ATS001';

如果存在,则需disable这些FK。

2.3重建目标schema

2.3.1删除目标schema

drop user &username cascade;

2.3.2重建schema

使用2.2.1的备份脚本重建schema

2.3.3检查schema

检查2.3.2创建的schema的密码权限

系统权限

select * from dba_sys_privs d where d.grantee='&username';

对象权限

select * from dba_tab_privs d where d.grantee='&username';

2.4imp目标schema

#vi imp.par

userid='/ as sysdba '

file=exp01.dmp

fromuser=username

touser=username

ignore=y

rows=y

log=imp.log

RESUMABLE=y

RESUMABLE_NAME=imp_myname

RESUMABLE_TIMEOUT=9999999

#imp parfile=imp.par

2.5导入后检查

2.5.1重建DB link

先删除导入的dblink,该dblink很可能是指向生产的。

使用2.2.2的备份脚本重建dblink

2.5.2核对所有对象个数

获取目标schema所有对象个数,同1.1.2的结果比较

select d.object_type, count(1)

from dba_objects d

where d.owner = 'ATS001'

group by d.object_type

order by d.object_type;

2.5.3重编译失效对象

获取失效对象

select *

from dba_objects d

where d.owner = 'ATS001'

and d.status <> 'VALID';

重编译失效对象(以trigger为例)

select 'alter trigger ats001.' || d.object_name || ' compile;'

from dba_objects d

where d.owner = 'ATS001'

and d.status <> 'VALID'

and d.object_type = 'TRIGGER';