Oracle's Rman Backup and restore

Source: Internet
Author: User

RMAN Incremental backup available: database, tablespace, data file

only The Used Block can be backed up into Backup Set

table spaces correspond to data files: Dba_data_files/v$datafile_header

in the Noarchivelog mode, you can use the RMAN Backup read-only and the Offline The table space

ORACLE RMAN Downtime Backup:

Backup

Rman connection on oracle,windows under command mode

RMAN TARGET/

Local authentication mode is used to connect to the local database. The Rman connection database must be in dedicate mode. Therefore, the database in share mode should be configured with an dedicate connection for the Rman connection.

If you want to back up the control files and parameter files together

Configure Controfile autobackup on;//open autobackup
Configure Controfile autobackup off;//close Autobackup
Close the database
Rman>shutdown Immediate
The backup of the Mount database Rman must be in Mount mode, which is also important for controlling file backups.
Rman>startup Mount
The simplest backup
Rman>backup Database
Just this one, it's OK.
For such a backup, the backup set is in the database default location. %oracle_home%/ora92/database
Of course you can also use Run to flexibly define your backups.
rman>run{
>allocate chennel d1 type disk; assigning channels
>backup full database//fully backed up databases
>include Current Controlfile//Includes present Controlfile
>format ' E:\oracle\orders\db_%d_%s_%p_%t_%T '; Backup file location and file name format
>release Channel d1;//release channels
}

Recovery
1, the data file is damaged, and the control file is good, or has been restored
Rman connected to the database
Startup Mount
Restore Database
Recover database Noredo;
ALTER DATABASE open resetlogs;
Recover database Noredo This command instructs Rman to perform the final recovery operation to prepare to open the database. The Noredo parameter is required in this command because it is in Noarchivelog mode and no archived redo logs are applied and an online redo log is lost.

Finally, open the database with ALTER DATABASE open Resetlogs. Because the control file has been restored and the redo log needs to be rebuilt, resetlogs must be used.
2. Restore Control files
Startup Nomount;
Set dbid = <dbid>
Restore Controlfile from Autobackup;
ALTER DATABASE Mount;
Restore database;
Recover database Noredo;
ALTER DATABASE open resetlogs;
ALTER DATABASE open;
In this example there is a dbid this can be
SELECT * from V$database. But a database in the control file is broken can not open how to see it is in peacetime to write down this dbid.
This is the simplest example of backup and recovery with Rman, but you can see a synopsis of the Rman backup and recovery.

ORACLE RMAN Online Backup:

1. ORACLE RMAN Online backup needs to switch log mode as archive log;

A. Closing a database
sql> shutdown immediate;

B. Start the database to Mount state
sql> startup Mount;

C. Enable archiving mode
sql> ALTER DATABASE Archivelog;

D. Viewing the modified database backup and recovery strategy and location of the archive file
sql> archive log list;

Note: Modify the Archive mode, all previous database backups are invalid.

E. Modifying the appropriate initialization parameters
Before oracle10g, you also need to modify the initialization parameters to keep the database in auto-archive mode.
Available sql> show parameter log_archive_start; view
NAME TYPE VALUE
------------------------------------ ----------- --------------
Log_archive_start Boolean FALSE
Sql> alter system set LOG_ARCHIVE_START=TRUE Scope=spfile;
Restart database This parameter is in effect, at which time the database is in Auto-archive mode.

Of course you can not do the 5th step directly
Sql>archive Log Start
Enables the database to enable automatic archiving, but the database is still in manual archive mode after a reboot.

2. run:RMAN target/

3. RMAN information Save: saved in control file by default, save period 7 days

Adjustment: Alter system set control_file_record_keep_time= days;

4. Build a standalone database to hold RMAN Backup Information

Since there is only one database, it is built on its own database

A. Creating a tablespace rc:create tablespace rc datafile size 10M autoextend on next 1M

B. Create user rc:

CREATE USER RC identified by RC temporary tablespace temp DEFAULT tablespace RC QUOTA UNLIMITED on RC;

C. Authorization rc:grant Recovery_catalog_owner to RC;

D. Build:

Rman catalog rc/[email protected]

Rman>create Catalog;

Rman>exit

Rman target/catalog rc/[email protected]

Rman>register database;

E. Use:

Rman target/catalog rc/[email protected]

After this connection, the data will be stored in the control file and catalog

5. Global parameter configuration:

View: Show All;

Modify: Configure parameter name specific settings

For example: Modify whether to automatically save control file:configure controlfile autobackup on;

Restore Default value: Configure parameter name clear;

Key parameters:

A. Save period: Retention Policy

The default is redundancy 1: keep a backup;

Available values: Recovery window of 7 days: retains backups that can meet the 7-day recovery cycle

Based on condition check: report Obsolete:rman lists the backups that can be deleted based on the save period parameters

Delete more than backup: Delete obsolete

B. Optimized backup: Backup Optimization:rman automatically ignores content that has been backed up (data files, archive logs, backup blocks)

Premise: backup Specifies the same channel

C. Default Backup channel: Default device Type to disk: defaults to disks, the path is Flash recovery area

Channel Type:

Disk: File system path

Flash Recovery area: Default path

SBT: Tape Device

Modify to disk other path: Configure channel Device type disk format ' path/%u ';

For example: Configure Channel Device type disk format '/tmp/movedata/%u ';

6. Backup Results

Backupset:backup (as Backupset) backup content, which is split into one or more backup piece, only this type of backup can be compressed.

Copy:backup as copy backup content

View By Type:

Backupset View: List Backup summary (List backupset summary)

View Details: List backupset BS

Copy view: List copy

View by content:

Entire database: list backup of database;

Tablespace:list Backup of tablespace users;

Data files: List backup of datafile N;

Control file: List backup of Controlfile;

Archive log: List archivelog all;

View by rule:

View files can be deleted according to save rules: report obsolete;

View what you need to back up according to your Save rules: report

Rman and OS combined check: Corsscheck content;

7. How to back up

Full: fully prepared;

Incremental: Incremental Backup

Types that can be incrementally backed up: databases, data files, table spaces

A. A level 0 backup is required first as a basis. Example: Backup incremental level 0 back up content (Backup content: All used data block, different from image copy)

B. Increment type:

Cumulative increment: Backup cumulative Level 1 back up content;

Difference Increment: Backup incremental level 1 back up content;

Difference: Cumulative increment is always based on level 0 backup;

The first difference increment is a level 0 based backup, and the second one is based on the previous incremental backup

C. Image backup Increment method:

First time: Based on image all-ready;

Second time: Make incremental backup based on full standby, and then synthesize into an image fully prepared

The third time: based on the second image is fully prepared, make an incremental backup, complete the synthesis into an image full

Realize:

For example: for tablespace example

RUN {
RECOVER COPY of tablespace example with TAG ' incr_update ';
BACKUP INCREMENTAL Level 1 for RECOVER of COPY with TAG ' incr_update '
tablespace example;
}

D. Turn on the parameter "Block change tracking" to increase the speed

View status: SELECT status from V$block_change_tracking;

Default value: DISABLED

Open: ALTER DATABASE ENABLE BLOCK change TRACKING; (Default storage path db_create_file_dest in OMF)

To set the file path:

ALTER DATABASE ENABLE BLOCK change TRACKING USING FILE '/u01/oradata/mysid/rman_change_track.f ' reuse;

Off: ALTER DATABASE DISABLE BLOCK change TRACKING;

Backup and check: Bakcup check logical backup content;

Do not back up just check files: Backup validate back up content;

If the check has an error, view: v$backup_corruption;v$copy_corruption

8. Backup content:

Entire database: Rman>backup;

Classic backup of the whole library: backup as compressed backupset database include current controlfile plus archivelog delete input;

Tablespace:rman>backup tablespace name;

Data file: Rman>backup datafile N; (N: Specific data file number select File_name,file_id,tablespace_name from Dba_data_files;)

Control file: Rman>backup current controlfile;

Or Rman>backup database include current controlfile;

Log file: Rman>backup archivelog all;

or rman>backup database plus archivelog;

Parameter file: Rman>backup spfile;

9. Restore

A. Full Recovery

method One: Restore the entire database from the most recent backup set and the database will run automatically Redo and the Archive log (Full recovery):

Sql>shutdown Immediate

Sql>startup Mount

Rman>restore database;

Rman>recover database;

Rman>sql ' ALTER DATABASE open ';

method Two: from Tag restore the entire database and the database will run Redo and the Archive log (Full recovery) with the same results as the previous script:

1. View Tags:

rman> List Backupset summary;
Key TY LV S Device Type completion time #Pieces #Copies compressed Tag
------- -- -- - ----------- --------------- ------- ------- ---------- ---
B a A DISK 25-jul-11 1 1 NO tag20110725t104634
B 0 A DISK 25-jul-11 1 1 NO tag20110725t104645
B a A DISK 25-jul-11 1 1 NO tag20110725t104711
B F A DISK 25-jul-11 1 1 NO tag20110725t104713
B a A DISK 25-jul-11 1 1 NO tag20110725t105333
B a A DISK 25-jul-11 1 1 NO tag20110725t105350
B 1 A DISK 25-jul-11 1 1 NO tag20110725t105353
B a A DISK 25-jul-11 1 1 NO tag20110725t105408
B F A DISK 25-jul-11 1 1 NO tag20110725t105411
25-jul-11 B A A DISK 1 1 NO tag20110725t111403
PNS B 1 A DISK 25-jul-11 1 1 NO tag20110725t111405
25-jul-11 B A A DISK 1 1 NO tag20110725t111421
25-jul-11 B F A DISK 1 1 NO tag20110725t111423

2. Restore the database:

Sql>shutdown immediate;
Sql>startup Mount;
Rman>restore database from tag tag20110725t104645;

rman> recover database from tag tag20110725t104645;

rman> ALTER DATABASE open;

B. Incomplete recovery:

Sql>shutdown immediate;
Sql>startup Mount;
Rman>restore database from tag tag20110725t104645;

Rman>recover database until Time "to_date (' 2011-08-04 15:37:25 ', ' yyyy/mm/dd hh24:mi:ss ')";

Rman>alter database open resetlogs;
Note: All backup sets are not valid after use, ensuring security requires re-provisioning of the database ( oracle10g later, Resetlog previous backup is still available)

Critical Table Space recovery ( System/undotbs1/sysaux ):

Sql>shutdown Abort

Sql>startup Mount

Rman>restore tablespace name;

Rman>recover tablespace name;

Rman>sql ' ALTER DATABASE open ';

Non-critical Table space recovery ( example/users ):

SELECT * from V$datafile_header; Table space and data file correspondence relationship

Sql>alter database datafile digital offline;

Rman>restore tablespace name;

Rman>recover tablespace name;

Sql>alter database datafile Digital online;

Delete a backup

All backup backups set: Delete backup;

All copy backup machines: delete copy;

Specific backup machine: delete backupset 19;

Delete files can be deleted according to save rule: delete obsolete;

To delete an expired backup:

Delete Expired backupset;

Delete expired copy;

One . RUN Block

For example:

Rman> RUN {
ALLOCATE CHANNEL C1 DEVICE TYPE SBT;
ALLOCATE CHANNEL C2 DEVICE TYPE SBT;
ALLOCATE CHANNEL C3 DEVICE TYPE SBT;
BACKUP
INCREMENTAL level = 0
FORMAT '/disk1/backup/df_%d_%s_%p.bak '
(datafile 1,4,5 CHANNEL C1)
(datafile 2,3,9 CHANNEL C2)
(datafile 6,7,8 CHANNEL C3);
ALTER SYSTEM ARCHIVE LOG current;
}
External variables:

Language: Set Nls_lang=american

Date: Set Nls_date_format=yyyy-mm-dd ....

RMAN sciprt

Prerequisites: Catalog

notation: (global means it can be called by multiple databases)

Create Global script Name

Comment "Remark description"

{Script Contents}

For example:

Create global Script ABC

Comment "Test"

{Backup current controlfile;}

Call: Run {Execute script name}

For example: Run {execute script ABC;}

View: Print script name

Rewrite:

Replace Global script Name

Comment "Remark description"

{Script Contents}

Remove: Delete script name;

permanently Keep backups

The condition is that the backup cannot be kept in the flash recovery area;

A. Create a backup:

RUN

{
ALLOCATE CHANNEL C1 DEVICE TYPE disk format '/tmp/autobackup/%u ';
BACKUP Tablespace example;
}

B. Find the Backup:

List backupset of tablespace example;

C. modify properties to Permanent

Change backupset number Keep forever nologs;

Set up multiple fixed-size backups

Example: Example test backup size is greater than 50M

Run

{

Allocate channel C1 device type disk maxpiecesize 10M format '/tmp/autobackup/%u ';

Backup Tablespace example;

}

There are six files in the/tmp/autobackup directory

Run script:backup Recovery Area

Backup content:

A. control file autobackup;

B. Incremental backup Sets

17.BLOCK Change Tracking

A. For the entire database;

B. Default storage path: Background_dump_dest

Oracle's Rman Backup and restore

Related Article

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.