讲义Oracle.ppt_第1页
讲义Oracle.ppt_第2页
讲义Oracle.ppt_第3页
讲义Oracle.ppt_第4页
讲义Oracle.ppt_第5页
已阅读5页,还剩63页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Backup and Recovery,Objectives,After completing this lesson, you should be able to do the following: Describe the basics of database backup, restore, and recovery List the types of failure that may occur in an Oracle environment Define a backup and recovery strategy,Backup and Recovery Issues,Protec

2、t the database from numerous types of failures Increase Mean-Time-Between-Failures (MTBF) Decrease Mean-Time-To-Recover (MTTR) Minimize data loss,Categories of Failures,Statement failure User process failure User error Instance failure Media failure Network failure,Causes of Statement Failures,Logic

3、 error in an application Attempt to enter invalid data into the table Attempt an operation with insufficient privileges Attempt to create a table but exceed allotted quota limits Attempt an INSERT or UPDATE to a table, causing an extent to be allocated, but with insufficient free space available in

4、the tablespace,Resolutions for Statement Failures,Correct the logical flow of the program. Modify and reissue the SQL statement. Provide the necessary database privileges. Change the users quota limit by using the ALTER USER command. Add file space to the tablespace. Enable resumable space allocatio

5、n.,Causes of User Process Failures,The user performed an abnormal disconnect in the session. The users session was abnormally terminated. The users program raised an address exception, which terminated the session.,Resolution of User Process Failures,The PMON process detects an abnormally terminated

6、 user process. PMON rolls back the transaction and releases any resources and locks being held by it.,Possible User Errors,SQL DROP TABLE employees;,SQL TRUNCATE TABLE employees;,SQL UPDATE employees 2 SET salary = salary * 1.5; SQL COMMIT;,SQL DELETE FROM employees; SQL COMMIT;,Resolution of User E

7、rrors,Train the database users. Recover from a valid backup. Import the table from an export file. Use LogMiner to determine the time of error. Recover with a point-in-time recovery. Use LogMiner to perform object-level recovery. Use FlashBack to view and repair historical data.,Database,Datafile 1,

8、Datafile 2,Datafile 3,Controlfiles,Redo log file 1,Redo log file 2,145,Causes of Instance Failure,Instance,SGA,Redo log buffer,Data buffer,Large Pool,Locks,Shared pool,Data dict.cache,Shared SQLand PL/SQL,ARCn,Userprocess,Serverprocess,PGA,Userprocess,Serverprocess,PGA,146,146,146,146,146,Parameterf

9、ile,Passwordfile,Recovery from Instance Failure,No special recovery action is needed from DBA. Start the instance. Wait for the “database opened” notification. Notify users. Check alert file to determine the reason for the failure.,Causes of Media Failures,Head crash on a disk drive Physical problem

10、 in reading from or writing to database files File was accidentally erased,Resolutions for Media Failures,The recovery strategy depends on which backup method was chosen and which files are affected. If available, apply archived redo log files to recover data committed since the last backup.,Definin

11、g a Backup and Recovery Strategy,Business requirements Operational requirements Technical considerations Management concurrence,Disaster Recovery Issues,How will your business be affected in the event of a major disaster? Earthquake, flood, or fire Complete loss of machine Malfunction of storage har

12、dware or software Loss of key personnel, such as the database administrator Do you have a plan for testing your strategy periodically?,Categories of Backup,Database,Logical Backup按备份方式可分为全备份、增量备份、差异备份,按模式又可分为表备份、用户备份、表空间备份和全备份 Physical Backup又分为冷备份和RMAN备份,Logical Backup(exp/imp) Physical Backup,Full

13、 Database Mode Tables definitions Tables data Grants Indexes Tables constraints,Export Modes,Table Mode Table definitions Table data (all or selected rows) Owners table grants Owners table indexes Table constraints,User Mode Tables definitions Tables data Owners grants Owners indexes Tables constrai

14、nts,Tablespace Mode Table definitions Grants Indexes Table constraints Triggers,Command-Line Export,Syntax,Example,exp hr/hr TABLES=(employees,departments) rows=y file=exp1.dmp,exp keyword = (value, value2, ,valuen),exp system/manager OWNER=hr direct=yfile=expdat.dmp,exp system/manager FULL=y inctyp

15、e=cumulative file=expcum1.dmp,exp system/manager TRANSPORT_TABLESPACE=y TABLESPACES=(ts_emp) log=ts_emp.log,Import Modes,Mode Description Table Import specified tables into a schema. User Import all objects that belong to a schema Tablespace Import all definitions of the objects contained in the tab

16、lespace Full Database Import all objects from the export file,Command-Line Import,Syntax,Example,imp hr/hr TABLES=(employees,departments) rows=y file=exp1.dmp,imp keyword = value or keyword = (value, value2, value n),imp system/manager FROMUSER=hr file=exp2.dmp,imp system/manager TRANSPORT_TABLESPAC

17、E=y TABLESPACES=ts_employees,Physical Backup,Database,Copy file1 file2,Physical Backup可以分为冷备份和RMAN备份,冷备份主要是数据库文件的拷贝备份,更多的是操作系统层面的操作。,Consistent Whole Database Backup(Closed Database Backup),Datafiles,Control files,Passwordfile,Online or offline storage,Parameterfile,Redo logfiles,2,Making a Consiste

18、nt Whole Database Backup,3,4,SHUTDOWN IMMEDIATE;,HOST cp /backup/,STARTUP OPEN;,1,Control files,Passwordfile,Parameter file,Datafiles,Redo log files,RMAN Backup,Database,Copy file1 file2,Physical Backup可以分为冷备份和RMAN备份,冷备份主要是数据库文件的拷贝备份,更多的是操作系统层面的操作。,Recovery Manager Features,RMAN provides a flexible

19、way to: Back up the database, tablespaces, datafiles, control files, and archive logs Store frequently executed backup and recovery operations Perform incremental block-level backup Skip unused blocks Specify limits for backups,Oracle Overview,Instance,SGA,Database buffer cache,Large pool,Java pool,

20、Shared pool,Data dict.cache,Shared SQLand PL/SQL,ARCn,Userprocess,Serverprocess,PGA,Database,Datafile 1,Datafile 2,Datafile 3,Controlfile,Redo log file 1,Redo log file 2,Parameterfile,Passwordfile,Archived log files,Redo log buffer,RecoveryManager(RMAN),Serversession(default),Serversession(polling),

21、Serversession(channel),MML,Serversession(channel),Serversession(channel),Targetdatabase,Serversession(rcvcat),Recoverycatalog DB,Enterprise Manager,Recovery Manager Components,Disk,Disk,RMAN Repository: Using the Control File,The RMAN repository can exist solely in the control file of the target dat

22、abase. CONTROL_FILE_RECORD_KEEP_TIME determines retention time for RMAN records. The control file can grow in size. The control file cannot be used to store RMAN scripts.,Manual Channel Allocation,BACKUP, COPY, RESTORE, and RECOVER commands require at least one channel. Allocating a channel starts a

23、 server process on the target database. Channels affect the degree of parallelism. Channels write to different media types. Channels can be used to impose limits.,RMAN RUN 2 ALLOCATE CHANNEL c1 TYPE disk 3 FORMAT = /db01/BACKUP/usr0520.bak; 4 BACKUP DATAFILE /db01/ORADATA/users01.dbf;,Automatic Chan

24、nel Allocation,Change the default device type:,Configure parallelism for automatic channels:,RMAN CONFIGURE DEVICE TYPE DISK PARALLELISM 3;,RMAN CONFIGURE DEFAULT DEVICE TYPE TO sbt;,Configure automatic channel options:,RMAN CONFIGURE CHANNEL DEVICE TYPE DISK 2 FORMAT = /BACKUP/RMAN/%U;,RMAN CONFIGU

25、RE CHANNEL DEVICE TYPE DISK 2 MAXPIECESIZE 2G;,Recovery Manager Modes,Interactive mode Use it when doing analysis Minimize regular usage Avoid using with log option Batch mode Meant for automated jobs Minimize operator errors Set the log file to obtain information,The BACKUP Command,RMAN BACKUP 2 FO

26、RMAT /BACKUP/df_%d_%s_%p.bus 3 DATABASE filesperset = 2;,Backup set 1,Backup set 2,Backup set 3,Datafile 1,Datafile 2,Datafile 3,Datafile 4,Controlfile,Datafile 4,Controlfile,Datafile 1,Datafile 2,Datafile 3,Archived Redo Log Backup Sets,Include only archived redo log files Are always full backups,R

27、MAN BACKUP 2 FORMAT /disk1/backup/ar_%t_%s_%p 3 ARCHIVELOG ALL DELETE ALL INPUT;,RMAN Control File Autobackups,Use the CONFIGURE CONTROLFILE AUTOBACKUP command to enable When enabled, RMAN automatically performs a control file autobackup after BACKUP or COPY commands Backup is given a default name,R

28、MAN COPY 2 DATAFILE 3 TO /BACKUP/file3.dbf, 3 DATAFILE 1 TO /BACKUP/file1.dbf;,Database,The COPY Command,Image copy,Image copy,Datafile 1,Datafile 3,Datafile 1,Datafile 2,Datafile 3,Controlfiles,Redo logfile 1,Redo logfile 2,OnlineRedo log,Recovery Steps,Restored datafiles,Database containing commit

29、ted and uncommitted transactions,Recovered database,Redo applied,Undo applied,5,4,3,2,1,ArchivedRedo log,Recovery in Archivelog Mode,Complete Recovery Uses redo data or incremental backups Updates the database to the most current point in time Applies all redo changes Incomplete Recovery Uses backup

30、 and redo logs to produce a noncurrent version of the database,User-Managed Recovery Procedures:RECOVER Command,SQL RECOVER DATABASE; OR SQL RECOVER DATAFILE 2 /ORADATA/u03/users01.dbf;,Recover a mounted database:,SQL RECOVER TABLESPACE users; ORSQL RECOVER DATAFILE 3;,Recover an open database:,Shut

31、 down the instance,1,Datafile 3,Redo logfile 2,Datafile 2,Control files,Redo logfile 1,Datafile 1,Closed Database,Archivedlog file,144,Closed Database Recovery Example,Restore datafile 1(Log Sequence 144),2,Open the database,4,Datafile 3,Redo logfile 2,Datafile 2,Control files,Redo logfile 1,Datafil

32、e 1,Mounted Database,3,Datafile 3,Redo logfile 2,Control files,Redo logfile 1,Datafile 1,Recovered Database,146,145,146,146,146,Datafile 2,146,3,3,Open Database Recovery When the Database Is Initially Open,Use this method when: The database is currently open The database will remain open during the

33、recovery The media failure does not affect the SYSTEM tablespace,1,Datafile 3,Redo logfile 2,Datafile 2,Control files,Redo logfile 1,Datafile 1,Open Database Recovery Example,2,4,Datafile 3,Redo logfile 2,Datafile 2,Control files,Redo logfile 1,Datafile 1,146,145,146,144,146,146,3,3,3,Datafile 3,Red

34、o logfile 2,Control files,Redo logfile 1,Datafile 1,146,145,146,146,146,Datafile 2,146,Take datafile 2 offline,Restore datafile 2(Log Sequence 144),Bring datafile 2 online,Archivedlog file,144,Open Database,Open Database,Recovered Database,Open Database Recovery When the Database Is Initially Closed

35、,Use this method when: The database is currently closed The database will be opened during recovery The media failure does not affect the SYSTEM tablespace,Take datafile 2 offline,2,Open Database Recovery Example,Restore datafile 2,4,Bring datafile 2 online,6,1,Mount the database,3,Open the database

36、,Datafile 3,Redo logfile 2,Datafile 2,Control files,Redo logfile 1,Datafile 1,Datafile 3,Redo logfile 2,Control files,Redo logfile 1,Datafile 1,146,145,146,146,146,Datafile 2,146,Closed Database,Recovered Database,Datafile 3,Redo logfile 2,Datafile 2,Control files,Redo logfile 1,Datafile 1,146,145,1

37、46,144,146,146,5,5,5,Archivedlog file,144,Open Database,Recovery of a Datafile Without a Backup,Datafile is lost that was never backed up Cannot be used when it is a file from the SYSTEM tablespace,Datafile 3,Redo logfile 2,Datafile 2,Control files,Redo logfile 1,Datafile 1,146,145,146,146,146,146,O

38、pen Database,Datafile 3,Redo logfile 2,Datafile 2,Control files,Redo logfile 1,Datafile 1,146,145,146,144,146,146,Archivedlog file,144,Open Database,Recovery Without a Backup Example,Bring the datafile or tablespace online,4,1,Take the datafile or tablespace offline,2,Re-create the datafile,Datafile

39、 4,3,3,3,Datafile 4,146,Datafile 3,Redo logfile 2,Datafile 2,Control files,Redo logfile 1,Datafile 1,146,145,146,146,146,146,Recovered Database,Datafile 4,146,Recovering Control Files,Methods to recover from loss of control file: Use the current control file Create a new control file Use a backup co

40、ntrol file,Using RMAN to Recover a Database inNoarchivelog Mode,rman target / RMAN STARTUP MOUNT RMAN RESTORE DATABASE; RMAN RECOVER DATABASE; RMAN ALTER DATABASE OPEN RESETLOGS;,Using RMAN to Recover a Database inArchivelog Mode,rman target / RMAN STARTUP MOUNT RMAN RESTORE DATABASE; RMAN RECOVER D

41、ATABASE; RMAN ALTER DATABASE OPEN;,Using RMAN to Recover a Tablespace,Use the following RMAN commands to restore and recover a tablespace: RESTORE TABLESPACE RECOVER TABLESPACE,Incomplete Recovery Overview,Instance,SGA,Redo log buffer,Data buffer,Large Pool,Locks,Shared pool,Data dict.cache,Shared S

42、QLand PL/SQL,ARCn,Userprocess,Serverprocess,PGA,Userprocess,Serverprocess,PGA,Parameterfile,Passwordfile,Database,Archived logfiles,Reasons for PerformingIncomplete Recovery,Complete recovery fails because an archived log is lost. All control files are lost. All unarchived redo log files and a dataf

43、ile are lost. User error An important table was dropped. Invalid data was committed in a table.,Types of Incomplete Recovery,There are three types of incomplete recovery: Time-based recovery Cancel-based recovery Change-based recovery You may need to recover using a restored control file when: Contr

44、ol files are lost Performing incomplete recovery to a point when the database structure is different than the current,RECOVER Command Overview,recover database until cancel,Recover a database until cancel:,recover database until time 2001-03-04:14:22:03,Recover a database until time:,recover databas

45、e until time 2001-03-04:14:22:03 using backup controlfile,Recover using backup control file:,Time-Based Recovery Example,Scenario The current time is 12:00 p.m. on March 9, 2001. The EMPLOYEES table has been dropped. The table was dropped at approximately 11:45 a.m. Database activity is minimal beca

46、use most staff are currently in a meeting. The table must be recovered.,Shut down and back up,1,Mount the database,2,Time-Based Recovery Example,Restore all datafiles,3,Open with Resetlogs,5,Back up the database,6,Datafile 3,Redo logFile 2,Datafile 2,Control Files,Redo logFile 1,Datafile 1,Database,

47、145,146,146,146,146,146,Datafile 3,Redo logFile 2,Datafile 2,Control Files,Redo logFile 1,Datafile 1,Recovered Database,0,1,1,1,1,1,EMP,Datafile 3,Datafile 2,Datafile 1,Restored Database,146,144,144,144,EMP,Redo logFile 2,145,Archivedlog file,144,4,Redo logFile 1,146,Control Files,Cancel-Based Recov

48、ery Example,Scenario The current time is 12:00 p.m. on March 9,2001. The EMPLOYEES table was dropped while someone was trying to fix bad blocks. Log files exist on the same disk. The table was dropped at approximately 11:45 a.m. Staff are currently in a meeting.,Cancel-Based Recovery Example,Finding

49、s Redo logs are not multiplexed. One of the online redo logs is missing. The missing redo log is not archived. The redo log contained information from 11:34 a.m. Twenty-six minutes of data will be lost. Users can recover their data.,Using a Backup Control File During Recovery,Scenario The current ti

50、me is 12:00 p.m. on March 9, 2001. The tablespace containing the EMPLOYEES table has been dropped. The error occurred around 11:45 a.m. Many employee records were updated this morning, but not since 11:00 a.m. Backups are taken every night.,Using a Backup Control File During Recovery,Findings The ba

51、ckup from last night contains datafiles and control files required for recovery. The EMP_TS tablespace has one datafile. The current log sequence number is 61. You confirm that the tablespace was dropped at 11:44:54 a.m. on March 9, 2001. Datafile number 4 is offline.,Loss of Current Redo Log Files,

52、If the database is closed: Attempt to open the database. Find the current log sequence number. Recover the database until cancel. Drop and re-create log files if necessary. Open the database using RESETLOGS. Perform a whole-database backup.,RMAN Incomplete Recovery UNTIL TIME Example,RMAN run 2 allocate channel c1 type DISK; 3 allocate ch

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论