Oracle rman backup and restore the database to a point in time at any

 

 

 

Rman backup to physical backup, enable rman backup database archiving must be turned on, after opening the archive database is equivalent to adding a layer of double insurance. Rman data file backup main backup of the database, control files, archive logs.

 

 RMAN Backup

First, check whether the database is enabled archived. Cmd on a server with at sysdba login identity. Query the database archiving mode is enabled.

 

Sqlplus / as sysdba

 

Select dbid,name,log_mode from v$database;

If log_mode in archivelog state represents the state already in the archive.

If you are in noarchivelog mode represents the non-archive , this time need to use sysdba open database archiving capacity, followed by the following steps:

Immediate shutdown ; - close the database instances and

Startup mount; - start an instance, do not open the database

Alter database archivelog; --- change to non-filing archive

 

Alter database open; - Start the database

First,  create the RMAN user, RMAN user table space, authorization, create a recovery catalog, registration database. Steps in sequence as follows:

Create a user data table space:

Create tablespace rman_ts datafile ‘E:\app\Administrator\oradata\ydhldb\rman_ts.dbf’ sise 200M;

Create a user and authorization:

Create user rman identified  by rman tablespace rman_ts temporary tablespace temp;

Grant connect ,recovery_catalog_owner,resource to rman;

Create a recovery directory

Rman catalog rman/rman target ydhldb;

Create catalog tablespace rman_ts;

Next, fit to create batch command RMAN run block, as follows: 
run { 
Backup Database the format ' D: /backup/rman_full_db_%T_%U.dbf ' ; 
Configure controlfile AutoBackup the format for Device to Disk type ' D: /backup/rman_full_conf_%F.ctl ' ; 
Configure window of Retention Policy to Recovery . 7 Days; 
CROSSCHECK BACKUPSET; 
Delete noprompt expired The BACKUPSET; 
Backup SPFILE the format ' D: /backup/rman_full_sp_%T_%U.dbf ' ; 
Backup All the format ARCHIVELOG ' D: /backup/rman_full_arc_%T_%U.dbf ' ; 
CROSSCHECK ARCHIVELOG All;
noprompt ARCHIVELOG All Completed the before the Delete ' sysdate-seven ' ; 
the Delete noprompt Obsolete; 
} 
representing the whole backup data files, control files and archive logs, the longest National Day holiday seven days, it is only seven days backup, and automatically removes 7 backup data before the day. Save the above into Notepad, named backup_rman.rman. Fixed to a reserved path, as shown in FIG. Remain in the C: \ Users \ Administrator \ Desktop \ Rman.

Next, the batch needs to drafting automatically retrieved rman a run block contents. To retain the same path as follows:

set ORACLE_SID=YDHLDB

RMAN TARGET / LOG C:\Users\Administrator\Desktop\Rman\logs\bak_%date%.log CMDFILE=C:\Users\Administrator\Desktop\Rman\backup_rman.rman

This content will be written in a separate batch, the suffix .BAT format. And build logs folder used to store RMAN log during backup. Bat batch has been configured log path. As shown below:

此时即可采用win上的计划任务排程来调用RMAN批处理来备份数据库了,生产库建议一天一备,放于半夜23点执行。 如下图:

设置完成后,即可半夜执行备份数据库。

如图:

备份后:d盘的backup文件夹下生成了备份,如图:

此时备份完成。

 

RMAN还原

 

如果现场数据库故障,出现奔溃,则采用RMAN进行还原。还原时RMAN会自动选择就近的备份去进行还原并且还原时RMAN 会去自动识别备份片及通道。还原过程如图:

还原的时候数据库必须启动到mount状态,在open状态下会报错无法获取队列。

cmd下执行rman target /

Rman 下执行 shutdown immediate;

Startup mount;

Restore database;

 

 

Recover database;

 

 

此时还原完成,开启数据库。

 

 

注意:rman在还原时对应两个操作,数据库修复restore和数据库恢复recoverrestorerecover的区别,先restorerecoverrestore为修复,recover为恢复。

Restore时会利用建立的恢复目录来获取备份信息从而选择去获取备份信息。 Recover是将数据库恢复到奔溃前的状态,采用介质恢复的形式,恢复过程中主要应用归档和redo日志。

 

—————————————————————————RMAN还原数据库到任意一个时间点——————————————————————————————————

1、 启动数据库到mount状态。依次步骤如下:

Shutdown immediate;

Startup mount;

sql "alter session set nls_date_format=''yyyy-mm-dd hh24:mi:ss''";

restore database until time '2018-02-23 14:00:00';

recover database until time '2018-02-23 14:00:00';

sql 'alter database open resetlogs';

 

还原完成。

Guess you like

Origin www.cnblogs.com/tigergaonotes/p/11086673.html