ORACLE RMAN backup and recovery of

Advantage RMAN (Recovery Manager) backupset embodiment

1, archive mode, the database can be backed up in the open state, guarantee business 7 * 24

2, without the use of empty blocks is not backed up, reducing the I / O consumption

3, check whether the default database corruption during backup

4, can make incremental backups

5, can achieve various levels of backup, such as database, table space, data files

6, can be restored to the point of failure, or the nearest point in time point of failure, to ensure minimal data loss

RMAN backup retention policy

Oracle outdated backup files are not automatically deleted from the disk, just mark expired, expired files can use RMAN> delete obsolete deleted directly from the disk.

Time-based backup retention policy

Said simply, it is that you want the database can be restored to the earliest days ago, retention time, if there is an incremental backup, the backup file = retention period + level 0 backup interval

For example, every month, that is, 30 days to perform a backup of 0, 1 day to perform a level 1 backup every, if you set the backup retention policy is three days, not to say that all backup files three days ago are out of date, but that we can revert to three days ago.

Understanding: 1 0 backup execution, today is the No. 3 month, to be restored to three days ago, that is to return to No. 30 last month, last month's data is based on the number of 30 last month 0 + 1 month No. backup level 1 daily backup, then 0 days to retain the backup file No. 1 month is 30 + 3 = 33

Copy the backup set

RMAN> CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 2;

- Two backup file is generated when you configure the backup rman

RMAN> backup copies 2  datafile 4 FORMAT '/home/oracle/bak1/%U','/home/oracle/bak2/%U';

- generate two backup files, copy stored in / home / oracle / bak1 directory, copy stored in / home / oracle / bak2 directory

Rman default configuration of backup path

RMAN> configure channel device type disk format '/home/oracle/bak/%U';

If not configured, the default parameters stored in the db_recovery_file_dest path, if not configured db_recovery_file_dest parameter, the default stored in $ ORACLE_HOME / dbs directory

Official Document Path Format string substitution variables https://docs.oracle.com/cd/E11882_01/backup.112/e10643/rcmsubcl010.htm#RCMRF195

% U is most commonly used to generate a unique name for each backup piece

RMAN Backup Types

Mirroring

RMAN> backup as copy datafile 4; - the backup file and the actual file size, as part of a complete copy of the

Backup Set

RMAN> backup as backupset datafile 4; - the backup file is much smaller than the actual file size, empty blocks are not backed up.

Backup set backup sheet

The official document path https://docs.oracle.com/cd/E11882_01/backup.112/e10642/glossary.htm#BRADV526

Generally, a backup set composed of a backup piece, redundancy is provided or the backup file when the backup sheet is limited in size, will have a backup set corresponding to a plurality of backup pieces

Backup piece

backup piece

The physical file format used to store an RMAN backup set. Each logical backup set contains one or more physical backup pieces.

RMAN backup sets for storing a physical file format. Each logical backup set comprises one or more physical backup member.

Briefly, the backup plate, the backup is generated after a physical file, a backup sheet which may contain one or more datafile.

A backup set is a logical concept

backup set

A backup of one or more data files, control files, server parameter files, and archived redo log files. Each backup set consists of one or more binary files. Each binary file is called a backup piece. Backup pieces are written in a proprietary format that can only be created or restored by RMAN.

One or more data files, control files, server parameter file backup and archived redo log files. Each backup set of one or more binary files. Each binary files called backup pieces. Backup piece is written in a proprietary format that can only be created or restored by RMAN.

By default, the backup sets and backup sheet is one to

RMAN> backup database format '/home/oracle/1data%U';

select * from v$backup_set

select * from v$backup_piece

When setting the size of a backup set, backup sets and backup sheet-many

RMAN> CONFIGURE MAXSETSIZE clear;

RMAN> run

2> {allocate channel c1 device type disk maxpiecesize 1000M;

3> backup database format '/home/oracle/2data%U';

4> }

select * from v$backup_set

select * from v$backup_piece

Incremental Backup

Levels 0-4, and the default is the difference between an incremental backup.

Even without 0 backup, directly in Level 1 or Level 2 backups automatically to be 0 backup.

RMAN> backup incremental level 2 database format '/home/oracle/bak/%U';

Starting backup at 24-MAY-18

using target database control file instead of recovery catalog

allocated channel: ORA_DISK_1

channel ORA_DISK_1: SID=32 device type=DISK

no parent backup or copy of datafile 1 found

no parent backup or copy of datafile 2 found

no parent backup or copy of datafile 5 found

no parent backup or copy of datafile 3 found

no parent backup or copy of datafile 4 found

channel ORA_DISK_1: starting incremental level 0 datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/orcl/system01.dbf

input datafile file number=00002 name=/u01/app/oracle/oradata/orcl/sysaux01.dbf

input datafile file number=00005 name=/u01/app/oracle/oradata/orcl/example01.dbf

input datafile file number=00003 name=/u01/app/oracle/oradata/orcl/undotbs01.dbf

input datafile file number=00004 name=/u01/app/oracle/oradata/orcl/users01.dbf

channel ORA_DISK_1: starting piece 1 at 24-MAY-18

channel ORA_DISK_1: finished piece 1 at 24-MAY-18

piece handle=/home/oracle/bak/1at3lltr_1_1 tag=TAG20180524T024722 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:01:24

channel ORA_DISK_1: starting incremental level 2 datafile backup set

channel ORA_DISK_1: specifying datafile(s) in backup set

input datafile file number=00006 name=/u01/app/oracle/oradata/orcl/users02.dbf

input datafile file number=00007 name=/u01/app/oracle/oradata/orcl/users03.dbf

input datafile file number=00008 name=/u01/app/oracle/oradata/orcl/cataspace.dbf

channel ORA_DISK_1: starting piece 1 at 24-MAY-18

channel ORA_DISK_1: finished piece 1 at 24-MAY-18

piece handle=/home/oracle/bak/1bt3lm0g_1_1 tag=TAG20180524T024722 comment=NONE

channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03

Finished backup at 24-MAY-18

Starting Control File and SPFILE Autobackup at 24-MAY-18

piece handle=/home/oracle/bak/c-1498036209-20180524-00 comment=NONE

Finished Control File and SPFILE Autobackup at 24-MAY-18

No. 1 for as long as the data file is a data file SYSTEM table space to do backups, even if the automatic backup control file is not open, RMAN will automatically make a backup of the control file.

So when backing up the database, it will automatically back up control file because the database contains data files No. 1.

RMAN> catalog backuppiece ''

If you rebuild the control file, which backup information is lost, then, even without the use of catalog database, you can use the catalog command to register the backup file to the control file.

View the progress of a backup SQL statement

SELECT SID, SERIAL#, opname,ROUND(SOFAR/TOTALWORK*100)||'%' "%_COMPLETE",

TRUNC(elapsed_seconds/60) || ':' || MOD(elapsed_seconds,60) elapsed,

TRUNC(time_remaining/60) || ':' || MOD(time_remaining,60) remaining,

CONTEXT,target,SOFAR, TOTALWORK

FROM V$SESSION_LONGOPS

WHERE OPNAME LIKE 'RMAN%'

AND OPNAME NOT LIKE '%aggregate%'

AND TOTALWORK != 0

AND SOFAR <> TOTALWORK;

restore: restore the data files from the backup set to restore them

recover: recovery, use archive logs or online journals recovery

--restore default control file restore from a recent backup package, if there is no new, second to find new, if the second new does not exist, to find new third, and so on, if you have a not on the error

--restore there until time, it is provided with the latest backup until time range of packages, such as backup packages 3, are 1: 2:00: 00,3: 00, if the UNTIL TIME "TO_DATE ( '2:30: 00 ',' hh24: mi: ss') ", that is, using the latest package in the range of 2:30, that is the backup package 2:00

Non-filing mode can be used rman backup, but only in mount mode, no practical significance

[oracle@ocp ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Tue May 15 01:54:08 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1498036209)

RMAN> backup datafile 6;

ORA-19602: cannot backup or copy active file in NOARCHIVELOG mode

[oracle@ocp ~]$ rman target /

Recovery Manager: Release 11.2.0.3.0 - Production on Tue May 15 01:55:31 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database: ORCL (DBID=1498036209, not open)

RMAN> backup datafile 6;

Finished backup at DD-MAY-YY

The most comprehensive and concise script backup and recovery methods:

RMAN>CONFIGURE CONTROLFILE AUTOBACKUP ON;

RMAN>CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/bak/%F';

RMAN>backup database format '/home/oracle/bak/datafile%U' plus archivelog format '/home/oracle/bak/arch%U' delete all input;

The above script to back up the steps

1, archive, and then back up the archive logs, delete the archive logs that were backed up

2, backup database file

3, archiving, and then back up the archive logs, delete the archive logs that were backed up

4, the backup control files and parameter files

delete all input - delete all archived logs in the path

delete input - delete a log file path under

Assuming that all files are missing, the recovery steps

1, restore the spfile

rman target /

RMAN> startup nomount;

RMAN> restore spfile from 'XX';

2, start the database to the state nomount

sqlplus / as sysdba

SQL> shutdown abort;

SQL> startup nomount;

3, restore the control file

rman target /

RMAN> restore controlfile from '/home/oracle/bak/c-2876937480-20180819-00';

4, start the database to mount state

sqlplus / as sysdba

SQL> alter database mount;

5, restore the database, recover incomplete recovery database

RMAN> restore database;

RMAN> recover database; - This procedure except that the log file has been backed up, but will not use the backup archive logs generated after the backup is completed

RMAN> recover database until sequence XX; - sequence on XX-step recover database using prompted required

6, start the database to the open state, use resetlogs

sqlplus / as sysdba

SQL> alter database open resetlogs;

rman's advisor tool

Rman> List failure; - show the number of abnormal file

Rman> Advise failure; - displays the details of the file needs to be restored

Rman> Repair failure preview; - show the need to restore the operation of the script, and the script is stored under a path to, (knock when no report about the Validate database, and then come back again List failure \ Advise failure)

Rman> Repair failure; - a recovery operation

A backup file, and then shut down, and then delete the file, and then start to mount, perform the above sequence of operations can be resumed

VALIDATE command set and a single backup support for the data block verification. In physical damage, the database can not identify the block. In the logical corruption, the contents of the block logically inconsistent. By default, VALIDATE command checks only the physical damage. You can also specify CHECK LOGICAL corruption checking logic.

Damaged block can be divided between blocks and damage damaged block.

Damage within the block, the block itself is damaged, it can be physical or logical damage damaged.

In the inter-block is damaged, the damage occurs between the blocks can only be logical corruption.

VALIDATE command checks only the damaged blocks.

https://docs.oracle.com/cd/E11882_01/backup.112/e10642/glossary.htm#BRADV526

Inter damaged block interblock corruption

A type of block corruption in which the corruption occurs between blocks rather than within the block itself. This type of corruption can only be logical corruption.

intrablock the damaged block corruption

A type of block corruption in which the corruption occurs within the block itself. this type of corruption can be either a physical corruption or logical corruption.

RMAN> VALIDATE DATABASE; - checking physical bad blocks, only the operation check

RMAN> VALIDATE CHECK LOGICAL DATABASE; - bad blocks checking logic, operation check only

or

RMAN> BACKUP VALIDATE DATABASE; - checking physical bad blocks, not only checks the backup

RMAN> BACKUP VALIDATE CHECK LOGICAL DATABASE; - bad blocks checking logic, not only checks the backup

RMAN> BACKUP DATABASE; - no VILIDATE, do denotes a backup operation, while checking the physical backup bad blocks, bad blocks when a physical examination default RMAN backups

RMAN> BACKUP CHECK LOGICAL DATABASE; - no VILIDATE, do denotes a backup operation, the backup logic while checking for bad blocks

catalog of official document path https://docs.oracle.com/cd/E11882_01/backup.112/e10642/rcmcatdb.htm#BRADV8015

Nocatalog is to record information control file backup control file

If you use nocatalog way

Retention time of backup files = retention period + level 0 backup interval

Control file records retention time

Control_file_record_keep_time = retention time of backup files +1

For example, every month, that is, 30 days to perform a backup of 0, 1 day to perform a level 1 backup every, if you set the backup retention policy is three days, that we may be restored to the three days ago.

The control file is recorded Number of days to 30 + 3 + 1 = 34

CATALOG steps to create and use

1. Create a table space

SQL> create tablespace cataspace datafile '/u01/app/oracle/oradata/ocp/cataspace.dbf' size 10M autoextend on;

2. Create a user

SQL> create user catauser identified by oracle default tablespace cataspace;

3. User authorization must be recovery_catalog_owner

SQL> grant connect,resource,recovery_catalog_owner to catauser;

4.RMAN login CATALOG, and create CATALOG

[oracle@ocp ~]$ rman catalog catauser/oracle

RMAN> create catalog;

5.RMAN Log database and CATALOG, and registration database to the CATALOG, and use.

[oracle@ocp ~]$ rman target / catalog catauser/oracle

RMAN> register database;

RMAN> backup datafile 7;

Reproduced in: https: //www.jianshu.com/p/f2ab6f2fd63b

Guess you like

Origin blog.csdn.net/weixin_34268579/article/details/91241532