码迷,mamicode.com
首页 > 其他好文 > 详细

RMAN_RMAN备份标准过程(案例)

时间:2014-12-23 19:21:37      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

2014-12-23 Created By 鲍新建

技术分享一、摘要


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

技术分享

 

技术分享三、恢复 - 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

 

技术分享

RMAN_RMAN备份标准过程(案例)

标签:

原文地址:http://www.cnblogs.com/eastsea/p/4094698.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!