RMAN backup and recovery instance

Source: Internet
Author: User

1. Check the database mode:
Sqlplus/nolog
Conn/As sysdba
Archive log list (check whether the database is in archive Mode)

If not, the database archive mode is modified.
Startup Mount
Alter database archivelog
Alter database open

2. connect to the target database

Command: connect target/(connect target system/Oracle @ ora10g. If the database does not exist, run the RMAN command to start the database using startup)
You can connect to the target database. (RMAN connects to the target database, control file (nocatalog mode), and control file stores the backup information of RMAN)

3. Run the list backupset command to check whether there are any backup items.

4. Common backup commands:
Backup full database:
RMAN> Backup Database Plus archivelog Delete input; (back up full-database and control files, server parameter files, and all archived redo logs, and delete old archive logs)
Backup tablespace:
RMAN> Backup tablespace system plus archivelog Delete input; (backup the specified tablespace and archived redo logs, and delete the old archived logs )_
Back up archived logs:
RMAN> Backup archivelog all Delete input;

=============================================== Back up the entire database =====

1. Full backup of the entire database ).

Just enter the command: backup database;

2. List backupset to view the specific backup information

List of backup Sets
==============================

BS key Type LV Size Device Type elapsed time completion time
-------------------------------------------------------------
1 full 6.80 m disk 00:00:02 06-dec-08
BP key: 1 Status: available compressed: No tag: tag20081206t201041
Piece name:/home/Oracle/flash_recovery_area/ora10g/backupset/2008_12_06/o1_mf_ncsnf_tag20081206t201041_4mntz78s _. bkp
Control file included: ckp scn: 782019 CKP time: 06-dec-08
Spfile encoded ded: modification time: 06-dec-08

BS (backupset), piece is a file, and a BS contains multiple piece.

3. The default parameters in RMAN can be shown all;
In the backup database command, we can replace these default values with fixed values.

4. we can copy the backup files to the tape directory, and then delete the backup files under the Backup Directory. If you need to recover the files next time, just copy the file back to the backup directory.
5. view the backup information in the control file (because the backup is in nocatalog mode), and the control file is in the/u01/Oracle/oradata/ora10g directory, since the control file is a binary file, to view the content in the control file, use strings control03.ctl to find that control03.ctl contains the RMAN backup information.

 
=============================== 0-level Incremental Backup ========================

Concept: Full backup and zero-level Incremental backup. Full backup and zero-level Incremental Backup are almost the same. The only difference is that level 0 Incremental Backup can be used as the basis for Incremental backup, while full backup cannot be used as the basis for Incremental backup. Completely consistent with other aspects

1. Backup incremental level = 0 (leve 0) database; (backup with an incremental value of 0)
2. Backup incremental Level 1 (Level = 1) database; (Incremental backup of 1)
 
In the preceding backup, we have backed up datafile, controlfile, and parameter file. archive logs exist for files not backed up, redo logs and password files are not backed up. password files do not need to be backed up. We use orapw to create

The new password file. RMAN cannot be backed up in nocatalog mode for redo log files.

=========================== Backup archivelog in nocatalog mode ===================== =

Command: Backup Database Plus archivelog Delete input (delete input means to delete the archivelog file after the backup is complete. This option is optional, this command can also be used to backup incremental level = 0 (1, 2 ...))

=========================================Backup tablespace =====

Backup tablespace tablespacename

If you do not know the name of tablespace, you can use the report schema command in RMAN to view the name of the tablespace.

Man> report Schema;
Report of database schema

List of permanent datafiles
======================================
File size (MB) tablespace RB segs datafile name
---------------------------------------------------------------
480 system ***/home/Oracle/oradata/ora10g/system01.dbf
2 25 undotbs1 ***/home/Oracle/oradata/ora10g/undotbs01.dbf
3 250 sysaux ***/home/Oracle/oradata/ora10g/sysaux01.dbf
4 5 Users ***/home/Oracle/oradata/ora10g/users01.dbf
5 200 perfstat ***/home/Oracle/oradata/ora10g/perfstat. DBF

List of temporary files
======================================
File size (MB) tablespace maxsize (MB) tempfile name
---------------------------------------------------------------
1 20 temp 32767/home/Oracle/oradata/ora10g/temp01.dbf

 

==================================== Backup control file ============== ========

Backup current controlfile

Backup database include current controlfile

 

====================================== Backup image ============

There are two backup methods in RMAN: Backup set and image copies. Image backup is mainly a copy of a file: Copy datafile......

In RMAN> report Schema;

Report of database schema

List of permanent datafiles
======================================
File size (MB) tablespace RB segs datafile name
---------------------------------------------------------------
480 system ***/home/Oracle/oradata/ora10g/system01.dbf
2 25 undotbs1 ***/home/Oracle/oradata/ora10g/undotbs01.dbf
3 250 sysaux ***/home/Oracle/oradata/ora10g/sysaux01.dbf
4 5 Users ***/home/Oracle/oradata/ora10g/users01.dbf
5 200 perfstat ***/home/Oracle/oradata/ora10g/perfstat. DBF

List of temporary files
======================================
File size (MB) tablespace maxsize (MB) tempfile name
---------------------------------------------------------------
1 20 temp 32767/home/Oracle/oradata/ora10g/temp01.dbf

 

RMAN> copy datafile 5 to '/u01/rmanbak/tbso1bak. dbf'; (copy 5's schme: perfstat. DBF)

 

It uses TBS as a copy. We can use list backupset to check the tbs01bak. DBF we just backed up, because it is not a backupset. We can use list copy to view the files we just backed up.

 
================================== Single command and batch command ================== =====

Single command: backup database;

Batch command:

RMAN> run {
2> allocate channel cha1 type disk;
3> Backup
4> Format '/u01/rmanbak/full _ % t'
5> tag full-Backup // tag can be started by the way, it doesn't matter
6> database;
7> release channel cha1;
8>}

This run contains three commands separated by semicolons.

Format:
% C: number of copies of the backup slice (starting from 1 );
% D: Database Name;
% D: number of days in the month (dd );
% M: month in the year (mm );
% F: a unique name based on dbid, in the form of C-xxx-YYYYMMDD-QQ, where xxx bits the database's dbid, yyyymmdd is the date, QQ is a sequence of 1;
% N: database name, which is filled with X characters on the right side to keep it 8 characters long;
% U: an 8-character name consisting of the Backup set number and the creation time after compression. You can use % u to generate a unique name for each backup set;
% P: ID of the backup part in the backup set, starting from 1;
% U: % u _ % P _ % C, which can be used to generate a unique name for each backup segment (both disk files, this is the most common naming method;
% T: The timestamp of the Backup set;
% T: yyyymmdd );

Channel concept: a channel is a connection between RMAN and the target database. The "allocate channel" command starts a server process in the target database, and the server process must be defined to perform backup and recovery operations.

I/O type used

The channel control command can be used:
Controls OS resources used by RMAN
Affect degree of Parallelism
Specify the I/O bandwidth limit (set the limit read rate parameter)
Specify the size limit of the backup slice (set limit Kbytes)
Specify the limit of the currently opened file (set limit maxopenfiles)

 
============================================ Typical one-week backup solution for RMAN = ======================================

1. Sunday evening-level 0 backup completed MED (full backup)
2. Monday evening-Level 2 backup completed MED
3. Tuesday evening-Level 2 backup completed MED
4. Wednesday evening-Level 1 backup completed MED
5. Thursday evening-Level 2 backup completed MED
6. Friday evening-Level 2 backup completed MED
7. Sat night-Level 2 backup completed MED

 
If you need to recover on Tuesday, you only need 1 + 2,
If you need to recover on Thursday, you only need 1 + 4,
If you need to recover the service on Friday, you only need 1 + 4 + 5,
If it needs to be restored on Saturday, it only needs 1 + 4 + 5 + 6.

 

Automatic Backup: backup script + crontab
Bakl0
Bakl1
Bakl2

Run the script:
RMAN target/msglog = bakl0.log prepare file = bakl0 (/indicates the target database to be connected, msglog indicates the log file, and audit file indicates the script file)
RMAN target/msglog = bakl1.log prepare file = bakl1
RMAN target/msglog = bakl2.log partition file = bakl2

Instance: RMAN target system/Oracle @ ora10g (/) msglog =/u01/rmanbak/bakl1.log prepare file =/u01/rmanbak/bakl0

Complete command:/u01/Oracle/product/10.2.0/bin/RMAN target system/Oracle @ ora10g (/) msglog =/u01/rmanbak/bakl1.log prepare file =/u01/rmanbak/bakl0

 
Put the backup script under the/u01/rmanbak/Script directory. The contents of VI bakl0 and bakl0 are:

Run {
Allocate channel cha1 type disk;
Backup
Incremental level 0
Format '/u01/rmanbak/inc0 _ % u _ % t)
Tag monday_inc0 // The tag can be used by the way. It doesn't matter.
Database;
Release Channel cha1;
}
. Similarly, you can write the corresponding bakl1 and bakl2 scripts.

 
Automatic Backup
Crontab
Crontab-e-u Oracle (changing the command means editing the scheduled execution of oracle users (-E, edit-u Oracle, oracle users ))

Hour, day, month, week (0 represents Sunday)
45 23 ** 0 RMAN target/msglog = bakl0.log prepare file = bakl0 (the command will be executed as an oracle user at on Sunday)
45 23 ** 1 RMAN target/msglog = bakl2.log prepare file = bakl2
45 23 ** 2 RMAN target/msglog = bakl2.log prepare file = bakl2
45 23 ** 3 RMAN target/msglog = bakl1.log prepare file = bakl1
45 23 ** 4 RMAN target/msglog = bakl2.log prepare file = bakl2
45 23 ** 5 RMAN target/msglog = bakl2.log prepare file = bakl2
45 23 ** 6 RMAN target/msglog = bakl2.log prepare file = bakl2

 

Then start crontab and start the crontab command:
Root> service crond restart

===================================== RMAN recovery ====================== =

In non-catalog mode, the backup information is stored in the controlfile file. If the controlfile file is destroyed, it cannot be recovered,
The controlfile must be automatically backed up during Backup.
 
RMAN> show all;
Using target database control file instead of recovery catalog
RMAN configuration parameters are:
Configure retention policy to redundancy 1; # default
Configure backup optimization off; # default
Configure Default device type to disk; # default
Configure controlfile autobackup off; # default
Configure controlfile autobackup format for device type disk to '% F'; # default
Configure device type disk parallelism 1 Backup Type to backupset; # default
Configure datafile backup copies for device type disk to 1; # default
Configure archivelog backup copies for device type disk to 1; # default
Configure maxsetsize to unlimited; # default
Configure encryption for database off; # default
Configure encryption algorithm 'aes128 '; # default
Configure archivelog deletion policy to none; # default
Configure snapshot controlfile name to '/home/Oracle/product/10.20/dbs/snapcf_ora10g.f'; # default

Configure controlfile autobackup off; no autobackup is performed on controlfile. To use this function, run the following command to automatically back up controlfile:
RMAN> Configure controlfile autobackup on;

RMAN> show all;

Manual backup control file:
Backup current controlfile

Dbid indicates an ID of the database, which will be used to restore spfile and controlfile in the future.
RMAN> connect target/
Connected to target database: ora10g (dbid = 3988862108)
This dbid = 3988862108
 

RMAN> List backup; view previous backup information
RMAN> Delete backupset 24; // 24 indicates the number of the backupset.
RMAN> Backup format'/u01/rmanbak/full _ % T _ % u. Bak 'Database Plus archivelog; (perform a full backup)

Verify backup:
RMAN> validate backupset 3; // 3 indicates the number of the backupset.

 

Password File loss (not in the scope of RMAN backup), we only need to use a command to recreate this file:
Orapw file = orapwsid Password = pass entries = 5; // path of the password file:/u01/Oracle/product/10.20/db_1/dbs
Oracle> Cd/u01/Oracle/product/10.20/db_1/dbs
Oracle> RM orapwora10g; (File Deletion, simulated loss)
Oracle> orapwd file = orapwora10g Password = Oracle entries = 5; (create a new file), entries meaning (DBA users can have up to 5)

 

 

Spfile loss:
Startup nomount;
Set dbid 3988862108;
Restore spfile from autobackup;
Shutdown immediate;
Set dbid 3988862108;
Startup;

 

Simulated operation:
Oracle> MV spfileora10g. ora spora10g. ora
Oracle> RMAN target /;
RMAN> shutdown immediate;
RMAN> startup nomount;
Startup failure: ORA-01078: Failure in Processing System Parameters
LRM-00109: cocould not open parameter file '/home/Oracle/product/10.20/dbs/initora10g. ora'
RMAN> set dbid 3988862108;
RMAN> restore spfile from autobackup;

Run this command. If it is not found, the file path may be incorrect.
RMAN> restore spfile from '/u01/Oracle/flash_recovery_area/ora10g/autobackup/2008_12_09/o1_mf_s_673025706_4mw7xc79 _. bkp

Generate the spfileora10g. ora file in the dbs/directory. Prove that spfile has been restored

RMAN> shutdown immediate;
RMAN> startup; (if the command cannot start the database, set dbid 3988862108 is required)

Controlfile loss:
Startup nomount;
Restore controlfile from autobackup;
Alter database Mount;
Recover database;
Alter database open resetlogs;

Note: When alter database open resetlogs is executed, the online redelog file is cleared and the data file is lost. Therefore, a full backup is required.

Oracle> RM *. CTL
Oracle> RMAN target/; // cannot connect to RMAN because controlfile is lost
Oracle> sqlplus/nolog;

SQL> shutdown immediate; // The shutdown fails because the controlfile is lost.
SQL> shutdown abort;

Oracle> RMAN target /;

RMAN> startup nomount;
RMAN> restore controlfile from autobackup;
RMAN> alter database Mount;
RMAN> alter database open resetlogs;

RMAN-00571: ========================================================== ==============================
RMAN-00569: ==================== error message stack follows ==========================
RMAN-00571: ========================================================== ==============================
RMAN-03002: failure of alter dB command at 16:21:13
ORA-01194: File 1 needs more recovery to be consistent
ORA-01110: Data File 1: '/home/Oracle/oradata/ora10g/system01.dbf

// Error. The SCN of the redo log is recorded in the controlfile. Because we have a new controlfile, we need resetlogs;
 
/*
The resetlogs command indicates the end of the logical lifetime of a database and the start of the logical lifetime of another database. each time you use the resetlogs command, the SCN will not be reset, But Oracle will reset the log serial number and reset

Online redo log Content.
This is done to prevent conflicts in the log sequence after Incomplete recovery (because there is a time difference between the existing log and data files ).
*/
RMAN> recover database;
RMAN> alter database open resetlogs;

Redolog file loss: (the following statements must be executed in sqlplus rather than RMAN)
(Sqlplus/nolog)
1. Shutdown immediate;
2. startup Mount;
3. Recover database until cancel; (Media recovery)
4. Alter database resetlogs;

 

Data File loss (execute an SQL statement in RMAN and enclose the SQL statement in double quotation marks ):
1. SQL "alter database datafile 3 offline ";
2. Restore datafile 3
3. Recover datafile 3
4. SQL "alter database datafile 3 online ";

 

Tablespace loss:
1. SQL "alter tablespace users offline"; // if the file does not exist, use SQL "alter tablespace users offline immeidate ";
2. Restore tablespace users;
3. Recover tablespace users; // consistent with the online redolog File Information
4. SQL "alter tablespace users online ";

 

Non-catalog mode full recovery

Database problems:

1. startup nomount;
2. Restore controlfile from autobackup;
3. Alter database Mount;
4. Restore database;
5. Recover database;
6. Alter database open resetlogs;

 

Simulated operation:
Oracle ora10g> RM *;
Oracle ora10g> ls;
Oracle ora10g> // data file. Delete all control files.

Oracle ora10g> RMAN target/; // unable to connect to RMAN due to the loss of controlfile
Oracle ora10g> sqlplus/nolog;
Oracle ora10g> connect/As sysdba;
Oracle ora10g> shutdown abort;
Oracle ora10g> RMAN target/

 

RMAN> startup nomount;
RMAN> restore controlfile from autabackup;
RMAN> alter database Mount;
RMAN> Restore database;
RMAN> recover database; // online redolog does not exist

SQL> recover database until cancel; // when the redo log is lost, the database does not allow the recover operation by default. How can this problem be solved?
SQL> Create pfile from spfile;

VI/u01/product/10.20/dbs/initora10g. ora, add
*. Allow_resetlogs_uption = 'true'; // allow resetlog uption

 
SQL> shutdown immediate;
SQL> startup pfile = '/u01/product/10.20/dbs/initora10g. ora' Mount;
SQL> alter database open resetlogs;

 

Recovery based on time points:
Run {
Set until time "to_date (07/01/02 15:00:00 ', 'Mm/DD/yy hh24: MI: ss ')";
Restore database;
Recover database;
Alter database open resetlogs;
}

Alter session set nls_date_format = 'yyyy-MM-DD hh24: MI: ss ';
1. startup Mount;
2. Restore database until time "to_date ('2017-7-19 13:19:00 ', 'yyyy-MM-DD hh24: MI: ss ')";
3. Recover database until time "to_date ('2017-7-19 13:19:00 ', 'yyyy-MM-DD hh24: MI: ss ')";
4. Alter database open resetlogs;

 

If open resetlogs exists, they are all incomplete recovery.

 

SCN-based recovery:
1. startup Mount;
2. Restore database until SCN 10000;
3. Recover database until SCN 10000;
4. Alter database open resetlogs;

Log sequence-based recovery:
1. startup Mount;
2. Restore database until sequence 100 thread 1; // 100 is the log Sequence
3. Recover database until sequence 100 thread 1;
4. Alter database open resetlogs;

Log sequence query command: SQL> select * from V $ log; where there is a sequence field. resetlogs, the sequence is set to 1

==================================== Backup and restore ================================

1. Create the tablespace required by catalog
SQL> Create tablespace rman_ts size datafile '/u01/Oracle/oradata/ora10g/rmants. dbf' 20 m;
 

2. Create and authorize the RMAN user
SQL> create user RMAN identified by RMAN default tablespace rman_ts quota unlimited on rman_ts;
SQL> grant recovery_catalog_owner to RMAN; (grant connect to RMAN)

 
View the permissions of a role: Select * From dba_sys_privs where grantee = 'recovery _ catalog_owner ';
(Recover_catalog_owner, connect, resource)

3. Create a recovery directory
Oracle> RMAN catalog RMAN/RMAN
RMAN> Create catalog tablespace rman_ts;
RMAN> Register database; (the database is the target database)

Database registered in recovery catalog
Starting full Resync of recovery catalog
Full Resync complete

RMAN> connect target /;

To use backup and recovery in the future, you need to connect to the two databases. command:

Oracle> RMAN target/catalog rman/RMAN (the first slash represents the target database, and catalog represents the directory RMAN/RMAN represents the catalog user name and password)

After the command is executed, it is displayed as follows:

Recovery Manager: Release 10.2.0.1.0-production on Wed Dec 10 15:00:42 2008
Copyright (c) 1982,200 5, Oracle. All rights reserved.
Connected to target database: ora10g (dbid = 3988862108)
Connected to recovery Catalog Database

Command explanation:
Report schema report Shema refers to the schema that needs to be found in the database.
List Backup reads information from control
Crosscheck backup check the backup file and check whether the directory or file in the controlfile is on the disk.
Delete backupset 24 represents the number of the backupset, which is the delete directory or delete your file.

 

Note: When alter database open resetlogs is executed, the online redelog file is cleared and the data file is lost. Therefore, a full backup is required.

The resetlogs command indicates the end of the logical lifetime of a database and the start of the logical lifetime of another database. each time you use the resetlogs command, the SCN will not be reset, But Oracle will reset the log serial number and reset

Online redo log content. This is done to prevent conflicts in the log sequence after Incomplete recovery (because there is a time difference between the existing log and data files ).

 

If the RMAN archive file is lost and cannot be backed up, run the following two commands before backup:
Crosscheck archivelog all;
Delete expired archivelog all;

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.