Migrating a database to a different machine using Rman

Source: Internet
Author: User
Tags sqlplus

There are several ways to migrate a database, and the more common is to use Rman to migrate. Using Rman to migrate a database belongs to the physical backup and Recovery category of the database, and the information about the database is completely mirrored throughout the process. Therefore, restoring a restored database based on this method for testing would make a relatively small difference from the real production environment. This article describes the process of using Rman to restore an Oracle 10g database.

First, the main steps
1. Backing Up the database
2. FTP Backup to destination server
3. Create a project directory for the target database
4. Create Pfile or SPFile for the target database (use Rman to restore or copy the original pfile to the destination server)
5. Restore Control files
6. Restore Data files
7. OPEN Database

In fact, these steps are better understood, the whole essence is the database architecture and database of the entire start-up process understanding.
You can refer to the architecture and startup process for
Oracle Instances and Oracle Databases (Oracle architecture)
Oracle DB instance startup shutdown process

Here's a description of this
A, first need to create the appropriate directory for the instance's running environment, such as dump location, datafile location, archive location, etc.
If you are recovering to a different path, subsequent Rman needs to be updated to the control file using the set NewName for DataFile method
b, the instance needs to be pfile to start, so you need to restore pfile or spfile, and then switch the database to Nomount state
C, the next step is to switch the database to mount state through the control file, so you need to restore the control file and then mount
D, Mount to restore operations on the database
E. After the restore is complete, restore (recovery) operations to the database (Restore and recover require backup information based on the control file or recovery directory)
F, and finally the Open database


Second, the Migration demo

1. Back up the original database the source database shown here is using the same version as the target database for Oracle 10g R2 (10.2.0.3), the operating system is SuSE +SP3 backup process slightly, for backup script, refer to: Linux under Rman backup shell script http  ://blog.csdn.net/robinson_0612/article/details/80292452, FTP All backup files to the server that need to be recovered to package the entire backup set FTP to the target server or SCP to the target server Here are the files that are included in the FTP to target server decompression [email protected]:/u02/database/sy5221_rman/20121013> ls-hltr Total 9.4g-rw-r--r--1 or Acle oinstall 3.0K 2012-10-16 09:48 initsy5221.ora-rw-r--r--1 Oracle oinstall 2.7G 2012-10-16 10:02 sy5221_lev0_2012101  30630_4unnkjvi_1_1-rw-r--r--1 Oracle oinstall 3.1G 2012-10-16 10:04 sy5221_lev0_201210130630_4vnnkjvi_1_1-rw-r--r--1 Oracle Oinstall 938M 2012-10-16 10:07 sy5221_lev0_201210130630_arc_51nnkk2h_1_1-rw-r--r--1 Oracle oinstall 935M 2012-1 0-16 10:08 sy5221_lev0_201210130630_arc_52nnkk2h_1_1-rw-r--r--1 Oracle oinstall 930M 2012-10-16 10:10 SY5221_lev0_2012 10130630_arc_53nnkk31_1_1-rw-r--r--1 Oracle oinstall 15M 2012-10-16 10:10 sy5221_lev0_cntl_bak_ c-1468911009-20121013-00-rw-r--r--1 Oracle Oinstall 15M 2012-10-10:10 sy5221_lev0_cntl_bak_c-1468911009-20121013-01-rw-r--r--1 Oracle oinstall 910M 2012-10-16 10:11 SY5221_lev0_20 1210130630_arc_54nnkk32_1_13, creating the required directory (using Oracle user) [email protected]:~> more mkdir_sy5221.sh mkdir-p/u02/ Database/sy5221/flash_recovery_area mkdir-p/u02/database/sy5221 mkdir-p/u02/database/sy5221/archive mkdir-p/u02/d Atabase/sy5221/backup mkdir-p/u02/database/sy5221/bdump mkdir-p/u02/database/sy5221/cdump mkdir-p/u02/database/SY 5221/udump mkdir-p/u02/database/sy5221/controlf mkdir-p/u02/database/sy5221/oradata mkdir-p/u02/database/SY5221/r Edolog mkdir-p/u02/database/sy5221/undo mkdir-p/u02/database/sy5221/temp mkdir-p/u02/database/SY5221/ref_data mk Dir-p/U02/DATABASE/SY5221/BNR mkdir-p/u02/database/sy5221/bnr/full mkdir-p/u02/database/sy5221/bnr/dump mkdir-p /u02/database/sy5221/dbcreatelogs oracle_sid=sy5221; Export Oracle_sid [email protected]:~> chmod u+x mkdir_sy5221.sh [email protected]:~>./mkdir_sy5221.sh4, creating a password file [email protected]:~> cd $ORACLE _home/dbs [email protected]:~/ orahome10g/dbs> orapwd file=orapwsy5221 password=oracle force=y entries=10 # author:robinson # blog:http://blog. csdn.net/robinson_06123, using Pfile to launch an instance to Nomount State [email protected]:~> cp/u02/database/sy5221_rman/20121013/ Initsy5221.ora $ORACLE _home/dbs [email protected]:~> export oracle_sid=sy5221 [email protected]:~> Sqlplus/as sysdba sql> startup nomount;4, Recovery control file and switch to mount status #再开一个session [email protected]:~> export ORACLE _sid=sy5221 [email protected]:~> $ORACLE _home/bin/rman target/rman> restore controlfile from '/u02/databas  E/sy5221_rman/20121013/sy5221_lev0_cntl.bak_c-1468911009-20121013-01 '; rman> ALTER DATABASE MOUNT;5, specify the directory where the backup files rman> catalog start with '/u02/database/sy5221_rman/20121013 ';  #此命令用于扫描整个目录的备份片或者归档日志文件等6, restore the database rman> restore database;7, restore the database rman> recover; Unable to find aRchive Log Archive log thread=1 sequence=143388 RMAN-00571: ========================================================= = = RMAN-00569: =============== ERROR MESSAGE STACK follows =============== RMAN-00571: ================================ =========================== rman-03002:failure of recover command at 10/16/2012 11:32:54 Rman-06054:media recovery req uesting unknown log:thread 1 seq 143388 lowscn 608805162 #由于未复制联机日志文件, this prompt requires seqence 143388,SCN 608805162 #在sqlplus提示符  Continue the media recovery sql> conn/as sysdba Connected.  idle> recover database until cancel;    Ora-00283:recovery session canceled due to errors ora-01610:recovery using the BACKUP controlfile option must is done  sql> Recover database using Backup controlfile until cancel; Ora-00279:change 608805162 generated at 10/13/2012 06:31:44 needed for thread 1 ora-00289:suggestion:/u02/database/sy 5221/archive/arch_668881377_1_143388.arc ora-00280:change 608805162 for thread 1 are in sequence #143388 specifyLOG: {<ret>=suggested | AUTO | Cancel} Cancel #输入cancel, Finish media recovery Cancelled.8, open database #如果open unsuccessful, try shutdown again after open, if still not successfully using hidden parameters    _allow_resetlogs_corruption Open the database sql> alter databases open resetlogs;    Database Altered.9, consistency shut down database and restart databases sql> shutdown immediate; Sql> Startup

Revert to different directories in the same machine (supplemental content @20130906)

Steps are basically the same as the same directory used, some need to be aware of, listed below

1, backup data and FTP to the destination server, the same as before

2. Create the appropriate directory
The directory here differs from the original directory, as in the following example
Original directory:/u02/database/sy5221 original database name: SY5221 (Host: Linux1, oracle_sid=sy5221)
New directory:/u02/database/sy5223 new database name: SY5223 (Host: Linux2, oracle_sid=sy5223)

3. Create the Pfile file and launch the instance
Extract the parameter files from the original database to the destination server, modify the corresponding parameters as needed, such as increasing the SGA size, etc.
Next, modify the associated path in the Pfile file to point to the new location, where all the SY5221 directories in the parameter file should be modified to SY5223
Note that the db_name parameter is unchanged, for the original db_name, after the restoration is complete, use Nid to modify
Booting to the Nomount state using the Pfile file

3. Restore Control files
rman> restore Controlfile from '/u02/database/bak/sy5221cntl.bak ';

--Switch to Mount State, note that db_name must keep the original db_name, otherwise when switching to mount, prompt
--ora-01103:database name ' SY5221 ' in control file was not ' SY5223 '

Rman> ALTER DATABASE Mount;

4. Use catalog start with to specify the backup file location
rman> catalog start with '/u02/database/bak ';

5, restore and restore the database, because the use of different locations, so we need to use the SET newname clause, such as the following example
run{
Set newname for datafile 1 to '/u02/database/sy5223/oradata/syssy5223.dbf ';
Set newname for datafile 2 to '/u02/database/sy5223/undo/undotbssy5223.dbf ';
Set newname for DataFile 3 to '/u02/database/sy5223/oradata/sysauxsy5223.dbf ';
Set newname for datafile 4 to '/u02/database/sy5223/undo/undotbssy52232.dbf ';
Set newname for datafile 5 to '/u02/database/sy5223/oradata/sy5223_system_tbl.dbf ';
Set newname for datafile 6 to '/u02/database/sy5223/oradata/sy5223_account_tbl.dbf ';
Set newname for datafile 7 to '/u02/database/sy5223/oradata/sy5223_stock_tbl.dbf ';
Set newname for datafile 8 to '/u02/database/sy5223/oradata/sy5223_stock_l_tbl.dbf ';
Restore database;
Switch datafile all;
Recover database;}

You receive the following error message during the--recover process
Rman-03002:failure of recover command at 09/06/2013 22:40:54
Rman-06054:media recovery requesting unknown Log:thread 1 seq 2872 lowscn 18896302

--we use the until clause to recover again
rman>run{
2> set until sequence 2872;
3> Recover database;
4> ALTER DATABASE open resetlogs;
5>}

Executing command:set until clause

Starting recover at 06-SEP-13
Using channel Ora_disk_1

Starting Media recovery
Media recovery complete, elapsed time:00:00:03

Finished recover at 06-sep-13

RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE, STACK follows ===============
RMAN-00571: ===========================================================
Rman-03002:failure of Alter DB command at 09/06/2013 22:52:04
Ora-00344:unable to re-create online log '/u02/database/sy5221/redolog/log1asy5221.log '
Ora-27040:file create error, unable to create file
linux-x86_64 error:2: No such file or directory

--The error message above was received because the log file could not be created because the path is inconsistent with the original database path
Rman> exit

6. Modify log file location and open database
$ sqlplus/as SYSDBA
Sql> select Name,open_mode from V$database;

NAME Open_mode
--------- ----------
SY5221 Mounted

Sql> Set Linesize 190
Sql> Col member format A60
Sql> select * from V$logfile;

group# STATUS TYPE MEMBER is_
---------- ------- ------- ------------------------------------------------------------ ---
1 Online/u02/database/sy5221/redolog/log1asy5221.log NO
1 Online/u02/database/sy5221/redolog/log1bsy5221.log NO
2 Online/u02/database/sy5221/redolog/log2asy5221.log NO
2 Online/u02/database/sy5221/redolog/log2bsy5221.log NO

Sql> set heading off;
Sql> SELECT ' ALTER DATABASE rename file ' | | member| | "to" | | Replace (member, ' SY5221 ', ' SY5223 ') | | '; ' from V$logfile;

Alter DATABASE rename file '/u02/database/sy5221/redolog/log1asy5221.log ' to '/u02/database/sy5223/redolog/ Log1aSY5223.log ';
Alter DATABASE rename file '/u02/database/sy5221/redolog/log1bsy5221.log ' to '/u02/database/sy5223/redolog/ Log1bSY5223.log ';
Alter DATABASE rename file '/u02/database/sy5221/redolog/log2asy5221.log ' to '/u02/database/sy5223/redolog/ Log2aSY5223.log ';
Alter DATABASE rename file '/u02/database/sy5221/redolog/log2bsy5221.log ' to '/u02/database/sy5223/redolog/ Log2bSY5223.log ';

sql> ALTER DATABASE rename file '/u02/database/sy5221/redolog/log5bsy5221.log ' to '/u02/database/sy5223/redolog/ Log5bSY5223.log ';
sql> ALTER DATABASE rename file '/u02/database/sy5221/redolog/log6asy5221.log ' to '/u02/database/sy5223/redolog/ Log6aSY5223.log ';
sql> ALTER DATABASE rename file '/u02/database/sy5221/redolog/log6bsy5221.log ' to '/u02/database/sy5223/redolog/ Log6bSY5223.log ';
sql> ALTER DATABASE rename file '/u02/database/sy5221/redolog/log7asy5221.log ' to '/u02/database/sy5223/redolog/ Log7aSY5223.log ';

Sql> set heading on;
sql> ALTER DATABASE open resetlogs;

Database altered.

7, fixed the corresponding temporary data file
Sql> select * from Dba_temp_files;
SELECT * FROM Dba_temp_files
*
ERROR at line 1:
Ora-01157:cannot identify/lock data file 201-see DBWR trace file
Ora-01110:data file 201: '/U02/DATABASE/SY5221/TEMP/TEMPSY5221.DBF '

Sql> select name from V$tempfile;

NAME
------------------------------------------------------------
/u02/database/sy5221/temp/tempsy5221.dbf
/u02/database/sy5221/temp/sy5221_tempsy5221.dbf

sql> Alter tablespace temp add tempfile '/u02/database/sy5223/temp/tempsy5223.dbf ' size 50m;

Sql> alter tablespace goex_temp add tempfile '/u02/database/sy5223/temp/sy5223_tempsy5223.dbf ' size 50m;

sql> alter tablespace temp drop tempfile '/u02/database/sy5221/temp/tempsy5221.dbf ';

sql> alter tablespace goex_temp drop tempfile '/u02/database/sy5221/temp/sy5221_tempsy5221.dbf ';

sql> ALTER DATABASE Tempfile '/U02/DATABASE/SY5223/TEMP/TEMPSY5223.DBF ' autoextend on;

sql> ALTER DATABASE Tempfile '/U02/DATABASE/SY5223/TEMP/SY5223_TEMPSY5223.DBF ' autoextend on;

Sql> Select COUNT (*) from Dba_temp_files;

COUNT (*)
----------
2

sql> shutdown immediate;

8. Use Nid to modify database name
$ Export oracle_sid=sy5223
$ sqlplus/as SYSDBA
sql> startup Mount Pfile=/u02/database/sy5223/initsy5223.ora;
$ nid target=sys/oracle dbname=sy5223 setname=yes #nid命令用法可参考: Modify DB name and dbid using the NID command
After the modification, modify the db_name parameter in the Pfile file to SY5223, start the database, generate SPFile, and create the corresponding password file.
Sql> create SPFile from Pfile;
$orapwd file=orapwsy5223 password=oracle force=y entries=10

9, configure the Listener and TNSNames, according to the need to fully prepare the database

10. PostScript
The main description above is the Oracle 10g, unable to connect to the target database, that is, do not use the duplicate method of the different recovery methods

Ext.: http://lib.csdn.net/article/oracle/43644

Migrating a database to a different machine using Rman

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.