RMAN backup and recovery data

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

this article from the csdn blog, reprinted please indicate the source: http://blog.csdn.net/tianlesoftware/archive/2009/10/20/4699320.aspx

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.