|
迁移之前的准备工作
在需要导出的数据库执行:
1. 检查Oracle实例状态 ,sid
SQL< select instance_name,host_name,startup_time,status,database_status from v$instance;
2.查看用户和默认表空间的关系。select username, DEFAULT_TABLESPACE from dba_users;
3.切换到你需要导出的账户,查看表对应的表空间。select table_name,tablespace_name from user_all_tables;
select tablespace_name,count(tablespace_name) from user_all_tables group by tablespace_name;
4.检查表空间使用情况
select
f.tablespace_name,
a.total,
f.free,(a.total-f.free)/1024 "usedSIZE(G)"
,round((f.free/a.total)*100) "% Free"
from
(select tablespace_name, sum(bytes/(1024*1024))total from dba_data_files group by tablespace_name) a,
(select tablespace_name,round(sum(bytes/(1024*1024))) free from dba_free_space group by tablespace_name) f
WHERE a.tablespace_name =f.tablespace_name(+)
order by "% Free"
file:///E:/%E7%AC%94%E8%AE%B0/crabbo@vip.qq.com/a18c533aa3304b23be925126448fc3e9/4735e08456d5459aaf368456723b03be.jpg
5.创建dump directory目录: create or replace directory test_dir as '/home/oracle/dump';在操作系统上药创建相应的目录。 ho mkdir /home/oracle/dump6.授权:Grant read,write on directory test_dir to cesm;7.导出数据:导出全库:ho expdp \'/ as sysdba\' full=y directory=test_dir dumpfile=full.dmp 导出指定用户:ho expdp \'/ as sysdba\' schemas=bankuser directory=test_dir dumpfile=bank.dmp windows下是:ho expdp '/ as sysdba' schemas=bankuser directory=test_dir dumpfile=bank.dmp 导出指定表空间:ho expdp bankuser/bankuser tablespaces=bank directory=test_dir dumpfile=tablespace.dmp 导出指定表: ho expdp bankuser/bankuser tables=emp% directory=test_dir dumpfile=table.dmp (emp%:以emp开头的表)带条件导出单个表:ho expdp scott/cat tables=emp query=\'where deptno=10\' directory=test_dir dumpfile=emp.dmp 带条件导出多个表:ho expdp scott/cat tables=emp,emp1,dept query=\'where deptno=10\' directory=test_dir dumpfile=emp3.dmp 或 expdp \"testuser/testuser\" DIRECTORY=test_dir dumpfile=cu.dmp tables=test query=\"where cust like \'066%\'\" query="where cust_no like '066%'" 注意转义字符只导出定义:
expdp system/<password> DIRECTORY=datamove DUMPFILE=schema_exp.dmp SCHEMAS=scott content=metadata_only
导出表
Linux/Unix Platform
expdp system/<password> DIRECTORY=datamove DUMPFILE=export.dmp logfile=export.log schemas=scott INCLUDE=table:\"LIKE \'%EMP%\'\"
Windos Platform
expdp system/<password> DIRECTORY=datamove DUMPFILE=export.dmp logfile=export.log schemas=scott INCLUDE=table:\"LIKE '%EMP%'\" 8.导入数据:2)按用户导入, 这里由david执行导入scott的数据表(切莫在末尾加上分号)
impdp david/abc123 directory=dirdp dumpfile=expdp.dmp remap_schema=scott:davidimpdp david/abc123 directory=dirdp dumpfile=expdp.dmp schemas=scott remap_schema=scott:davidho impdp system/oracle schemas=bankuser (remap_schema=bankuser:bankuser) directory=test_dir dumpfile=bank.dmp 如果是导入原用户名都不用创建用户,不是原用户名创建后需要改密码。但都要创建对应表空间。按表导入:ho impdp scott/cat tables=emp directory=test_dir dumpfile=emp.dmp按查询条件导入
impdp david/abc123@orcl schemas=scott remap_schema=scott:david directory=dir
dp dumpfile=expdp.dmp query='dept:"WHERE DEPTNO=20"';按表空间导出入
impdp system/oracle directory=dirdp dumpfile=tablespace.dmp tablespaces=users;导入整个数据库
impdp system/oracle directory=dirdp dumpfile=full.dmp full=y;
并行导入:expdp scott/tiger@orcl schemas=scott directory=dirdp dumpfile=expdp_%U.dmp logfile=expdp.log parallel=12 job_name=jobname_parallel并行导出file:///E:/%E7%AC%94%E8%AE%B0/crabbo@vip.qq.com/a704152d6a864c488da271396b9207ea/1ok5gi(1~k1sz9(lh_%24%5Dk(2.jpg目标库建表空间,用户.
revoke取消授权
查看所有目录:select * from dba_directories;--查看目录及权限
Sql代码
SELECT PRIVILEGE, DIRECTORY_NAME, DIRECTORY_PATH
FROM USER_TAB_PRIVS T, ALL_DIRECTORIES D
WHERE T.TABLE_NAME(+) = D.DIRECTORY_NAME
ORDER BY 2, 1;
file:///E:/%E7%AC%94%E8%AE%B0/crabbo@vip.qq.com/19f66efd13a84d50ace8333f2302fc3d/clipboard.png
file:///E:/%E7%AC%94%E8%AE%B0/crabbo@vip.qq.com/fdea0a76fb124caabd41683dffb7ab30/clipboard.png
注:非归档模式不能实现一致性备份。
非归档,没归档日志,基本上没办法恢复,只能恢复到rman冷备那个时间点。
非归档下,RMAN只以冷备不能热备,且需要停机。
如果数据重要,还是打开归档吧。查看oracle数据库是否归档和修改归档模式:
Oracle分为非归档模式(NOARCHIVELOG) 和归档模式(ARCHIVELOG)。非归档模式不产生归档日志,虽然节省了硬盘空间,但是备份方案选择很有限,通常只能选择冷备份。还原也只能还原到备份那一时刻的数据,通常也仅在开发时使用(据说在数据仓库中也使用),Oracle安装默认就是非归档模式。在生产环境中我们因该使用归档模式,它会产生归档日志,可以使用多种备份和还原方案,对与Oracle管理员来说应该更改模式是必然的选择。
1.查看数据库现有模式可使用以下语句 select name,log_mode from v$database; 也可以用下面的语句
archive log list;(该方法需要as sysdba) 2.关闭数据库 SQL> shutdown immediate;
3.启动数据库到mount模式
SQL> startup mount;4.修改数据库为归档模式
SQL> alter database archivelog;
5,打开数据库库
SQL> alter database open;
SQL> SELECT NAME,created,log_mode FROM v$database; NAME CREATED LOG_MODE
--------- --------- ------------
ORCL 04-JUN-12 ARCHIVELOG 6,查看归档日志的路径和目录
SQL> show parameter db_recovery_file_dest; NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string /data/app/oracle/flash_recovery_area
db_recovery_file_dest_size big integer 2G
修改方法:
SQL> alter system set db_recovery_file_dest_size=20g;
SQL> alter system set db_recovery_file_dest='/app/arc';
|
|