RMAN restores archivelog)

Source: Internet
Author: User

I have heard of the restoration (restore) database, tablespace and database files, and the use of archive log recovery (recover) database, tablespace, and database files. Restore. What about restoring archived logs? Yes, we may ignore the archive log restoration process because the archive log is usually automatically restored by Oracle during recover. In most cases, we first restore the database, restore the database, and open the database. In fact, there is an action before restoring the database, that is, restoring the archive log, that is, restoring the log file to the default archive location, if the delete [all] input clause is used to back up archived logs. This article provides examples of restoring archived logs separately and restoring archived logs, as well as some usage of restore archivelog, just to better understand the restoration and restoration processes, because in most cases, the data file is restored to the default path. If it is restored to a non-default path, you need to manually restore archivelog.

1. Understanding restoration and recovery

Restoration: replace or copy a data file (possibly damaged) with a previous backup to a new path. This is usually the case in most cases.

Recovery: apply the archived logs after backup to the database, and refresh the database to a specific or up-to-date state based on the transaction of the archived logs (usually after restoration ). Roll back the committed transactions in the archived logs.

Restore archived logs: Restoring archived logs is a process between restoring a database and restoring a database. It restores the archive logs deleted using the delete [all] input Method When backing up archive logs to the default archive location. After the database is restored, archive logs are required for recover, that is, media recovery. After restoration, perform

Where are the archive logs required for recover? Is there a specified archiving path for archiving logs? If yes, a message is displayed during restoration. The archived log is already in the specified location.

If no, but there is a backup archive backup set. The backup set contains backup slices, that is, archived logs. Now that the package is packaged, You Need To unpackage the package to the default path or the specified path. This is to restore the archive log.

2. The example shows how to restore archived logs.

-- Demo Environment
-- To better simulate the restoration of archive logs, we only use a specific data file for copy backup, and then back up the archive logs (the archive logs are deleted during Backup)
-- Then destroy the data file, restore the data file, restore the archived log file, and restore the log file.
[Oracle @ linux3 ~] $ Cat/etc/issue
Enterprise Linux Server release 5.5 (Carthage)
Kernel \ r on an \ m

[Oracle @ linux3 ~] $ Sqlplus-V

SQL * Plus: Release 11.2.0.1.0 Production


A. Back up data files and archive logs
RMAN> list backup of archivelog all; ---> list archived logs backed up by the current database

Specification does not match any backup in the repository

RMAN> list backupset; ---> list existing backup sets of the current database

Specification does not match any backup in the repository

SQL> select username, default_tablespace from dba_users where username = 'Scott '; --> View the tablespace and data file where user SCOTT is located.

USERNAME DEFAULT_TABLESPACE
------------------------------------------------------------
SCOTT USERS

SQL> select name, file # from v $ datafile where tablespace_name = 'users ';

Name file #
----------------------------------------------------------------------
/U01/database/sybo3/oradata/users01.dbf 4

SQL> conn scott/tiger;
Connected.
SQL> select name, sequence #, status, COMPLETION_TIME from v $ archived_log where status = 'a'; --> the current system does not have any archived logs

No rows selected

SQL> host;

RMAN> copy datafile 4 to '/u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/users01.dbf'; --> Use rman copy to back up data files

RMAN> list copy;

Using target database control file instead of recovery catalog
Specification does not match any control file copy in the repository
Specification does not match any archived log in the repository
List of Datafile Copies
======================================

Key File S Completion Time Ckp SCN Ckp Time
------------------------------------------------------------
3 4 A 20:10:31 961662 20:10:31
Name:/u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/users01.dbf
Tag: tag2013020.t201031

--> Prepare a test table to verify whether the restoration is successful.
SQL> create table t1 (seq varchar2 (10), who varchar2 (20 ));

SQL> insert into t1 select 'first ', 'Robin' from dual;

SQL> commit;

SQL> alter system archive log current; --> Generate archive logs

SQL> select name, sequence #, status, COMPLETION_TIME from v $ archived_log where status = 'a ';

Name sequence # S COMPLETION_TIME
------------------------------------------------------------------------------------------------------------
/U01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_27_8z4sy 5ft _. arc 27 A 20130726 20:12:53

SQL> insert into t1 select 'second', 'robinson 'from dual;

SQL> commit;

SQL> alter system archive log current; --> Generate archive logs again

SQL> select name, sequence #, status, COMPLETION_TIME from v $ archived_log where status = 'a ';

Name sequence # S COMPLETION_TIME
------------------------------------------------------------------------------------------------------------
/U01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_27_8z4sy 5ft _. arc 27 A 20130726 20:12:53
/U01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_28_8z4t1q0s _. arc 28 A 20130726 20:14:47

--> Back up the archived logs and delete the backup logs.
RMAN> backup archivelog all delete input;

Starting backup at 2013/07/26 20:16:39
Current log archived
Using target database control file instead of recovery catalog
Allocated channel: ORA_DISK_1
Channel ORA_DISK_1: SID = 21 device type = DISK
Channel ORA_DISK_1: starting archived log backup set
Channel ORA_DISK_1: specifying archived log (s) in backup set ---> archive logs contained in the backup set
Input archived log thread = 1 sequence = 27 RECID = 23 STAMP = 821823173
Input archived log thread = 1 sequence = 28 RECID = 24 STAMP = 821823287
Input archived log thread = 1 sequence = 29 RECID = 25 STAMP = 821823400
Channel ORA_DISK_1: starting piece 1 at 2013/07/26 20:16:40
Channel ORA_DISK_1: finished piece 1 at 2013/07/26 20:16:41
Piece handle =/u01/database/Sybo/fra/Sybo/backupset/2013_07_26/empty _. bkp tag = tag201301_t201640 comment = NONE
Channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Channel ORA_DISK_1: deleting archived log (s) ---> the message "delete" is displayed.
Archived log file name =/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_27_8z4sy 5ft _. arc RECID = 23 STAMP = 821823173
Archived log file name =/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_28_8z4t1q0s _. arc RECID = 24 STAMP = 821823287
Archived log file name =/u01/database/sybo3/fra/SYBO3/archivelog/2013_07_26/o1_mf_1_29_8z4t585k _. arc RECID = 25 STAMP = 821823400
Finished backup at 2013/07/26 20:16:41


B. Simulate the destruction of data files
SQL> insert into t1 select 'last', 'end of test' from dual;

SQL> commit;

SQL> ho cat/dev/null>/u01/database/sybo3/oradata/users01.dbf ---> destroys data files

SQL> select * from t1; ---> data can still be queried in the buffer cache.

SEQ WHO
------------------------------
First Robin
Second Robinson
Last End of test

SQL> alter system checkpoint; ---> implements the checkpoint Process

System altered.

SQL> select * from t1; ---> in this case, the data file is not accessible.
Select * from t1
*
ERROR at line 1:
ORA-00376: file 4 cannot be read at this time
ORA-01110: data file 4: '/u01/database/sybo3/oradata/users01.dbf'

SQL> select * from v $ recover_file;
Select * from v $ recover_file
*
ERROR at line 1:
ORA-01135: file 4 accessed for DML/query is offline
ORA-01110: data file 4: '/u01/database/sybo3/oradata/users01.dbf'


C. Restore and restore damaged data files
SQL> select TABLESPACE_NAME, STATUS from dba_tablespaces where tablespace_name = 'users'; ---> tablespace is still Online

TABLESPACE_NAME STATUS
---------------------------------------
USERS ONLINE

SQL> alter tablespace users offline immediate; ---> offline damaged tablespace

Tablespace altered.

SQL> select tablespace_name, status from dba_tablespaces where tablespace_name = 'users'; ---> the status is offline

TABLESPACE_NAME STATUS
---------------------------------------
USERS OFFLINE

RMAN> restore datafile 4; ---> An error occurred while using restore datafile.

Starting restore at 2013/07/26 20:30:20
Using channel ORA_DISK_1
RMAN-00571: ========================================================== ==============================
RMAN-00569: ==================== error message stack follows ==========================
RMAN-00571: ========================================================== ==============================
RMAN-03002: failure of restore command at 20:30:20
ORA-01135: file 4 accessed for DML/query is offline
ORA-01110: data file 4: '/u01/database/sybo3/oradata/users01.dbf'
RMAN-06010: error while looking up datafile: 4

RMAN> restore tablespace users; ---> in this case, the error message "failed" appears when you use restore tablespace. It seems that for copy backup, you must copy it back.

Starting restore at 2013/07/26 20:31:12
Using channel ORA_DISK_1
RMAN-00571: ========================================================== ==============================
RMAN-00569: ==================== error message stack follows ==========================
RMAN-00571: ========================================================== ==============================
RMAN-03002: failure of restore command at 20:31:12
ORA-01135: file 4 accessed for DML/query is offline
ORA-01110: data file 4: '/u01/database/sybo3/oradata/users01.dbf'
RMAN-06019: cocould not translate tablespace name "USERS"

--> Use copy to restore
SQL> ho cp/u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/users01.dbf/u01/database/sybo3/oradata/users01.dbf

--> Next we will restore the archive log and define the from sequence clause. In fact, if we do not specify the restore archivelog, the archive log will be automatically restored during recover.
RMAN> restore archivelog from sequence 27;

Starting restore at 2013/07/26 20:36:55
Using channel ORA_DISK_1

Channel ORA_DISK_1: starting archived log restore to default destination ---> This is the key prompt, Which is restored to the default location.
Channel ORA_DISK_1: restoring archived log
Archived log thread = 1 sequence = 27
Channel ORA_DISK_1: restoring archived log
Archived log thread = 1 sequence = 28
Channel ORA_DISK_1: restoring archived log
Archived log thread = 1 sequence = 29
Channel ORA_DISK_1: reading from backup piece/u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/o1_mf_annnn_tag201301_t201640_8z4t58tn _. bkp
Channel ORA_DISK_1: piece handle =/u01/database/sybo3/fra/SYBO3/backupset/2013_07_26/container _. bkp tag = tag201301_t201640
Channel ORA_DISK_1: restored backup piece 1
Channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 2013/07/26 20:36:57

-- Author: Robinson
-- Blog:

Recommended reading:

Clone an Oracle EBS Database

User-managed database clone

RMAN-based database cloning on the same machine

RMAN duplicate Database

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.