课程目标:
1、备份和恢复目的
备份和恢复的目的是还原有问题的数据库。恢复由于硬件固执、介质故障、用户错误及程序错误导致数据库问题。还可以将数据恢复到过去的某一个时间点。还可以移动数据。
2、典型的备份恢复任务
使用最少的时间从数据丢失的数据库恢复,需要:
3、备份和恢复解决方案
RMAN特性:
备份类型:
4、备份解决方案
RMAN备份数据文件,控制文件,重做日志归档文件和服务器参数文件。可以备份成备份集或者镜像拷贝。可以备份到磁盘,可以借助类似Oracle Secure Backup的media management layer(MML)备份到磁带。
OSB是一款包括文件系统和数据库的Oracle环境集中磁带管理软件。既可以备份和恢复本地的数据还可以是网络上面的数据。
5、术语回顾
Correct Answers: 1P, 2C, 3F, 4O, 5W
6、术语回顾
Correct Answers: 1B, 2A
7、Oracle-Suggested Backup
Oracle-Suggested Backup使用增量备份。先做一个全库的0级备份,然后每天做一个增量备份。至少可以回到24小时之前的状态。
8、使用RMAN
启动rman可以使用以下选项:
target:指定连接到目标数据块,"/"表示连接到本地数据库,使用操作系统认证
catalog:指定连接到恢复目录
nocatalog:不使用恢复目录,默认选项
cmdfile:指定命令文件
log:指定日志文件
例子:rman连接到本地数据块,使用操作系统认证,指定命令文件和日志文件
$ rman target / cmdfile=~/fullbu.rman log=~/fullbu.log
9、RMAN命令类型
RMAN命令有2种基本类型:
10、Job Commands:例子
job commands必须都位于run块中,使用大括号括起来,run块中的配置只影响当前块的执行,覆盖之前的配置。必须位于run块中的命令有:
11、为备份和恢复操作配置数据库
将数据库配置为归档模式。
配置FRA。
12、归档模式
数据库数据被修改时重做数据会被写入到联机重做日志文件,当写满后,归档进程复制联机重做日志文件到归档位置进行保存。因为联机重做日志文件是循环写入,在归档模式下,只能向已经归档的联机重做日志文件进行写入,确保每个联机重做日志文件都会被归档。
13、配置归档模式
使用EM也可以使用SQL。需要数据库处于mount状态。且必须干净关闭(不能使用abort)。
使用SQL步骤如下:
SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 173
Current log sequence 175
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 889389056 bytes
Fixed Size 2258360 bytes
Variable Size 662702664 bytes
Database Buffers 218103808 bytes
Redo Buffers 6324224 bytes
Database mounted.
SQL> alter database archivelog;
Database altered.
SQL> alter database open;
Database altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 173
Next log sequence to archive 175
Current log sequence 175
注意:切换到归档模式后需要对数据库进行一次备份。
14、配置归档日志位置
Oracle建议指定多个归档位置,因为如果只有1个且空间不足的话,数据库会hang住。
Oracle建议通过设置log_archive_dest_n初始化参数指定本地和远程归档位置,可以指定10个,n从1到10。
如果是Oracle标准版,则只能设置log_archive_dest和log_archive_duplex_dest这两个初始化参照指定2个本地磁盘目录作为归档位置。
15、保证归档日志成功
如果指定了不止一个归档位置,则需要设置log_archive_min_succeed_dest初始化参数指定必须归档成功的最小数量。如果归档成功的数量不满足设置,则联机重做日志文件不能重用。
上图中3个归档位置,2个本地,1个远程,log_archive_min_succeed_dest设置为2,意味着只要有2个位置归档成功,就可以重用联机重做日志文件,即使有1个失败了,也不会影响数据库的正常运行。
如果使用了log_archive_dest_n参数设置归档位置,根据n的大小,则log_archive_min_succeed_dest可以从1到10,如果使用了log_archive_dest,则log_archive_min_succeed_dest只能为1或者2。
可以使用mandatory或者optional,指定归档位置是必须归档还是可选归档(默认),例如:
log_archive_dest_1='location=/disk3/arch mandatory'
如果必须归档位置归档失败,则联机重做日志文件不能重用,忽略log_archive_min_succeed_dest的设置。
log_archive_dest初始化参数指定的归档位置是必须归档的位置。
SQL> show parameter log_archive_min_succeed_dest
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_min_succeed_dest integer 1
16、指定保留策略
使用保留策略设置备份可以保留多久。可以通过rman的configure命令或者EM进行配置。
恢复窗口保留策略:
用于恢复出现在一段时期内的逻辑错误,将错误的对象恢复到某个时间点,这一段时期称为恢复窗口。指定恢复窗口为多少天,备份必须满足以下条件:
SYSDATE – backup_checkpoint_time >= recovery_window
可以使用下面的命令语法配置恢复窗口保留策略:
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF DAYS;
如果没有使用恢复目录,那么恢复窗口需要小于等于控制文件记录保留时间参数control_file_record_keep_time指定的值,避免写入控制文件中的备份信息被覆盖掉而失效。如果使用了恢复目录,需要确保control_file_record_keep_time大于恢复目录同步时间,同步发生在:
冗余保留策略:
用于指定保留多少份备份。默认为1,表示任何时间都必须有一份备份,超过1份后老的备份会被标记为过期。使用下面的命令配置冗余保留策略:
RMAN> CONFIGURE RETENTION POLICY TO REDUNDANCY ;
禁用保留策略:
如果使用了其他的备份软件管理备份,可以禁用保留策略,使用如下命令:
RMAN> CONFIGURE RETENTION POLICY TO NONE;
17、恢复窗口保留策略:例子
上图中的保留策略要求恢复到过去7天内的任何时间。不需要用于7天窗口恢复的备份和日志已经过期。保留策略配置如下:
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
用于恢复到恢复窗口中的指定时间点所需要的数据仅包括Backup B和Log201到Log500之间的某些日志。由于Backup B位于恢复窗口之前,则之前的Backup A就不需要了,如果只有备份C,则不能恢复到恢复窗口开始的时间点。需要的是备份窗口开始之前的最后的备份以及之后的所有日志。
18、使用快速恢复区
快速恢复区是所有与恢复相关的文件的一个统一位置。包括2种类型的文件:永久的和临时的。
永久类型有:
临时类型:
19、定义快速恢复区
定义快速恢复区需要设置下面参数:
20、快速恢复区管理
当快速恢复区可用空间过小,且没有文件可以被删除,就会发出警告,但rman仍旧会在快速恢复区创建备份,直到快速恢复区占满到100%。所以需要设置db_recovery_file_dest_size为合适的值来存放备份。
当写入到快速恢复区的文件请求空间时,会删除在过期列表中的文件,并将信息写入的告警日志。
当快速恢复区使用到85%,则会发出告警,使用到97%,则会发出严重告警,这是系统内部设置,不能更改。告警示例如下:
WARNING: db_recovery_file_dest_size of 52428800 bytes is 100.00% used, and has 0 remaining bytes available.
可以通过dba_outstanding_alerts数据字典查询告警信息以及建议:
SQL> select object_type,message_type,message_level,reason,suggested_action
2 from dba_outstanding_alerts;
OBJECT_TYPE MESSAGE_TYPE MESSAGE_LEVEL REASON SUGGESTED_ACTION
--------------- ------------ ------------- -------------------------------------------------- ------------------------------
TABLESPACE Warning 5 Tablespace [INVENTORY] is [90 percent] full Add space to the tablespace
TABLESPACE Warning 1 Tablespace [TBS_03] is [100 percent] full Add space to the tablespace
如果快速恢复区满了,可以选择增加磁盘空间,备份文件到另外的地方,使用rman删除快速恢复区的文件或者修改rman的保留策略。
21、快速恢复区空间使用
为避免快速恢复区空间不足,可以使用如下建议:
不要把不受rman管理的文件放到快速恢复区,如果不是使用rman删除快速恢复区的文件,需要再使用rman删除对应的记录(crosscheck和delete)回收空间。例如备份了归档日志文件后,要删除这些已经成功备份了的归档日志文件,可以使用以下rman命令:
BACKUP ARCHIVELOG ALL DELETE ALL INPUT;
配置归档日志删除策略
使用CONFIGURE ARCHIVELOG DELETE POLICY命令对所有归档位置配置删除策略。
归档日志可以被数据库自动删除也可以通过发出rman命令进行删除:
22、自动执行
当使用了类似流的多个组件的时候,简化了归档日志的管理,提供了可用性。
当如Data Guard,Streams,Flashback Database等不再需要归档日志了,才会被删除。
当配置归档删除规则,对所有的归档位置有效,包括FRA。BACKUP ... DELETE INPUT和DELETE ... ARCHIVELOG都会使用该规则。
当备份快速恢复区时,此时快速恢复区不能访问,此时备份归档日志只能备份到其他位置。
23、监控FRA
例子:通过V$FLASH_RECOVERY_AREA_USAGE视图查看快速恢复区使用情况
SQL> SELECT * FROM V$FLASH_RECOVERY_AREA_USAGE;
FILE_TYPE PERCENT_SPACE_USED PERCENT_SPACE_RECLAIMABLE NUMBER_OF_FILES
-------------------- ------------------ ------------------------- ---------------
CONTROL FILE .25 0 1
REDO LOG 3.79 0 3
ARCHIVED LOG 10.84 5.67 12
BACKUP PIECE 34.13 23.69 10
IMAGE COPY 0 0 0
FLASHBACK LOG 0 0 0
FOREIGN ARCHIVED LOG 0 0 0
7 rows selected.
例子:通过EM查看快速恢复区度量
24、使用快速恢复区的好处
简化备份的管理。
Oracle推荐使用快速恢复区自动管理备份文件的磁盘空间分配。
25、相关习题
(1)You are using the flash recovery area (fast recovery area in 11g Release 2) to store backup related files in your database. After regular monitoring of space usage in the flash recovery area. You realize that the flash recovery area is (jetting filled up very fast and it is running out of space. Your database flash recovery area is low on specie and you have no more room on disk. Proactively, which two options could you use to make more space available in the flash recovery [Choose two]
A.
Change the RMAN archived log deletion policy.
B.
Use the RMAN CROSSCHECK command to reclaim the archived log space.
C.
Change the RMAN retention policy to retain backups for a shorter period of time.
D.
Use OS command to move files from the flash recovery area to some other location
答案:BD
(2) You want to set the following initialization parameters for your database instance:
LOG_ARCHIVE_DEST_1 = 'LOCATION=/disk1/arch'
LOG_ARCHIVE_DEST_2 = 'LOCATION=/disk2/arch'
LOG_ARCHIVE_DEST_3 = 'LOACTION=/disk3/arch'
LOG_ARCHIVE_DEST_4 = 'LOCATION=/disk4/arch MANDATORY'
Identify the statement that correctly describes this setting.
A. The MANDATORY location must be a flash recovery area.
B. The optional destinations may not use the flash recovery area.
C. This setting is not allowed because the first destination is not set as MANDATORY.
D. The online redo log file is not allowed to be overwritten if the archived log cannot be created in the fourth destination.
答案:D
(3)You have configured flash recovery area in your database and you set the following Initialization parameters for your database instance:
LOG_ARCHIVE_DEST 1 = ,,LOCATION=/disk1/arch MANDATORY'
LOG _ARCHIEVE_DEST 2 = ,,LOCATION=/disk2/arch'
LOG_ARCHIVK_DEST_3 = ,,LOCATION=/diSk3/arch
LOG_ARCH1VK_DEST_4 = ' LOCATION=/disk4/arch'
LOG_ARCHIVE_MIN-SUCCEED_DEST = 2
While the database instance is functional, you realized that the destination set by the LOG_ARCHIVE_DEST_I parameter is not available for the archived redo log file to be created in. All redo log groups have been used. What happens in an event of log switch?
A. The online redo log file is not allowed to be overwritten.
B. The archived redo log files are written to the flash recovery area until the MANDATORY destination is made available.
C. The database instance will crash because the archived redo log file cannot be created in a destination set as MANDATORY.
D. The destination set by the LOG_ARCHIVE_DEST_1 parameter is ignored and the archived redo log files are created in the next two available locations to guarantee archive log success.
答案:A
(4)Which of the following parameters defines the location where Oracle should create archived redo logs?
A. LOG_ARCHIVE_1
B. LOG_DESTINATION_1
C. LOG_ARCHIVED_DESTINATION_1
D. LOG_ARCHIVE_DEST_1
E. LOG_ARCHIVE_SOURCE_1
答案:D
(5)Archived redo logs can be copied to more than one destination by Oracle.
A. True
B. False
答案:A
(6)What will be the result of the following configuration?
Log_archive_dest_1=location=c:\oracle\arch\mydb
Log_archive_dest_2=location=z:\oracle\arch\mydb
A. An error will occur during database startup because the second parameter is not valid.
B. An error will occur during database startup since you are trying to create archived redo logs intwo different locations.
C. Archived redo logs will be created in two different locations by the ARCH process.
D. Archived redo logs will be created in two different locations by the LGWR process.
E. Neither parameter setting is valid, so the database will not start up.
答案:C
(7)If you issue the command shutdown abort prior to trying to put the database in ARCHIVELOG mode, what will be the result when you issue the command alter database archivelog?
A. The alter database archivelog command will fail.
B. The alter database archivelog inconsistent command must be used to put the database in ARCHIVELOG mode.
C. The alter database archivelog command will succeed.
D. The alter database archivelog command will ask if you want to make the database consistent first.
E. There is no alter database archivelog command. The correct command is alter database alterlogging.
答案:A
(8)Your archive-log destination directory runs out of space. What is the impact of this on the database?
A. None. The database will switch over to the stand-by archive-log destination directory.
B. A warning message will be written to the alert log of the database, but no adverse impacts to the database will be experienced.
C. The database will shut down, and will not restart until you correct the out-of-space situation.
D. The database will continue to try to write to the archive-log destination directory for one hour.
After one hour, the database will shut down normally.
E. Once Oracle has cycled through all online redo logs, it will stop processing any DML or DDL until the out-of-space condition is corrected.
答案:E
(9)How many individual archive-log destination directories are supported by Oracle Database11g?
A. 7
B. 1
C. 10
D. 11
E. 21
答案:C
(10)You want to use the automatic management of backup and recovery operations features for your database.
Which configuration must you set?
A. Enable the flash recovery area and specify it as the archived redo log destination.
B. Disable the flash recovery area and start the database instance in ARCHIVELOG mode.
C. Enable the flash recovery area but do not specify it as the archived redo log destination.
D. Disable the flash recovery area and start the database instance in NOARCHIVELOG mode.
答案:A
(11)Which three types of files can be automatically placed in the flash recovery area (fast recovery area in 11g Release 2)? (Choose three.)
A. Alert log file
B. Archived redo log files
C. Control file autobackups
D. Server Parameter file (SPFILE)
E. Recovery Manager (RMAN) backup piece
答案:BCE
(12)While Monitoring the space usage in your database that is in ARCHIVELOG mode you observed that the flash recovery area does not have enough free space to accommodate any more files and you do not have necessary permissions to add more space to it.
Identify the two events that can occur in the event of a log switch? (Choose two.)
A. An entry is created in the alert log file and the database instance continues to function normally
B. The log switch hangs occur for transactions until free space is available in the flash recovery area
C. The Oracle database server deletes a file that is on the obsolete file list to make free space in the flash recovery area
D. The database instance status is implicitly changed to RESTRICTED mode and file creations to the flash recovery area are prevented
答案:BC
(13)Which options would you consider while configuring a flash recovery area (fast recovery area in 11g Release 2) for your production database that is running in ARCHIVELOG mode? (Choose all that apply.)
A. Setting the FAST_START_MTTR_TARGET to set the mean time to recover
B. Setting the RECOVERY_PARALLELISM parameter to twice the number of CPUs
C. Using the DB_RECOVERY_FILE_DEST parameter to set the location for flash recovery area
D. Using the DB_RECOVERY_FILE_DEST_SIZE parameter to define the disk space limit for the recovery files created in the flash recovery area
答案:CD
欢迎光临 重庆思庄Oracle、Redhat认证学习论坛 (http://bbs.cqsztech.com/) | Powered by Discuz! X3.2 |