程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> Oracle教程 >> RMAN冷備份異機還原,rman還原

RMAN冷備份異機還原,rman還原

編輯:Oracle教程

RMAN冷備份異機還原,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:

出現上面錯誤是因為安裝時選擇了“僅安裝數據庫軟件”,對應的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> 

出現這個錯誤是因為控制文件路徑由於編輯時,不小心將路徑給忽略了,實際應該為: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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved