首页 > 代码库 > RMAN_RMAN备份标准过程(案例)

RMAN_RMAN备份标准过程(案例)

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/backupFilesystem 1K-blocks Used Available Use% Mounted on/dev/sda2 38352124 18196724 18175792 51% /

Step2. 将数据库odellprod切换成Mount模式 - Mount database odellprod

[oracle@odellprod backup]$ . oraenvORACLE_SID = [odellprod] ? odellprodThe Oracle base for ORACLE_HOME=/opt/oracle/product/11.2.0/odellprod is /opt/oracle
[oracle@odellprod backup]$ sqlplus
/as sysdbaSQL*Plus: Release 11.2.0.1.0 Production on Tue Dec 23 01:34:36 2014Copyright (c) 1982, 2009, Oracle. All rights reserved.Connected to an idle instance.SQL> startup mountORACLE instance started.Total System Global Area 422670336 bytesFixed Size 1336960 bytesVariable Size 318769536 bytesDatabase Buffers 96468992 bytesRedo Buffers 6094848 bytesDatabase 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 2014Copyright (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 catalogRMAN configuration parameters for database with db_unique_name ODELLPROD are:CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # defaultRMAN> 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 storedRMAN> 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 BACKUPSETINCREMENTAL LEVEL = 0 DATABASEFORMAT = /data/oracle/odellprod/backup/ODELLPROD_DF_%U_%T tag database backupPLUS ARCHIVELOG SKIP INACCESSIBLEFORMAT=/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:01Finished backup at 2014-12-23 01:44:46RMAN> list backup;

RMAN> exit

技术分享

 

技术分享三、恢复 - Recovery


Step1. 确认Backup目录是否有效 - Make sure filesystem with backups is mounted

[oracle@odellprod backup]$ df -k /data/oracle/odellprod/backupFilesystem           1K-blocks      Used Available Use% Mounted on/dev/sda2             38352124  19588744  16783772  54% /[oracle@odellprod backup]$ ls -ltr /data/oracle/odellprod/backuptotal 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]$ . oraenvORACLE_SID = [odellprod] ? odellprodThe 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 2014Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database (not started)RMAN> startup nomountOracle instance startedTotal System Global Area 422670336 bytesFixed Size 1336960 bytesVariable Size 318769536 bytesDatabase Buffers 96468992 bytesRedo Buffers 6094848 bytesRMAN> restore spfile to $ORACLE_HOME/dbs/spfileodellprod.ora from /data/oracle/odellprod/backup/ODELLPROD_SPFILE;RMAN> shutdown immediateOracle instance shut down

Step3. 从备份中恢复控制文件 - Restore controlfiles from backups and mount database

RMAN> startup nomountconnected to target database (not started)startup failed: ORA-01078: failure in processing system parametersLRM-00109: could not open parameter file /opt/oracle/product/11.2.0/odellprod/dbs/initodellprod.orastarting Oracle instance without parameter file for retrieval of spfileOracle instance startedTotal System Global Area     159019008 bytesFixed Size                     1335192 bytesVariable Size                 75497576 bytesDatabase Buffers              79691776 bytesRedo Buffers                   2494464 bytesRMAN> restore controlfile from /data/oracle/odellprod/backup/ODELLPROD_CONTROLFILE; Starting restore at 2014-12-23 02:03:52allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=18 device type=DISKchannel ORA_DISK_1: restoring control filechannel ORA_DISK_1: restore complete, elapsed time: 00:00:01output file name=/opt/oracle/product/11.2.0/odellprod/dbs/cntrlodellprod.dbfFinished restore at 2014-12-23 02:03:53RMAN> alter database mount;database mountedreleased channel: ORA_DISK_1

Step4. 从备份中恢复数据文件 - Restore database from backups

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

Step5. 还原数据库 - Recover database

RMAN> recover database;Starting recover at 2014-12-23 02:05:15using channel ORA_DISK_1using channel ORA_DISK_2using channel ORA_DISK_3using channel ORA_DISK_4using channel ORA_DISK_5using channel ORA_DISK_6starting media recoveryarchived log for thread 1 with sequence 103 is already on disk as file /opt/oracle/oradata/odellprod/redo01.logarchived log file name=/opt/oracle/oradata/odellprod/redo01.log thread=1 sequence=103media recovery complete, elapsed time: 00:00:00Finished recover at 2014-12-23 02:05:16

Step6. 打开数据 - Open database

RMAN> alter database open resetlogs;database opened

 

技术分享

RMAN_RMAN备份标准过程(案例)