Basic Oracle tutorial-copying a database through RMAN

Source: Internet
Author: User

By using database backup, DBA can create a copy database on the same server or other servers. This replica database can have the same name (copy) or different (clone) from the primary database ).

The only difference between Oracle Database copy and database clone is that the name of the copied database cannot be changed. Using the copy database feature of RMAN, you can create a new database from the RMAN backup, and retain the existing database name for this copy database or assign a new name.

RMAN terms and commands:

A. Auxiliary database: RMAN copies the target database to the database instance. The parameter file, path, and password file of the database to be created. The secondary database instance must be started in non-loaded (NOMOUNT) mode before the RMAN database replication.

B. Duplicate: Creates a new database from the RMAN backup of other databases. Configure the database where RMAN performs replication and start the Oracle instance. From the perspective of RMAN, the target database is copied to the replica database.

C. set newname: Set a new name for the data file in an RMAN running block, the file name provided to this parameter overwrites any auxiliary database name (set auxname) or auxiliary database parameter (DB_FILE_NAME_CONVERT) of the data file ). The value of this new name is valid only in the running block.

D. Set auxname: Set a secondary name for the data file. The secondary name exists between RMAN sessions. If you do not want to use the name set in future RMAN commands, you must set this name to NULL.

E. log file: This keyword can be used in the Duplicate command to specify the online redo log file created by the replica database. If this keyword is not specified, RMAN will generate a log file in the path determined by the LOG_FILE_NAME_CONVERT parameter in the auxiliary parameter file. If the RMAN keyword is absent and no auxiliary parameter is set, RMAN will create logs in the same location as the target database.

(Assume that the NOCHECKFILENAME option is specified ).

F. do not check the file name (Nocheckfilename): by default, RMAN checks the data files that are restored to the path of the primary target data file on the replica host to ensure that they are not overwritten incorrectly. This option overwrites the default operation. In this way, you need to manually ensure that RMAN does not overwrite any existing data files. Use this command with caution to prevent overwriting of data files.

During the Duplicate command execution, RMAN executes a series of tasks. When you connect to the target, secondary, or selected directory database, RMAN performs the following operations:

1) decide which basic Backup will be used for the copy operation based on the recent occurrence or the provided recovery stop point.

2) determine the location where data files are stored in the secondary database instance based on the auxiliary database parameters or the commands and options set by RMAN.

3) read the backup slices or images for the secondary database and copy and restore the data files. This RMAN function is the same as normal database restoration.

4) apply any Incremental backup to restore data files based on the recovery stop point. The incremental application is the same as the task of releasing the Restore database command with RMAN.

5) apply all archived log files from the disk or backup to restore data files based on the recovery stop point.

6) create a new control file for the auxiliary database.

7) When you reset the online redo log file, open the replica database. The new online redo log file will be created based on the database commands specified in RMAN copy or the auxiliary parameter files for conversion.

Steps for creating a copy database:

1) Prepare a copy database parameter file: copy the parameter file of the target database to the $ ORACLE_BASE/admin/clone/pfile location. Modify the parameter file, replace the name of all target databases with the name of the replica database, and add

Add two parameters: db_file_name_convert = ("primary", "clone"), log_file_name_convert = ("primary", "clone"), and add them to the $ ORACLE_HOME/dbs directory.

LINUX parameter file connection, or add a windows parameter file in the % ORACLE_HOME % \ database directory.

2) create a password file:

LINUX> orapwd file = $ ORACLE_HOME/dbs/orapwCLONE password = clone entries = 4

WINNT> orapwd file = % ORACLE_HOME % \ database \ PWDCLONE. ORA password = clone

3) create a windows service (not required for linux ):

WINNT> oradim-new-sid clone-intpwd clone

4) Establish a NET8 connection

5) Start secondary instance: Before RMAN creates a replica database, the secondary instance must be started in non-loading mode.

6) load or open the target database

7) create a copy Database

C: \ Documents ents and Settings \ Administrator> rman

Recovery Manager: Version 9.2.0.1.0-Production

Copyright (c) 1995,200 2, Oracle Corporation. All rights reserved.

RMAN> connect target sys/oracle @ mydb;

Connected to the target database: MYDB (DBID = 2567199153)

RMAN> connect catalog rman/rman @ standby

Online to Restore directory database

RMAN> connect auxiliary sys/clone;

Connect to secondary Database: clone (not mounted)

RMAN> run {

2> set until logseq 3 THREAD 1;

3> ALLOCATE auxiliary channel d1 type disk;

4> duplicate target database to "CLONE ";

5>}

Run the command: SET until clause

Configured channel: d1

Channel d1: sid = 14 devtype = DISK

Start Duplicate Db, in month-08

Print the stored command file: Memory Script

{

Set until scn1077491;

Set newname for datafile1 to "C: \ ORACLE \ ORADATA \ CLONE \ SYSTEM01.DBF ";

Set newname for datafile2 to "C: \ ORACLE \ ORADATA \ CLONE \ UNDOTBS01.DBF ";

Set newname for datafile3 to "C: \ ORACLE \ ORADATA \ CLONE \ CWMLITE01.DBF ";

Set newname for datafile4 to "C: \ ORACLE \ ORADATA \ CLONE \ DRSYS01.DBF ";

Set newname for datafile5 to "C: \ ORACLE \ ORADATA \ CLONE \ EXAMPLE01.DBF ";

Set newname for datafile6 to "C: \ ORACLE \ ORADATA \ CLONE \ INDX1.DBF ";

Set newname for datafile7 to "C: \ ORACLE \ ORADATA \ CLONE \ ODM01.DBF ";

Set newname for datafile8 to "C: \ ORACLE \ ORADATA \ CLONE \ TOOLS01.DBF ";

Set newname for datafile9 to "C: \ ORACLE \ ORADATA \ CLONE \ USERS01.DBF ";

Set newname for datafile10 to "C: \ ORACLE \ ORADATA \ CLONE \ XDB01.DBF ";

Set newname for datafile11 to "C: \ ORACLE \ ORADATA \ CLONE \ MYTS01.DBF ";

Restore

Check readonly

Clone database

;

}

Execute Command file: Memory Script

Run the command: SET until clause

Run the command: SET NEWNAME

Run the command: SET NEWNAME

Run the command: SET NEWNAME

Run the command: SET NEWNAME

Run the command: SET NEWNAME

Run the command: SET NEWNAME

Run the command: SET NEWNAME

Run the command: SET NEWNAME

Run the command: SET NEWNAME

Run the command: SET NEWNAME

Run the command: SET NEWNAME

Start restore, on September 5-08

Channel d1: start restoration of the data file backup set

Channel d1: Setting the data file to be restored from the backup set

Restoring file 00001 to C: \ ORACLE \ ORADATA \ CLONE \ SYSTEM01.DBF

Restoring file 00002 to C: \ ORACLE \ ORADATA \ CLONE \ UNDOTBS01.DBF

Restoring file 00003 to C: \ ORACLE \ ORADATA \ CLONE \ CWMLITE01.DBF

Restoring file 00004 to C: \ ORACLE \ ORADATA \ CLONE \ DRSYS01.DBF

Restoring file 00005 to C: \ ORACLE \ ORADATA \ CLONE \ EXAMPLE01.DBF

Restoring file 00006 to C: \ ORACLE \ ORADATA \ CLONE \ INDX1.DBF

Restoring file 00007 to C: \ ORACLE \ ORADATA \ CLONE \ ODM01.DBF

Restoring file 00008 to C: \ ORACLE \ ORADATA \ CLONE \ TOOLS01.DBF

Restoring file 00009 to C: \ ORACLE \ ORADATA \ CLONE \ USERS01.DBF

Restoring file 00010 to C: \ ORACLE \ ORADATA \ CLONE \ XDB01.DBF

Restoring file 00011 to C: \ ORACLE \ ORADATA \ CLONE \ MYTS01.DBF

Channel d1: Restore backup Part 1

Processing piece = D: \ ORACLEBAK \ dbmydb_10_1_658243100 flag = WHOLE_INC0 parameter = NULL

Channel d1: restored successfully

Restore completed, from month to month 08

SQL statement: CREATE CONTROLFILE REUSE SET DATABASE "CLONE" RESETLOGS ARCHIVELOG

MAXLOGFILES 50

MAXLOGMEMBERS 5

MAXDATAFILES 100

MAXINSTANCES 1

# MAXLOGHISTORY 226

LOGFILE

GROUP1 ('C: \ ORACLE \ ORADATA \ CLONE \ redo01.log') SIZE104857600REUSE,

GROUP2 ('C: \ ORACLE \ ORADATA \ CLONE \ REDO02.LOG ') SIZE104857600REUSE,

GROUP3 ('C: \ ORACLE \ ORADATA \ CLONE \ REDO03.LOG ') SIZE104857600REUSE

DATAFILE

'C: \ ORACLE \ ORADATA \ CLONE \ system01.dbf'

Character set AL32UTF8

Print the stored command file: Memory Script

{

Switch clone datafile all;

}

Execute Command file: Memory Script

Data File 2 has been switched to the copy of the data file

Input data file copy recid = 1 Stamp = 654059846 file name = C: \ ORACLE \ ORADATA \ CLONE \ UNDOTBS01.DBF

Data File 3 has been switched to the copy of the data file

Recid = 2 Stamp = 654059846 file name = C: \ ORACLE \ ORADATA \ CLONE \ CWMLITE01.DBF

Data File 4 has been switched to the copy of the data file

Input duplicate data file recid = 3 stamp = 654059847 file name = C: \ ORACLE \ ORADATA \ CLONE \ DRSYS01.DBF

Data File 5 has been switched to the copy of the data file

Input duplicate data file recid = 4 stamp = 654059847 file name = C: \ ORACLE \ ORADATA \ CLONE \ EXAMPLE01.DBF

Data file 6 has been switched to the copy of the data file

Input duplicate data file recid = 5 Stamp = 654059847 file name = C: \ ORACLE \ ORADATA \ CLONE \ INDX1.DBF

Data File 7 has been switched to data file copy

Input duplicate data file recid = 6 stamp = 654059847 file name = C: \ ORACLE \ ORADATA \ CLONE \ ODM01.DBF

Data File 8 has been switched to data file copy

Recid = 7 stamp = 654059847 file name = C: \ ORACLE \ ORADATA \ CLONE \ TOOLS01.DBF

Data File 9 has been switched to the copy of the data file

Input duplicate data file recid = 8 stamp = 654059847 file name = C: \ ORACLE \ ORADATA \ CLONE \ USERS01.DBF

Data File 10 has been switched to the copy of the data file

Input duplicate data file recid = 9 stamp = 654059847 file name = C: \ ORACLE \ ORADATA \ CLONE \ XDB01.DBF

Data File 11 has been switched to the copy of the data file

Input duplicate data file recid = 10 stamp = 654059847 file name = C: \ ORACLE \ ORADATA \ CLONE \ MYTS01.DBF

Print the stored command file: Memory Script

{

Set until scn1077491;

Recover

Clone database

Delete archivelog

;

}

Execute Command file: Memory Script

Run the command: SET until clause

Start recover, on September 5-08

Start media recovery

Channel d1: Start the disk storage log to restore to the preset Purpose

Channel d1: restore disk logs

Disk Storage log line = 1 order = 1

Channel d1: restore disk logs

Disk Storage log line = 1 order = 2

Channel d1: Restore backup Part 1

Processing piece = D: \ ORACLEBAK \ ARCHMYDB_11_1_654043289 flag = TAG20080506T224129 parameter = NULL

Channel d1: restored successfully

Disk Storage log file name = C: \ ORACLE \ ORADATA \ CLONE \ ARCHIVE1_1.DBF line = 1 order = 1

Channel clone_default: delete disk logs

Disk Storage log file name = C: \ ORACLE \ ORADATA \ CLONE \ ARCHIVE1_1.DBF recid = 2 Stamp = 654059855

Disk Storage log file name = C: \ ORACLE \ ORADATA \ CLONE \ ARCHIVE1_2.DBF line = 1 order = 2

Channel clone_default: delete disk logs

Disk Storage log file name = C: \ ORACLE \ ORADATA \ CLONE \ ARCHIVE1_2.DBF recid = 1 Stamp = 654059854

Media Recovery completed

Complete recover, from month to month 08

Print the stored command file: Memory Script

{

Shutdown clone;

Startup clone nomount;

}

Execute Command file: Memory Script

Database detached

Oracle disabled for processing

Connect to secondary database (not started)

Oracle started for processing

The overall system region is 122755896 bytes in total

Fixed Size 453432 bytes

Variable Size 96468992 bytes

Database Buffers: 25165824 bytes

Redo Buffers 667648 bytes

SQL statement: CREATE CONTROLFILE REUSE SET DATABASE \ CLONE \ RESETLOGS ARCHIVELOG

MAXLOGFILES 50

MAXLOGMEMBERS 5

MAXDATAFILES 100

MAXINSTANCES 1

# MAXLOGHISTORY 226

LOGFILE

GROUP1 ('C: \ ORACLE \ ORADATA \ CLONE \ redo01.log') SIZE104857600REUSE,

GROUP2 ('C: \ ORACLE \ ORADATA \ CLONE \ REDO02.LOG ') SIZE104857600REUSE,

GROUP3 ('C: \ ORACLE \ ORADATA \ CLONE \ REDO03.LOG ') SIZE104857600REUSE

DATAFILE

'C: \ ORACLE \ ORADATA \ CLONE \ system01.dbf'

Character set AL32UTF8

Print the stored command file: Memory Script

{

Catalog clone datafilecopy "C: \ ORACLE \ ORADATA \ CLONE \ UNDOTBS01.DBF ";

Catalog clone datafilecopy "C: \ ORACLE \ ORADATA \ CLONE \ CWMLITE01.DBF ";

Catalog clone datafilecopy "C: \ ORACLE \ ORADATA \ CLONE \ DRSYS01.DBF ";

Catalog clone datafilecopy "C: \ ORACLE \ ORADATA \ CLONE \ EXAMPLE01.DBF ";

Catalog clone datafilecopy "C: \ ORACLE \ ORADATA \ CLONE \ INDX1.DBF ";

Catalog clone datafilecopy "C: \ ORACLE \ ORADATA \ CLONE \ ODM01.DBF ";

Catalog clone datafilecopy "C: \ ORACLE \ ORADATA \ CLONE \ TOOLS01.DBF ";

Catalog clone datafilecopy "C: \ ORACLE \ ORADATA \ CLONE \ USERS01.DBF ";

Catalog clone datafilecopy "C: \ ORACLE \ ORADATA \ CLONE \ XDB01.DBF ";

Catalog clone datafilecopy "C: \ ORACLE \ ORADATA \ CLONE \ MYTS01.DBF ";

Switch clone datafile all;

}

Execute Command file: Memory Script

Data file backup has been added to the directory

Data file backup file name = C: \ ORACLE \ ORADATA \ CLONE \ UNDOTBS01.DBF recid = 1 Stamp = 654059903

Data file backup has been added to the directory

Data file backup file name = C: \ ORACLE \ ORADATA \ CLONE \ CWMLITE01.DBF recid = 2 Stamp = 654059903

Data file backup has been added to the directory

Data file backup file name = C: \ ORACLE \ ORADATA \ CLONE \ DRSYS01.DBF recid = 3 stamp = 654059903

Data file backup has been added to the directory

Data file backup file name = C: \ ORACLE \ ORADATA \ CLONE \ EXAMPLE01.DBF recid = 4 stamp = 654059904

Data file backup has been added to the directory

Data file backup file name = C: \ ORACLE \ ORADATA \ CLONE \ INDX1.DBF recid = 5 Stamp = 654059904

Data file backup has been added to the directory

Data file backup file name = C: \ ORACLE \ ORADATA \ CLONE \ ODM01.DBF recid = 6 stamp = 654059904

Data file backup has been added to the directory

Data file backup file name = C: \ ORACLE \ ORADATA \ CLONE \ TOOLS01.DBF recid = 7 stamp = 654059904

Data file backup has been added to the directory

Data file backup file name = C: \ ORACLE \ ORADATA \ CLONE \ USERS01.DBF recid = 8 stamp = 654059905

Data file backup has been added to the directory

Data file backup file name = C: \ ORACLE \ ORADATA \ CLONE \ XDB01.DBF recid = 9 stamp = 654059905

Data file backup has been added to the directory

Data file backup file name = C: \ ORACLE \ ORADATA \ CLONE \ MYTS01.DBF recid = 10 stamp = 654059905

Data File 2 has been switched to the copy of the data file

Input data file copy recid = 1 Stamp = 654059903 file name = C: \ ORACLE \ ORADATA \ CLONE \ UNDOTBS01.DBF

Data File 3 has been switched to the copy of the data file

Recid = 2 Stamp = 654059903 file name = C: \ ORACLE \ ORADATA \ CLONE \ CWMLITE01.DBF

Data File 4 has been switched to the copy of the data file

Input duplicate data file recid = 3 stamp = 654059903 file name = C: \ ORACLE \ ORADATA \ CLONE \ DRSYS01.DBF

Data File 5 has been switched to the copy of the data file

Input duplicate data file recid = 4 stamp = 654059904 file name = C: \ ORACLE \ ORADATA \ CLONE \ EXAMPLE01.DBF

Data file 6 has been switched to the copy of the data file

Input duplicate data file recid = 5 Stamp = 654059904 file name = C: \ ORACLE \ ORADATA \ CLONE \ INDX1.DBF

Data File 7 has been switched to data file copy

Input duplicate data file recid = 6 stamp = 654059904 file name = C: \ ORACLE \ ORADATA \ CLONE \ ODM01.DBF

Data File 8 has been switched to data file copy

Recid = 7 stamp = 654059904 file name = C: \ ORACLE \ ORADATA \ CLONE \ TOOLS01.DBF

Data File 9 has been switched to the copy of the data file

Input duplicate data file recid = 8 stamp = 654059905 file name = C: \ ORACLE \ ORADATA \ CLONE \ USERS01.DBF

Data File 10 has been switched to the copy of the data file

Input duplicate data file recid = 9 stamp = 654059905 file name = C: \ ORACLE \ ORADATA \ CLONE \ XDB01.DBF

Data File 11 has been switched to the copy of the data file

Input duplicate data file recid = 10 stamp = 654059905 file name = C: \ ORACLE \ ORADATA \ CLONE \ MYTS01.DBF

Print the stored command file: Memory Script

{

Alter clone database open resetlogs;

}

Execute Command file: Memory Script

Database enabled

Duplicate Db completed, from month to month 08

RMAN>

Use RMAN keywords and commands to control the names and locations of data files and log files

You can control the location of the data file and set a new name or a secondary name as follows:

SET auxname for datafile 2 TO 'C: \ oracle \ oradata \ clone \ auxname02.dbf ';

# Set a secondary name for the data file. The secondary name exists between RMAN sessions. If you do not want later RMAN to use the name, you must set this name to NULL.

SET auxname for datafile 2 TO 'C: \ oracle \ oradata \ clone \ auxname02.dbf ';

# Set a secondary name for the data file. The secondary name exists between RMAN sessions. If you do not want later RMAN to use the name, you must set this name to NULL.

SET auxname for datafile 4 TO 'C: \ oracle \ oradata \ clone \ auxname03.dbf ';

SET auxname for datafile 6 TO 'C: \ oracle \ oradata \ clone \ auxname04.dbf ';

Run {

ALLOCATE auxiliary channel d1 type disk;

Set until logseq 3 THREAD 1;

SET newname for datafile 1 TO 'C: \ oracle \ oradata \ clone \ newname01.dbf'; # SET a new name FOR the data file in the RMAN runtime block, the value of this new name is valid only in the running block.

SET newname for datafile 3 TO 'C: \ oracle \ oradata \ clone \ newname03.dbf ';

SET newname for datafile 5 TO 'C: \ oracle \ oradata \ clone \ newname05.dbf ';

SET newname for datafile 7 TO 'C: \ oracle \ oradata \ clone \ newname07.dbf ';

Duplicate target database to \ CLONE \ LOGFILE

GROUP 1 ('C: \ oracle \ oradata \ clone \ redo1_1.log ',

'C: \ oracle \ oradata \ clone \ redo1_2.log') SIZE 10 m reuse,

GROUP 2 ('C: \ oracle \ oradata \ clone \ redo2_1.log ',

'C: \ oracle \ oradata \ clone \ redo2_2.log ') SIZE 10 m reuse,

GROUP 3 ('C: \ oracle \ oradata \ clone \ redo3_1.log ',

'C: \ oracle \ oradata \ clone \ redo3_2.log ') SIZE 10 m reuse;

}

SET auxname for datafile 2 to null;

SET auxname for datafile 4 to null;

SET auxname for datafile 6 to null;

Specify a new file name (or location) for each data file of the clone database during replication ). In this way, when the backup of the target database is restored to the location of the copied database, each data file is renamed.

File can be specified as the duplicate targer database Command. In the preceding example, each data file is renamed, and the log file size, renaming, and image are also redefined, pair of singular data

Rename an object and rename an even data file.

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.