本文目标:
以数据泵方式导出、导入指定数据库,方便之后查验。
操作步骤:
1、切换至oracle用户创建物理备份目录
[root@oracle~]# su - oracle
[oracle@oracle ~]$ mkdir -p /oradata/oracle/oradata/backup_files
2、创建备份用户并赋权
[oracle@oracle ~]$ sqlplus /nolog
SQL> conn /as sysdba
SQL> create user dumpuser identified by "DumpPwd.147^Tkamc";
SQL> grant connect,resource,exp_full_database,imp_full_database to <username>;
- 创建逻辑目录
需以oracle管理员用户创建逻辑目录,在oracle中注册物理备份路径:
SQL> create or replace directory backup_dir as '/oradata/oracle/oradata/backup_files';
查看逻辑目录创建情况
SQL> select * from dba_directories;
为指定备份用户赋权逻辑目录的权限
SQL> grant read,write on directory backup_dir to <username>;
- 导出导入指令
####导出####
1、按用户导出数据
[oracle@test~]$ expdp username/password@servicename schemas=username DIRECTORY=backup_dir DUMPFILE=YYYYMMDD_USERNAME.dmp logfile=YYYYMMDD_USERNAME.log;
2、按表名导
[oracle@test ~]$ expdp username/password@servicename schemas=username DIRECTORY=backup_dir TABLES=tablename1,tablename2 dumpfile=tablename1.dmp;
3、按查询条件导
[oracle@test ~]$ expdp username/password@servicename directory=backup_dir dumpfile=tablename1.dmp schemas=username Tables=tablename1 query=\"WHERE id=\'5280e\'\";
4、全库导出
[oracle@test ~]$ expdp username/password@service_name directory=backup_dir dumpfile=YYYYMMDD_FULL.dmp logfile=YYYYMMDD_FULL.log full=y
###导入####
1、按用户导入
[oracle@test ~]$ impdp username/password@servicename directory=backup_dir dumpfile=username.dmp schemas=username table_exists_action=truncate logfile=username.log remap_tablespace=sourcespace:destinationspace
2、按表导入
[oracle@test ~]$ impdp username/password@servicename directory=backup_dir dumpfile=username.dmp schemas=username directory=backup_dir tables=tablename1 dumpfile=username.dmp logfile=username.log
3、全库导入
[oracle@test ~]$ impdb username/password@service_name directory=backup_dir dumpfile=YYYYMMDD_FULL.dmp logfile=YYYYMMDD_FULL.log full=y
参数说明:
schemas ##此处填写对应需要导出的username
directory ##此处填写数据库创建的逻辑目录名称
remap_schemas ## remap_schema=QA:QB 含义为将数据从Schema:QA导入Schema:QB
remap_tablespace ## remap_tablespace=QA:QB 含义为从将表空间从QA转移为QB