Oracle开启归档模式


1.开启归档


sqlplus>shutdown immediate;(启动归档前先要停止数据库) 


sqlplus>startup mount;(数据库以mount方式启动) 


sqlplus>alter database archivelog;(启动数据库归档) 


sqlplus>alter system set log_archive_dest_1="/arch"(改变归档日志路径)


sqlplus>alter database open;(打开数据库) 


sqlplus>archive log list;(查看归档是否已经打开)


2.关闭归档


alter database noarchivelog;


RMAN 已经成为ORACLE中的最重要的备份恢复工具   catalog    



3.创建catalog所需的表空间


SQL> create tablespace rman_tbs datafile '/u01/oradata/oradata/PROD1/rman_tbs01.dbf' size 100m;

SQL> create user rman identified by rman default tablespace rman_tbs;

SQL> grant connect,resource,recovery_catlog_owner to rman;

linux$ rman catalog rman/rman


RMAN> upgrade catalog;

RMAN> upgrade catalog;

RMAN>register database;



run{


allocate channel d1 type disk;   //分配通道


backup full database             //全备份数据库


include  current controlfile     //包括当前的controlfile


format ‘/home/oracle/ db_%d_%s_%p_%t_%T’;   //备份文件位置和文件格式


relesae channel d1;                          //释放通道


}


backup archivelog all (delete all input);


RMAN恢复


备份完成后,删除/oracle/oradata/oca(目标数据库)目录中的所有文件(相当于数据文件全毁了)。

$su - oracle

$lsnrctl stop

$lsnrctl start

$ORACLE_SID=oca

$sqlplus sys/oracle as sysdba;

>startup nomount #可能要先shutdown abort

>exit

$ORACLE_SID=ocp

$sqlplus sys/oracle as sysdba;

>startup;#可能要先shutdown immediate;

>exit

$rman target sys/oracle@OCA catalog kata/oracle@OCP

可能出错:all appropriate instances are blocking new connections,修改tnsnames.ora,OCA的CONNECT_DATA中添加:(UR=A)

RMAN>list backup; #看看备份是否在

RMAN>restore database;#恢复

RMAN>show all;

RMAN>restore controlfile;

RMAN>alter database mount;

RMAN>alter database open resetlogs