Oracle冷备份脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle冷备份脚本相关的知识,希望对你有一定的参考价值。
一、原理
-
- 冷备份
数据库在关闭状态下完成所有物理系统文件拷贝的过程,也称脱机备份
适合于非归档模式下,数据库处于一致性状态
-
步骤
首先在运行的库中得到数据库运行的所有的物理文件位置,然后在计划内关闭数据库(shutdown)
再执行拷贝物理文家到备份路径或备份设备
备份完成后立即启动数据库让其提供正常的服务
-
总结 - 优点
冷备模式下概念易于理解,即将需要备份的文件复制到安全的位置
操作比较简单,不需要太多的干预
容易恢复到某个时间点上(只需将文件再拷贝回去)
能与归档方法相结合,作数据库“最新状态”的恢复。
-
总结 - 缺点
备份时,数据库必须处于一致性关闭状态
只能提供到某一时间点的恢复
备份时速度比较慢,尤其是数据量大性能影响比较大
不能实现基于表和用户级别的数据恢复
二、案例首先应该在相关视图里查出数据库的数据文件,日志文件,控制文件,临时文件所在的位置。注意:不要直接把oradata下的cp就行了,因为生产库里各个文件通常分布在不同的磁盘,不同的地方,所以在去视图里获得真实路径 。
1).查看数据库是否为CDB
[email protected]>select name, decode(cdb, ‘YES‘, ‘Multitenant Option enabled‘, ‘Regular 12c Database: ‘) "Multitenant Option" , open_mode, con_id from v$database;
NAME Multitenant Option OPEN_MODE CON_ID
NEWTEST Multitenant Option enabled READ WRITE 0
YES表示该数据库是CDB,如果是NO表示是NO-CDB(普通数据库)
2).查看实例和数据库的相关信息
[email protected]>select instance_name,version,status,archiver,database_status from v$instance;
INSTANCE_NAME VERSION STATUS ARCHIVE DATABASE_STATUS
newtest 12.2.0.1.0 OPEN STARTED ACTIVE
[email protected]>select dbid,name,log_mode from v$database;
DBID NAME LOG_MODE
1779551310 NEWTEST ARCHIVELOG
[email protected]>set linesize 180
[email protected]>col guid format A40
[email protected]>col name format A20
[email protected]>select con_id, dbid, guid, name , open_mode from v$pdbs;
CON_ID DBID GUID NAME OPEN_MODE
2 603865257 32CAC9A05E614355926257BE671D9AFC PDB$SEED READ ONLY
3 3394996704 24549D14BBEB417BAB312BF19BC5259E PDBTEST READ WRITE
4 50957894 D4B2FCAAC2B944CC8AF5864EC7CB853C CLONEPDB_PLUG READ WRITE
3). 查看数据文件及状态信息
[email protected]>col file_name format A60
[email protected]>select file_name,tablespace_name,status,online_status from dba_data_files;
FILE_NAME TABLESPACENAME STATUS ONLINE
C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\SYSTEM01.DBF SYSTEM AVAILABLE SYSTEM
C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\SYSAUX01.DBF SYSAUX AVAILABLE ONLINE
C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\UNDOTBS01.DBF UNDOTBS1 AVAILABLE ONLINE
C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\USERS01.DBF USERS AVAILABLE ONLINE
[email protected]>col con_id format 99
[email protected]>col name format A80
[email protected]>select con_id,FILE#,NAME,status,enabled from v$datafile order by 1;
CON_ID FILE# NAME STATUS ENABLED
1 1 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\SYSTEM01.DBF SYSTEM READ WRITE
1 3 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\SYSAUX01.DBF ONLINE READ WRITE
1 5 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\UNDOTBS01.DBF ONLINE READ WRITE
1 7 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\USERS01.DBF ONLINE READ WRITE
2 2 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\PDBSEED\SYSTEM01.DBF SYSTEM READ WRITE
2 4 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\PDBSEED\SYSAUX01.DBF ONLINE READ WRITE
2 6 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\PDBSEED\UNDOTBS01.DBF ONLINE READ WRITE
3 8 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\PDBTEST\SYSTEM01.DBF SYSTEM READ WRITE
3 11 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\PDBTEST\USERS01.DBF ONLINE READ WRITE
3 10 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\PDBTEST\UNDOTBS01.DBF ONLINE READ WRITE
3 9 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\PDBTEST\SYSAUX01.DBF ONLINE READ WRITE
CON_ID FILE# NAME STATUS ENABLED
4 42 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\CLONEPDB_PLUG\UNDOTBS01.DBF ONLINE READ WRITE
4 41 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\CLONEPDB_PLUG\SYSAUX01.DBF ONLINE READ WRITE
4 40 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\CLONEPDB_PLUG\SYSTEM01.DBF SYSTEM READ WRITE
4 43 C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\CLONEPDB_PLUG\USERS01.DBF ONLINE READ WRITE
15 rows selected.
4).查看临时文件
[email protected]>col name format A100
[email protected]>select name from v$tempfile;
NAME
C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\TEMP01.DBF
C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\PDBSEED\TEMP012017-12-13_17-23-31-944-PM.DBF
C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\PDBTEST\TEMP012017-12-13_17-23-31-944-PM.DBF
C:\APP\ADMINISTRATOR\VIRTUAL\ORADATA\NEWTEST\CLONEPDB_PLUG\TEMP012017-12-13_17-23-31-944-PM.DBF
以上是关于Oracle冷备份脚本的主要内容,如果未能解决你的问题,请参考以下文章