RMAN冷备份异机还原

1:环境准备

    在新的服务器上安装ORACLE实例,安装过程中需要注意源服务器与目标服务器的ORACLE_SID一致,另外确保安装路径与源路径一致(不仅是安装目录,甚至包括数据文件、控制文件目录、联机重做日志文件所在目录都要注意)。如果不一致相当麻烦,需要修改spfile。

2:RMAN做冷备份

使用cold_backup.sh将数据库备份到/u04/migration目录下面

mkdir -p /u04/migration
mkdir -p /u04/migration/log

cat /u04/migration/cold_backup.sh

export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
export ORACLE_SID=SCM2
export CATALOG=NOCATALOG
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
rman target / log=/u04/migration/log/rman_coldbackup_db_EELSCM2_20150510.log <<EOF
sql 'alter system checkpoint';
shutdown immediate;
startup mount;
sql  "create pfile=''/u04/migration/pfile`date +%d%m%Y`.ora'' from spfile";
RUN {
ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT '/u04/migration/%U';
ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT '/u04/migration/%U';
ALLOCATE CHANNEL disk3 DEVICE TYPE DISK FORMAT '/u04/migration/%U';
BACKUP AS COMPRESSED BACKUPSET DATABASE;
BACKUP CURRENT CONTROLFILE FORMAT '/u04/migration/cntrl_%s_%p_%t';
RELEASE CHANNEL disk1;
RELEASE CHANNEL disk2;
RELEASE CHANNEL disk3;
}

 

3:RMAN做还原操作

 

1:首先将备份文件拷贝到目标服务器上,如下所示

 
[oracle@DB-Server migration]$ ls -lrt
total 25205332
-rw-r----- 1 oracle oinstall 1378779136 May 10 18:56 4eq6j632_1_1
-rw-r----- 1 oracle oinstall 1971355648 May 10 19:33 4fq6j6dr_1_1
-rw-r----- 1 oracle oinstall  993918976 May 10 19:52 4jq6j6v2_1_1
-rw-r----- 1 oracle oinstall    9338880 May 10 19:53 4mq6j79h_1_1
-rw-r----- 1 oracle oinstall 2445590528 May 10 20:39 4bq6j5gu_1_1
-rw-r----- 1 oracle oinstall 1682866176 May 10 21:12 4hq6j6rj_1_1
-rw-r----- 1 oracle oinstall 2082570240 May 10 21:53 4gq6j6ea_1_1
-rw-r----- 1 oracle oinstall 1440210944 May 10 22:22 4dq6j629_1_1
-rw-r----- 1 oracle oinstall   21495808 May 10 22:22 cntrl_16535_1_879337140
drwxr-xr-x 2 oracle oinstall       4096 May 11 00:20 log
-rw-r----- 1 oracle oinstall 6072287232 May 11 00:20 4aq6j5gu_1_1
-rwxr-xr-x 1 oracle oinstall        814 May 11 01:10 cold_backup.sh
-rw-r----- 1 oracle oinstall 2605039616 May 11 01:10 4cq6j5gu_1_1
-rw-r----- 1 oracle oinstall 1613660160 May 11 01:41 4kq6j771_1_1
-rw-r----- 1 oracle oinstall 1230159872 May 11 02:05 4iq6j6tb_1_1
-rw-r----- 1 oracle oinstall 2237693952 May 11 02:48 4lq6j784_1_1
-rw-r--r-- 1 oracle oinstall       1542 May 11 10:03 pfile20150510.ora
-rw-r--r-- 1 oracle oinstall        195 May 11 11:28 restore.sh
[oracle@getlnx14 migration]$ 

 

2:给oracle账号对应目录授予相关权限。

 

2.1 由于一些数据文件位于/u02、 /u03、 /u04目录下面. 在root目录下面创建这几个目录,并授权给ORACLE用户。

mkdir /u02

mkdir /u03

mkdir /u04

chown -R oracle:oinstall /u02 /u03 /u04

2.2 由于安装时选择了“仅安装数据库软件”,所以需要按照源服务器的目录设置下面路径

[oracle@DB-Server oracle]$ ls
oraInventory  product
[oracle@DB-Server oracle]$ mkdir admin
[oracle@DB-Server oracle]$ cd admin/
[oracle@DB-Server admin]$ mkdir SCM2
[oracle@DB-Server admin]$ cd SCM2/
[oracle@DB-Server SCM2]$ ls
[oracle@DB-Server SCM2]$ mkdir udump
[oracle@DB-Server SCM2]$ mkdir adump
[oracle@DB-Server SCM2]$ mkdir cdump
[oracle@DB-Server SCM2]$ mkdir dpdump
[oracle@DB-Server SCM2]$ mkdir pfile
[oracle@DB-Server SCM2]$ mkdir bdump

 

案例遇到的错误1:

RMAN> @restore.sh
 
RMAN> run
2> {
3> startup pfile='/u04/migration/pfile20150510.ora' nomount;
4> restore controlfile from 'cntrl_16535_1_879337140';
5> alter database mount;
6> restore database;
7> alter database open resetlogs;
8> }
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 05/12/2015 15:48:00
RMAN-04014: startup failed: ORA-16032: parameter LOG_ARCHIVE_DEST_1 destination string cannot be translated
ORA-07286: sksagdi: cannot obtain device information.
Linux-x86_64 Error: 2: No such file or directory
 
RMAN> 
RMAN> **end-of-file**

在源数据库查看参数LOG_ARCHIVE_DEST_1,发现联机重做日志的归档日志位于/u04/backup/archive 。而目标服务器没有/u04/backup/archive这个目录,需要创建对应的目录。

SQL> show parameter LOG_ARCHIVE_DEST_1
 
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_1                   string      LOCATION=/u04/backup/archive
log_archive_dest_10                  string
SQL> 

 

案例遇到的错误2:

clip_image001

出现上面错误是因为安装时选择了“仅安装数据库软件”,对应的background_dump_dest、audit_file_dest目录都没有,查看pfile文件,创建对应的目录问题解决

[oracle@DB-Server oracle]$ ls
oraInventory  product
[oracle@DB-Server oracle]$ mkdir admin
[oracle@DB-Server oracle]$ cd admin/
[oracle@DB-Server admin]$ mkdir SCM2
[oracle@DB-Server admin]$ cd SCM2/
[oracle@DB-Server SCM2]$ ls
[oracle@DB-Server SCM2]$ mkdir udump
[oracle@DB-Server SCM2]$ mkdir adump
[oracle@DB-Server SCM2]$ mkdir cdump
[oracle@DB-Server SCM2]$ mkdir dpdump
[oracle@DB-Server SCM2]$ mkdir pfile
[oracle@DB-Server SCM2]$ mkdir bdump

案例遇到的错误3:

RMAN> @restore.sh
 
RMAN> run
2> {
3> startup pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/pfile20150510.ora' nomount;
4> restore controlfile from 'cntrl_16535_1_879337140';
5> alter database mount;
6> restore database;
7> alter database open resetlogs;
8> }
Oracle instance started
 
Total System Global Area   12884901888 bytes
 
Fixed Size                     2105920 bytes
Variable Size               9328135616 bytes
Database Buffers            3506438144 bytes
Redo Buffers                  48222208 bytes
 
Starting restore at 12-MAY-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=987 devtype=DISK
 
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of restore command at 05/12/2015 15:59:27
RMAN-06172: no autobackup found or specified handle is not a valid copy or piece
 
RMAN> 
RMAN> **end-of-file**
 
RMAN> 

clip_image002

出现这个错误是因为控制文件路径由于编辑时,不小心将路径给忽略了,实际应该为:restore controlfile from '/u04/migration/cntrl_16535_1_879337140';

run
{
startup pfile='/u01/app/oracle/product/10.2.0/db_1/dbs/pfile20150510.ora' nomount;
restore controlfile from '/u04/migration/cntrl_16535_1_879337140';
alter database mount;
restore database;
alter database open resetlogs;
}

 

还原过后,对数据库参数进行设置,例如从pfile文件创建spfile。另外,视服务器配置等,调整SGA的一些参数!


参考资料:

 

http://blog.itpub.net/11411056/viewspace-733456/

 http://blog.csdn.net/edwzhang/article/details/8933372

你可能感兴趣的:(rman)