Oracle RMAN backup and recovery supplementary knowledge

RMAN recovery considerations

  1. Plan and implement the plan in advance, and formulate recovery guidance documents for various scenarios;
  2. Before RMAN recovers, on-site protection must be done to avoid secondary injuries;

RMAN recovery method description

RMAN data recovery has two processes:

  1. RESTORE
    restores the data file from the backup location on tape, disk or other media to the specified location (disk, ASM, etc.), and makes it available for database server access.

  2. RECOVER
    will reapply the changes since the backup in the archive log ArchiveLog and online redo log RedoLog to the file to restore the database to the required point in time or SCN location.

※ SCN => system change number

RMAN recovery classification description

  1. Complete database recovery is to restore to the state before the failure occurs. All submitted operations are restored to ensure that the database does not lose any data. Complete recovery is only used in archive mode.

  2. Incomplete database recovery is to restore the database to the state at a certain moment between the backup point and the point of media failure. It does not restore all submitted operations. Incomplete recovery may lose some data .

Any type of recovery includes two phases: a roll-forward phase and a roll-back (rollback) phase.

  • In the roll-forward recovery phase (roll-forward recovery), the recovery manager applies the necessary transaction log group to "redo" (REDO) all committed transactions that are not in the database data file.

  • In the rollback phase, after roll-forward recovery, Oracle must perform roll-back recovery. Because the modification information of some unfinished transactions to the database has been submitted to the database, in order to ensure the consistency of the database, it is necessary to clear the modification of the database by these transactions. The database should perform a rollback operation (UNDO) to forcefully cancel these unfinished transactions.
    Insert picture description here

After RMAN is not fully recovered, how to recover again?

When RMAN recovers, sometimes it is found that the recovered state is not the data we expect. At this time, if you perform the recovery again, you will find that Archivelog and redo are no longer available. At this point, we must set the correct incarnation value, refer to the following:
RMAN> list incarnation;

DB 关键字  Inc 关键字 DB 名  DB ID            STATUS  重置 SCN  重置时间
------- --------------- ---------------- ------------- ----------
1       1       ORCL     1295249725       PARENT  6401206    19-2月 -12
2       2       ORCL     1295249725       PARENT  6403536    19-2月 -12
3       3       ORCL     1295249725       PARENT  6404158    19-2月 -12
4       4       ORCL     1295249725       CURRENT 6406181    19-2月 -12

Operation steps:
(1) Start but do not load the instance. This is because we need to get a control file associated with the restored database counterpart.
(2) Use the reset database to incarnation command to indicate the backup set of the counterpart to RMAN.
(3) Restore controlfile to enable rman to restore the latest control file
(4) Load the database
(5) Restore the database
(6) Restore the database
(7) Use resetlogs to open the database

Reference command:

run {
    
    
reset database to incarnation 3;
set until scn SCNNumber
restore database;
recover database;
alter database open resetlogs;
}

The difference between RMAN's CATALOG and NOCATALOG

  • The catalog method must first create a catalog backup database and establish a recovery catalog.

  • The nocatalog method is to use the control file as the catalog. For each backup, a lot of backup information must be written to the control file, and there will be more and more backup information in the control file. By default, the control file saves the record information of the last 7 days, refer to the following:

alter system set control_file_record_keep_time=21 scope=both;

If the time of the RMAN file is exceeded, then you will need to re-register to the CATALOG information.
catalog start with'D:\RMANBACKUP';

RMAN backup optimization method

  • LARGE_POOL_SIZE area increases
# 查询LARGE_POOL_SIZE容量
SELECT nvl(name, 'large_pool') name,
       round(SUM(bytes) / 1024 / 1024, 2) size_mb
  FROM V$SGASTAT
 WHERE pool = 'large pool'
 GROUP BY ROLLUP(name);
# 设置LARGE_POOL_SIZE容量
alter system set large_pool_size = 400M scope=both;
  • RMAN parameter optimization
# 默认值为关闭,如果打开,rman将对备份的数据文件及归档等文件进行一种优化的算法。
CONFIGURE BACKUP OPTIMIZATION ON;
# 配置数据库设备类型的并行度。
CONFIGURE DEVICE TYPE DISK PARALLELISM 4;
# 配置备份集压缩的方式,默认是BZIP2。压缩模式参考V$RMAN_COMPRESSION_ALGORITHM
# 此参数需要注意不同版本,支持的方式可能不一样必须要先确认再设置
configure compression algorithm 'MEDIUM';
  • Enabling the Block Change Tracking function
    In the system, the BCT (Block Change Tracking) function is disabled by default. When the shared function is enabled, the relevant information will be recorded in the file whenever the data block changes. This way, when RMAN performs incremental backups, there is no need to completely traverse the entire data file to find the data block that needs to be backed up, which greatly Improve the efficiency of backup.
# 检查状态
select * from v$block_change_tracking;
# 启用命令
alter database enable block change tracking using file 'e:\RMANBackup\BlockChangeTracking.trc';
# 关闭命令
alter database disable block change tracking;

RMAN file format parameters

parameter Description
%c Number of copies of backup piece
%d Name database
%D The day of the month (DD)
%M In the month of the year (MM)
%F A unique name based on DBID, the format of this format is c-IIIIIIIIII-YYYYMMDD-QQ, where IIIIIIIIII is the DBID of the database, YYYYMMDD is the date, and QQ is a sequence of 1-256
%n Database name, padded to the right to a maximum of eight characters
% u An eight-character name represents the backup set and creation time
%p Number of backup pieces in the backup set, starting from 1 to the number of files created
% U A unique file name, representing %u_%p_%c
%s Number of the backup set
%t Backup set timestamp
%T Year, month and day format (YYYYMMDD)

RMAN backup and recovery progress query

set line 9999
set pages 500
col opname for a30
col start_time for a19
SELECT SID, SERIAL#,opname, to_char(start_time,'yyyy-mm-dd HH24:MI:SS')  start_time, SOFAR, TOTALWORK,
       ROUND(SOFAR/TOTALWORK*100,2) "%COMPLETE",ceil(ELAPSED_SECONDS/60) ELAPSED_MI
FROM V$SESSION_LONGOPS
where opname like 'RMAN%' and totalwork!=0 and sofar!=totalwork order by start_time asc;

RMAN common recovery commands

  • SPFILE parameter file
SHUTDOWN IMMEDIATE;
STARTUP NOMOUNT;
RUN{
    
    
SET DBID=1540861503;
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'D:\RMANBACKUP\%F';
ALLOCATE CHANNEL CH1 TYPE  DISK;
RESTORE SPFILE FROM AUTOBACKUP;
RELEASE CHANNEL CH1 ;
}
  • CONTROL control file
SHUTDOWN IMMEDIATE;
STARTUP NOMOUNT;
RUN{
    
    
SET DBID=1540861503;
SET CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO 'D:\RMANBACKUP\%F';
ALLOCATE CHANNEL CH1 TYPE  DISK;
RESTORE CONTROLFILE FROM AUTOBACKUP;
RELEASE CHANNEL CH1 ;
}
  • Complete data recovery
STARTUP MOUNT; 
RUN{
    
    
RESTORE DATABASE;
RECOVER DATABASE;
}
sql 'alter database open read only'; # 检查恢复数据状态
# SQL 'ALTER DATABASE OPEN RESETLOGS';
  • Time-based recovery
STARTUP MOUNT; 
RUN{
    
    
set until time "to_date('2018-08-15 15:45:00','yyyy-mm-dd hh24:mi:ss')";
RESTORE DATABASE;
RECOVER DATABASE;
}
sql 'alter database open read only'; # 检查恢复数据状态
# SQL 'ALTER DATABASE OPEN RESETLOGS';
  • Based on SCN recovery
STARTUP MOUNT;
RUN{
    
    
ALLOCATE CHANNEL D1 TYPE DISK;
RESTORE DATABASE UNTIL SCN 1317011;
RECOVER DATABASE UNTIL SCN 1317011;
RELEASE CHANNEL D1;
sql 'alter database open read only'; # 检查恢复数据状态
# SQL 'ALTER DATABASE OPEN RESETLOGS';
}
  • Log-based recovery
STARTUP MOUNT; 
RUN {
    
    
SET UNTIL SEQUENCE 120 THREAD 1;
RESTORE DATABASE;
RECOVER DATABASE; --recovers through log 119 not include 120
sql 'alter database open read only'; # 检查恢复数据状态
# SQL 'ALTER DATABASE OPEN RESETLOGS';
}
  • Cancellation based recovery
STARTUP MOUNT; 
RUN {
    
    
RESTORE DATABASE;
RECOVER DATABASE UNTIL CANCEL;  # 它将恢复数据库直到找不到日志文件
sql 'alter database open read only'; # 检查恢复数据状态
# SQL 'ALTER DATABASE OPEN RESETLOGS';
}

Guess you like

Origin blog.csdn.net/weixin_38623994/article/details/105970897