Oracle rman backup and restoration RMAN supports Incremental Backup: databases, tablespaces, and data files

Source: Internet
Author: User

Oracle rman backup and Restoration




RMAN supports Incremental Backup: databases, tablespaces, and data files.


Only used blocks can be backed up as backup set


Ing between tablespaces and data files: dba_data_files/v $ datafile_header


In noarchivelog mode, you can use RMAN to back up the read-only and offline tablespaces.


Oracle rman downtime backup:


Backup


RMAN is connected to ORACLE, while WINDOWS is in command mode.


Rman target/


Local Authentication mode is used to connect to the local database. RMAN must connect to the database in dedicate mode. Therefore, in the share mode, a dedicate connection should be configured for the RMAN connection.


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


Configure controfile autobackup on; // open autobackup
Configure controfile autobackup off; // disable autobackup
Close Database
RMAN> shutdown immediate
The backup of the mount database RMAN must be in the MOUNT mode, which is also important for controlling file backup.
RMAN> startup mount
Simplest backup
RMAN> backup database
This sentence is OK.
The backup set is in the default database location. % Oracle_home %/ora92/database
Of course, you can also use run to flexibly define your backup.
RMAN> run {
> Allocate chennel d1 type disk; // Distribution Channel
> Backup full database // full backup database
> Include current controlfile // include the current controlfile
> Format 'e: \ oracle \ orders \ db _ % d _ % s _ % p _ % t _ % T'; // backup file location and file name format
> Release channel d1; // release the channel
>}


Restore
1. The data file is corrupted, while the control file is good or has been recovered.
Connect RMAN to database
Startup mount
Restore database
Recover database noredo;
Alter database open resetlogs;
Recover database noredo this command instructs RMAN to execute the final recovery operation to prepare to open the database. Because it is in NOARCHIVELOG mode and no archived redo logs are applied and online redo logs are lost, you must use the noredo parameter in this command.


Finally, use alter database open resetlogs to open the database. Because the control file has been restored and the redo log needs to be re-built, you must use resetlogs.
2. Restore the control file
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 which can
Select * from v $ database. But how can I see that a database cannot be opened when the control file breaks down? This DBID is recorded in normal times.
This is the simplest example of using RMAN for backup and recovery, but we can see the summary of RMAN backup and recovery.


Oracle rman online backup:


1. Before oracle rman online backup, you must switch the log mode to archive logs;


A. Close the database.
SQL> shutdown immediate;


B. Start the database to the mount status.
SQL> startup mount;


C. Enable archive Mode
SQL> alter database archivelog;


D. view the modified database backup and recovery policies and the location of the archive files.
SQL> archive log list;


Note: After the archive mode is changed, all previous Database backups are invalid.


E. Modify the initialization parameters.
Before Oracle10g, you also need to modify the initialization parameters so that the database is in the automatic archiving 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 the database. This parameter takes effect when the database is in automatic archiving mode.


Of course, you can also skip step 1, directly
SQL> archive log start
Enable automatic archiving for the database, but the database is still in manual archiving mode after restart.


2. Run: RMAN target/


3. Save RMAN information: it is saved in control file by default, and the storage period is 7 days.


Adjusted: alter system set control_file_record_keep_time = days;


4. Set up an independent database to save RMAN backup information


Because there is only one database, it is built on its own database.


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


B. Create a user RC:


Create user rc identified by rc temporary tablespace temp default tablespace rc quota unlimited on rc;


C. Authorize RC: GRANT RECOVERY_CATALOG_OWNER TO rc;


D. Build:


Rman catalog rc/rc @ orcl


RMAN> create catalog;


RMAN> exit


Rman target/catalog rc/rc @ orcl


RMAN> register database;


E. Use:


Rman target/catalog rc/rc @ orcl


After this connection method, the data will be saved in the control file and catalog.


5. Global parameter configuration:


View: show all;


Modify: configure parameter name settings


For example, modify whether to automatically save the control file: configure controlfile autobackup on;


Restore Default Value: configure parameter name clear;


Key parameters:


A. retention Period: retention policy


The default value is redundancy 1. A backup is retained;


Available value: recovery window of 7 days: retain the backup that can meet the 7-day recovery cycle


Conditional check: report obsolete: RMAN lists the backups that can be deleted based on the retention period parameters.


Delete more than backup: delete obsolete


B. Optimized backup: backup optimization: RMAN automatically ignores the backed up content (data files, archived logs, backup blocks)


Premise: Backup specifies the same channel


C. default backup channel: default device type to disk: default backup to disk, path: flash recovery area


Channel Type:


Disk: File System Path


Flash recovery area: default path


Sbt: tape device


Change to another disk 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) content, which is divided into one or more backup piece. Only this type of backup can be compressed.


Copy: backup as copy backup content


View by type:


View backupset: 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 File: list backup of datafile n;


Control File: list backup of controlfile;


Archive logs: list archivelog all;


View by rule:


View the files that can be deleted according to the Save rules: report obsolete;


View the backup content according to the Save rule: report


Combined check of RMAN and OS: corsscheck content;




7. Backup Mode
Full: full backup;


Incremental: Incremental Backup


Types of Incremental Backup: databases, data files, and tablespaces


A. level 0 backup is required as the basis. For example: backup incremental level 0 backup content; (backup content: All used data blocks, different from image copy)


B. incremental type:


Accumulative increment: backup cumulative level 1 backup content;


Incremental difference: backup incremental level 1 backup content;


Difference: the cumulative incremental data is always backed up based on level 0;


The first incremental differential backup is based on the level 0 backup, and the second Incremental backup is based on the previous Incremental backup.


C. Incremental backup mode of Image:


First time: Based on Image full backup;


Second: Perform Incremental Backup Based on full backup. After the backup is complete, it is merged into an Image full backup.


Third: Perform Incremental Backup Based on the second full backup of the Image. After the backup is completed, it is merged into an Image full backup.


Implementation:


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. Enable the "block change tracking" parameter to increase the speed.


View status: SELECT status FROM v $ block_change_tracking;


Default Value: DISABLED


ENABLE: alter database enable block change tracking; (DB_CREATE_FILE_DEST in OMF is stored by default)


Set the file path:


Alter database enable block change tracking using file '/u01/oradata/MYSID/rman_change_track.f' REUSE;


Close: alter database disable block change tracking;


Back up and check: bakcup check logical backup content;


Do not back up only check file: backup validate backup content;


If an error is reported, view: v $ backup_reply uption; v $ copy_reply uption.


8. Backup content:


Entire database: RMAN> backup database;


Classic full-database backup: 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 1: Restore the entire database from the latest backup set. The database automatically runs the redo and archive logs (completely recovered ):


SQL> shutdown immediate


SQL> startup mount


RMAN> restore database;


RMAN> recover database;


RMAN> SQL 'alter database open ';


Method 2: Restore the entire database from the tag, and the database will also run the redo and archive logs (completely restored). The results are the same as those of the above script:


1. View tags:


RMAN> list backupset summary;
Key ty lv s Device Type Completion Time # Pieces # Copies Compressed Tag
-----------------------------------------------------------------
25 B A DISK 25-JUL-11 1 1 NO tag20151125t104634
28 B 0 A DISK 25-JUL-11 1 1 NO tag20151125t104645
29 B A DISK 25-JUL-11 1 1 NO tag20151125t104711
30 B F A DISK 25-JUL-11 1 1 NO tag20151125t104713
31 B A DISK 25-JUL-11 1 1 NO tag20151125t105333
32 B A DISK 25-JUL-11 1 1 NO tag20151125t105350
33 B 1 A DISK 25-JUL-11 1 1 NO tag20151125t105353
34 B A DISK 25-JUL-11 1 1 NO tag20151125t105408
35 B F A DISK 25-JUL-11 1 1 NO tag20151125t105411
36 B A DISK 25-JUL-11 1 1 NO tag20151125t111403
37 B 1 A DISK 25-JUL-11 1 1 NO tag20151125t111405
38 B A DISK 25-JUL-11 1 1 NO tag20151125t111421
39 B F A DISK 25-JUL-11 1 1 NO tag20151125t111423


2. Restore the database:


SQL> shutdown immediate;
SQL> startup mount;
RMAN> restore database from tag tag20151125t104645;


RMAN> recover database from tag tag20151125t104645;


RMAN> alter database open;


B. Incomplete recovery:


SQL> shutdown immediate;
SQL> startup mount;
RMAN> restore database from tag tag20151125t104645;


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


RMAN> alter database open resetlogs;
Note: all the backup sets are invalid. Ensure that the database needs to be fully backup again (after ORACLE10G, the backup before resetlog is still usable)


Key tablespace 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 tablespace recovery (example/users ):


Select * from v $ datafile_header; ing between tablespaces and data files


SQL> alter database datafile number offline;


RMAN> restore tablespace name;


RMAN> recover tablespace name;


SQL> alter database datafile number online;


10. Delete backup


All backup sets: delete backup;


All copy backup machines: delete copy;


Specific backup machine: delete backupset 19;


Delete a file: delete obsolete;


Delete expired backups:


Delete expired backupset;


Delete expired copy;


11. 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;
}
12. external variables:


Language: set nls_lang = american


Date: set nls_date_format = yyyy-mm-dd ....


13. RMAN sciprt


Prerequisites: catalog


Statement: (global indicates that it can be called by multiple databases)


Create global script Name


Comment "Remarks"


{Script content}


For example:


Create global script abc


Comment "test"


{Backup current controlfile ;}


Call: run {execute script name}


Example: run {execute script abc ;}


View: print script Name


Rewrite:


Replace global script Name


Comment "Remarks"


{Script content}


Delete: delete script Name;


14. Permanent backup retained


The condition is that the backup cannot be stored 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. Change the property to permanent.


Change backupset No. keep forever nologs;


15. Create multiple fixed-size backups


For example, the backup size in example test is greater than 50 MB.


Run


{


Allocate channel c1 device type disk maxpiecesize 10 M format '/tmp/autobackup/% U ';


Backup tablespace example;


}


The/tmp/autobackup directory contains six files.


16. Run the 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

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.