04-备份与恢复2.ppt
基础入门姓名 李玥日期 2023年6月26日 D4了解RMAN的概念会使用RMAN的基本功能使用rman备份数据恢复数据RMAN可连接的数据库的类型:Target database RMAN connects you to the target database,which is the database that you are backing up or recovering,with the SYSDBA privilege.If you do not have this privilege,then the connection fails.Recovery catalog database This database is optional.By default,RMAN runs in NOCATALOG mode.Auxiliary database You can connect to a standby database,duplicate database,or auxiliary instance(standby instance or tablespace point-in-time recovery instance).RMAN备份非catalog方式:全备份0级增量备份1级增量备份RMAN备份RMAN备份非catalog方式:备份archivelogbackup database plus archivelog delete input备份表空间backup tablespace users备份控制文件backup current controlfilebackup database include current controlfileRMAN备份备份集 backupset镜像备份 Image copies copy datafile .to.RMAN备份单命令backup database;批命令 RMAN run 2 allocate channel cha1 type disk;3 backup 4 format/u01/rmanbak/full_%t 5 tag full-backup 6 database;7 release channel cha1;8 RMAN备份format%c:备份片的拷贝数(从1开始编号);%d:数据库名称;%D:位于该月中的天数(DD);%M:位于该年中的月份(MM);%F:一个基于DBID 唯一的名称,这个格式的形式为c-xxx-YYYYMMDD-QQ,其中xxx 为该数据库的DBID,YYYYMMDD 为日期,QQ 是一个1-256 的序列;%n:数据库名称,并且会在右侧用x字符进行填充,使其保持长度为8;%u:是一个由备份集编号和建立时间压缩后组成的8字符名称。利用%u可以为每个备份集生成一个唯一的名称;%p:表示备份集中备份片段的编号,从1 开始编号;%U:是%u_%p_%c的简写形式,利用它可以为每一个备份片段(即磁盘文件)生成一个唯一名称,这是最常用的命名方式;%s:备份集的号;%t:备份集时间戳;%T:年月日格式(YYYYMMDD);RMAN备份Channel 通道一个通道是RMAN和目标数据库之间的一个连接,allocate channel命令在目标数据库启动一个服务器进程,同时必须定义服务器进程执行备份或者恢复操作使用的I/O类型通道控制命令可以用来:控制RMAN使用的O/S资源 影响并行度 指定I/O带宽的限制值(设置limit read rate参数)定义备份片大小的限制(设置limit kbytes)指定当前打开文件的限制值(设置limit maxopenfiles)RMAN备份 Target DatabaseAuxiliary DatabaseCatalog Database/ControlfileRMANDisk/SBT TapeRMAN备份一个典型的增量备份案例如下:星期天晚上-level 0 backup performed 星期一晚上-level 2 backup performed 星期二晚上-level 2 backup performed 星期三晚上-level 1 backup performed 星期四晚上-level 2 backup performed 星期五晚上-level 2 backup performed 星期六晚上-level 2 backup performed RMAN备份自动备份:备份脚本+crontabbakl0bakl1bakl2执行脚本:rman target/msglog=bakl0.log cmdfile=bakl0rman target/msglog=bakl1.log cmdfile=bakl1rman target/msglog=bakl2.log cmdfile=bakl2RMAN备份-lastcrontab-e-u oracle45 23*0 rman target/msglog=bakl0.log cmdfile=bakl045 23*1 rman target/msglog=bakl2.log cmdfile=bakl245 23*2 rman target/msglog=bakl2.log cmdfile=bakl245 23*3 rman target/msglog=bakl1.log cmdfile=bakl1 45 23*4 rman target/msglog=bakl2.log cmdfile=bakl2 45 23*5 rman target/msglog=bakl2.log cmdfile=bakl2 45 23*6 rman target/msglog=bakl2.log cmdfile=bakl2RMAN备份Dbid=?Configure controlfile autobackup on;Backup database plus archivelog delete input;RMAN恢复口令文件丢失:orapwd file=orapwsid password=pass entries=5RMAN恢复spfile丢失:Startup nomount;Set dbid 9815108;Restore spfile from autobackup;Shutdown immediate;Set dbid 9815108;startup;RMAN恢复controlfile丢失:Startup nomount;Restore controlfile from autobackup;alter database mount;Recover database;Alter database open resetlogs;RMAN恢复datafile丢失:sql alter database datafile 3 offline;restore datafile 3recover datafile 3sql alter database datafile 3 online;RMAN恢复Redolog file丢失:(sqlplus/nolog)Shutdown immediate;Startup mount;recover database until cancel;Alter database open resetlogs;RMAN恢复表空间恢复:sql alter tablespace users offline;restore tablespace users;recover tablespace users;sqlalter tablespace users online;RMAN恢复非catalog方式完全恢复:数据库出现问题:-(startup nomount;restore controlfile from autobackup;alter database mount;restore database;recover database;alter database open resetlogs;RMAN恢复基于时间点的恢复:runset until time to_date(07/01/02 15:00:00,mm/dd/yy hh24:mi:ss)restore database;recover database;alter database open resetlogs;RMAN恢复基于SCN 的恢复:startup mount;restore database UNTIL SCN 10000;recover database UNTIL SCN 10000;alter database open resetlogs;RMAN恢复基于日志序列的恢复:startup mount;restore database UNTIL SEQUENCE 100 thread 1;recover database UNTIL SEQUENCE 100 thread 1;alter database open resetlogs;RMAN恢复Report schemaList backupCrosscheck backupDeleteEXP导出表导出用户对象导出数据库IMP导入表导入用户对象导入数据库SQL LOADER