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

RMAN備份標准過程(案例)(數據庫備份),rman數據庫備份

編輯:Oracle教程

RMAN備份標准過程(案例)(數據庫備份),rman數據庫備份


2014-12-23 Created By 鮑新建

一、摘要


RMAN_學習實驗1_RMAN備份標准過程(案例)

RMAN是Oracle提供的恢復和備份工具,是隨Oracle服務器軟件一同安裝的工具軟件,它可以用來備份和恢復數據庫文件、歸檔日志和控制文件,用來執行完全或不完全的數據庫恢復。

與傳統工具相比,RMAN具有獨特的優勢:跳過未使用的數據塊。

當備份一個RMAN備份集時,RMAN不會備份從未被寫入的數據塊,而傳統的方式無法獲知那些是未被使用的數據塊。

RMAN使用Oracle特有的二進制壓縮模式,與傳統備份的壓縮方式相比,能夠最大程度地壓縮數據塊中的一些典型數據

 

二、備份 - Backup


Step1. 確認一個新的目錄是否夠大 - Check new filesystem for backup

[oracle@odellprod backup]$ pwd
/data/oracle/odellprod/backup
[oracle@odellprod backup]$ df -k /data/oracle/odellprod/backup Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 38352124 18196724 18175792 51% /

Step2. 將數據庫odellprod切換成Mount模式 - Mount database odellprod

[oracle@odellprod backup]$ . oraenv
ORACLE_SID = [odellprod] ? odellprod
The Oracle base for ORACLE_HOME=/opt/oracle/product/11.2.0/odellprod is /opt/oracle
[oracle@odellprod backup]$ sqlplus '/as sysdba' SQL*Plus: Release 11.2.0.1.0 Production on Tue Dec 23 01:34:36 2014 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to an idle instance. SQL> startup mount ORACLE instance started. Total System Global Area 422670336 bytes Fixed Size 1336960 bytes Variable Size 318769536 bytes Database Buffers 96468992 bytes Redo Buffers 6094848 bytes Database mounted.

Step3. 備份數據庫、日志、控制文件和參數文件 - Backup database, archivelogs, controlfiles and spfile with rman

[oracle@odellprod backup]$ export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
[oracle@odellprod backup]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Tue Dec 23 01:38:07 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
connected to target database: ODELLPRO (DBID=1328237028, not open)

RMAN> show DEVICE TYPE;
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name ODELLPROD are:
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default

RMAN> CONFIGURE DEVICE TYPE DISK PARALLELISM 6;
new RMAN configuration parameters:
CONFIGURE DEVICE TYPE DISK PARALLELISM 6 BACKUP TYPE TO BACKUPSET;
new RMAN configuration parameters are successfully stored

RMAN> show DEVICE TYPE;
RMAN configuration parameters for database with db_unique_name ODELLPROD are:
CONFIGURE DEVICE TYPE DISK PARALLELISM 6 BACKUP TYPE TO BACKUPSET;

RMAN> run
{
BACKUP AS COMPRESSED BACKUPSET
INCREMENTAL LEVEL = 0 DATABASE
FORMAT = '/data/oracle/odellprod/backup/ODELLPROD_DF_%U_%T' tag 'database backup'
PLUS ARCHIVELOG SKIP INACCESSIBLE
FORMAT='/data/oracle/odellprod/backup/ODELLPROD_ARCH_%U_%T' tag 'archive log backup';

backup spfile format '/data/oracle/odellprod/backup/ODELLPROD_SPFILE' tag 'spfile backup';

backup current controlfile format '/data/oracle/odellprod/backup/ODELLPROD_CONTROLFILE' tag 'control file backup';
}2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 


Starting backup at 2014-12-23 01:39:01
Finished backup at 2014-12-23 01:44:46

RMAN> list backup;

RMAN> exit

 

三、恢復還原 - Restore/Recovery


Step1. 確認Backup目錄是否有效 - Make sure filesystem with backups is mounted

[oracle@odellprod backup]$ df -k /data/oracle/odellprod/backup
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda2             38352124  19588744  16783772  54% /
[oracle@odellprod backup]$ ls -ltr /data/oracle/odellprod/backup
total 1391716
-rw-r----- 1 oracle oinstall 169477120 Dec 23 01:42 ODELLPROD_ARCH_0apqrkto_1_1_20141223
-rw-r----- 1 oracle oinstall 160933376 Dec 23 01:42 ODELLPROD_ARCH_0fpqrktq_1_1_20141223
-rw-r----- 1 oracle oinstall 179330048 Dec 23 01:42 ODELLPROD_ARCH_0bpqrkto_1_1_20141223
-rw-r----- 1 oracle oinstall 190604800 Dec 23 01:42 ODELLPROD_ARCH_0cpqrktp_1_1_20141223
-rw-r----- 1 oracle oinstall 195282944 Dec 23 01:43 ODELLPROD_ARCH_0dpqrktp_1_1_20141223
-rw-r----- 1 oracle oinstall 195831296 Dec 23 01:43 ODELLPROD_ARCH_0epqrktp_1_1_20141223
-rw-r----- 1 oracle oinstall   1441792 Dec 23 01:43 ODELLPROD_DF_0hpqrl5i_1_1_20141223
-rw-r----- 1 oracle oinstall   3637248 Dec 23 01:43 ODELLPROD_DF_0kpqrl5l_1_1_20141223
-rw-r----- 1 oracle oinstall     98304 Dec 23 01:43 ODELLPROD_DF_0mpqrl66_1_1_20141223
-rw-r----- 1 oracle oinstall   1114112 Dec 23 01:43 ODELLPROD_DF_0lpqrl5m_1_1_20141223
-rw-r----- 1 oracle oinstall  22978560 Dec 23 01:43 ODELLPROD_DF_0jpqrl5j_1_1_20141223
-rw-r----- 1 oracle oinstall  93609984 Dec 23 01:44 ODELLPROD_DF_0ipqrl5i_1_1_20141223
-rw-r----- 1 oracle oinstall 199303168 Dec 23 01:44 ODELLPROD_DF_0gpqrl5h_1_1_20141223
-rw-r----- 1 oracle oinstall     98304 Dec 23 01:44 ODELLPROD_SPFILE
-rw-r----- 1 oracle oinstall   9895936 Dec 23 01:44 ODELLPROD_CONTROLFILE

Step2. 從備份中恢復參數文件 - Restore spfile from backups

[oracle@odellprod dbs]$ . oraenv
ORACLE_SID = [odellprod] ? odellprod
The Oracle base for ORACLE_HOME=/opt/oracle/product/11.2.0/odellprod is /opt/oracle
[oracle@odellprod dbs]$ export NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'
[oracle@odellprod dbs]$ rman target / Recovery Manager: Release 11.2.0.1.0 - Production on Tue Dec 23 01:57:55 2014 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. connected to target database (not started) RMAN> startup nomount Oracle instance started Total System Global Area 422670336 bytes Fixed Size 1336960 bytes Variable Size 318769536 bytes Database Buffers 96468992 bytes Redo Buffers 6094848 bytes RMAN> restore spfile to '$ORACLE_HOME/dbs/spfileodellprod.ora' from '/data/oracle/odellprod/backup/ODELLPROD_SPFILE'; RMAN> shutdown immediate Oracle instance shut down

Step3. 從備份中恢復控制文件 - Restore controlfiles from backups and mount database

RMAN> startup nomount
connected to target database (not started)
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/opt/oracle/product/11.2.0/odellprod/dbs/initodellprod.ora'
starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started
Total System Global Area     159019008 bytes
Fixed Size                     1335192 bytes
Variable Size                 75497576 bytes
Database Buffers              79691776 bytes
Redo Buffers                   2494464 bytes

RMAN> restore controlfile from '/data/oracle/odellprod/backup/ODELLPROD_CONTROLFILE'; 
Starting restore at 2014-12-23 02:03:52
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/opt/oracle/product/11.2.0/odellprod/dbs/cntrlodellprod.dbf
Finished restore at 2014-12-23 02:03:53

RMAN> alter database mount;
database mounted
released channel: ORA_DISK_1

Step4. 從備份中恢復數據文件 - Restore database from backups

RMAN> restore database;
Starting restore at 2014-12-23 02:04:35
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=19 device type=DISK
allocated channel: ORA_DISK_3
channel ORA_DISK_3: SID=21 device type=DISK
allocated channel: ORA_DISK_4
channel ORA_DISK_4: SID=22 device type=DISK
allocated channel: ORA_DISK_5
channel ORA_DISK_5: SID=23 device type=DISK
allocated channel: ORA_DISK_6
channel ORA_DISK_6: SID=24 device type=DISK
skipping datafile 1; already restored to file /opt/oracle/oradata/odellprod/system01.dbf
skipping datafile 2; already restored to file /opt/oracle/oradata/odellprod/sysaux01.dbf
skipping datafile 3; already restored to file /opt/oracle/oradata/odellprod/undotbs01.dbf
skipping datafile 4; already restored to file /opt/oracle/oradata/odellprod/users01.dbf
skipping datafile 5; already restored to file /opt/oracle/oradata/odellprod/example01.dbf
restore not done; all files read only, offline, or already restored
Finished restore at 2014-12-23 02:04:37

Step5. 還原數據庫 - Recover database

RMAN> recover database;
Starting recover at 2014-12-23 02:05:15
using channel ORA_DISK_1
using channel ORA_DISK_2
using channel ORA_DISK_3
using channel ORA_DISK_4
using channel ORA_DISK_5
using channel ORA_DISK_6
starting media recovery
archived log for thread 1 with sequence 103 is already on disk as file /opt/oracle/oradata/odellprod/redo01.log
archived log file name=/opt/oracle/oradata/odellprod/redo01.log thread=1 sequence=103
media recovery complete, elapsed time: 00:00:00
Finished recover at 2014-12-23 02:05:16

Step6. 打開數據 - Open database

RMAN> alter database open resetlogs;
database opened

 

Thanks and Regards

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