1.配置数据库
[root@oracle11g ~]# su - oracle
[oracle@oracle11g ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.3.0 Production on Tue Jul 8 21:53:15 2014
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup mount
ORACLE instance started.
Total System Global Area 1603411968 bytes
Fixed Size 2228784 bytes
Variable Size 1140854224 bytes
Database Buffers 452984832 bytes
Redo Buffers 7344128 bytes
Database mounted.
如果数据库处于非归档模式,需要设置为归档模式;
SQL> alter database archivelog;
Database altered.
启动数据库
SQL> alter database open;
Database altered.
2.进入rman
[oracle@oracle11g ~]$ rman target /
Recovery Manager: Release 11.2.0.3.0 - Production on Tue Jul 8 21:54:38 2014
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1373722558)
查看rman备份的内容
RMAN> list backupset;
using target database control file instead of recovery catalog
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1 Full 1.15G DISK 00:02:30 07-JUL-14
BP Key: 1 Status: AVAILABLE Compressed: NO Tag: TAG20140707T233510
Piece Name: /u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_07/o1_mf_nnndf_TAG20140707T233510_9vohkk1g_.bkp
List of Datafiles in backup set 1
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 2432142 07-JUL-14 /u01/oracle/oradata/orcl/system01.dbf
2 Full 2432142 07-JUL-14 /u01/oracle/oradata/orcl/sysaux01.dbf
3 Full 2432142 07-JUL-14 /u01/oracle/oradata/orcl/undotbs01.dbf
4 Full 2432142 07-JUL-14 /u01/oracle/oradata/orcl/users01.dbf
5 Full 2432142 07-JUL-14 /u01/oracle/oradata/orcl/example01.dbf
6 Full 2432142 07-JUL-14 /u01/oradata/icms.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
2 Full 9.36M DISK 00:00:04 07-JUL-14
BP Key: 2 Status: AVAILABLE Compressed: NO Tag: TAG20140707T233510
Piece Name: /u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_07/o1_mf_ncsnf_TAG20140707T233510_9vohpjr9_.bkp
SPFILE Included: Modification time: 07-JUL-14
SPFILE db_unique_name: ORCL
Control File Included: Ckp SCN: 2432206 Ckp time: 07-JUL-14
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 9.33M DISK 00:00:01 07-JUL-14
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20140707T233956
Piece Name: /u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_07/o1_mf_ncnnf_TAG20140707T233956_9vohtf4b_.bkp
Control File Included: Ckp SCN: 2432289 Ckp time: 07-JUL-14
3. 常用备份命令:
备份全库, (备份全库及控制文件、服务器参数文件与所有归档的重做日志,并删除旧的归档日志)
RMAN> backup database plus archivelog delete input;
Starting backup at 08-JUL-14
current log archived
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=589 device type=DISK
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=32 RECID=1 STAMP=850320965
input archived log thread=1 sequence=33 RECID=2 STAMP=850343825
input archived log thread=1 sequence=34 RECID=3 STAMP=850348094
input archived log thread=1 sequence=35 RECID=4 STAMP=850853773
input archived log thread=1 sequence=36 RECID=5 STAMP=850855576
input archived log thread=1 sequence=37 RECID=6 STAMP=850867210
input archived log thread=1 sequence=38 RECID=7 STAMP=850916517
input archived log thread=1 sequence=39 RECID=8 STAMP=850947402
input archived log thread=1 sequence=40 RECID=9 STAMP=851268680
input archived log thread=1 sequence=41 RECID=10 STAMP=851270489
input archived log thread=1 sequence=42 RECID=11 STAMP=851898271
input archived log thread=1 sequence=43 RECID=12 STAMP=852334352
input archived log thread=1 sequence=44 RECID=13 STAMP=852415711
channel ORA_DISK_1: starting piece 1 at 08-JUL-14
channel ORA_DISK_1: finished piece 1 at 08-JUL-14
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_08/o1_mf_annnn_TAG20140708T220831_9vqyv092_.bkp tag=TAG20140708T220831 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:55
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/oracle/orcl_arch/1_32_845941826.dbf RECID=1 STAMP=850320965
archived log file name=/u01/oracle/orcl_arch/1_33_845941826.dbf RECID=2 STAMP=850343825
archived log file name=/u01/oracle/orcl_arch/1_34_845941826.dbf RECID=3 STAMP=850348094
archived log file name=/u01/oracle/orcl_arch/1_35_845941826.dbf RECID=4 STAMP=850853773
archived log file name=/u01/oracle/orcl_arch/1_36_845941826.dbf RECID=5 STAMP=850855576
archived log file name=/u01/oracle/orcl_arch/1_37_845941826.dbf RECID=6 STAMP=850867210
archived log file name=/u01/oracle/orcl_arch/1_38_845941826.dbf RECID=7 STAMP=850916517
archived log file name=/u01/oracle/orcl_arch/1_39_845941826.dbf RECID=8 STAMP=850947402
archived log file name=/u01/oracle/orcl_arch/1_40_845941826.dbf RECID=9 STAMP=851268680
archived log file name=/u01/oracle/orcl_arch/1_41_845941826.dbf RECID=10 STAMP=851270489
archived log file name=/u01/oracle/orcl_arch/1_42_845941826.dbf RECID=11 STAMP=851898271
archived log file name=/u01/oracle/orcl_arch/1_43_845941826.dbf RECID=12 STAMP=852334352
archived log file name=/u01/oracle/orcl_arch/1_44_845941826.dbf RECID=13 STAMP=852415711
Finished backup at 08-JUL-14
Starting backup at 08-JUL-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/oradata/icms.dbf
input datafile file number=00001 name=/u01/oracle/oradata/orcl/system01.dbf
input datafile file number=00002 name=/u01/oracle/oradata/orcl/sysaux01.dbf
input datafile file number=00005 name=/u01/oracle/oradata/orcl/example01.dbf
input datafile file number=00003 name=/u01/oracle/oradata/orcl/undotbs01.dbf
input datafile file number=00004 name=/u01/oracle/oradata/orcl/users01.dbf
channel ORA_DISK_1: starting piece 1 at 08-JUL-14
channel ORA_DISK_1: finished piece 1 at 08-JUL-14
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_08/o1_mf_nnndf_TAG20140708T220928_9vqyws4c_.bkp tag=TAG20140708T220928 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:02:36
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 08-JUL-14
channel ORA_DISK_1: finished piece 1 at 08-JUL-14
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_08/o1_mf_ncsnf_TAG20140708T220928_9vqz1r2x_.bkp tag=TAG20140708T220928 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 08-JUL-14
Starting backup at 08-JUL-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=45 RECID=14 STAMP=852415929
channel ORA_DISK_1: starting piece 1 at 08-JUL-14
channel ORA_DISK_1: finished piece 1 at 08-JUL-14
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_08/o1_mf_annnn_TAG20140708T221209_9vqz1sxh_.bkp tag=TAG20140708T221209 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/oracle/orcl_arch/1_45_845941826.dbf RECID=14 STAMP=852415929
Finished backup at 08-JUL-14
备份表空间, (备份指定表空间及归档的重做日志,并删除旧的归档日志):
RMAN> backup tablespace system plus archivelog delete input;
Starting backup at 08-JUL-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=46 RECID=15 STAMP=852415948
channel ORA_DISK_1: starting piece 1 at 08-JUL-14
channel ORA_DISK_1: finished piece 1 at 08-JUL-14
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_08/o1_mf_annnn_TAG20140708T221228_9vqz2dy0_.bkp tag=TAG20140708T221228 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/oracle/orcl_arch/1_46_845941826.dbf RECID=15 STAMP=852415948
Finished backup at 08-JUL-14
Starting backup at 08-JUL-14
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/oracle/oradata/orcl/system01.dbf
channel ORA_DISK_1: starting piece 1 at 08-JUL-14
channel ORA_DISK_1: finished piece 1 at 08-JUL-14
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_08/o1_mf_nnndf_TAG20140708T221230_9vqz2g9k_.bkp tag=TAG20140708T221230 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:01:05
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 08-JUL-14
channel ORA_DISK_1: finished piece 1 at 08-JUL-14
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_08/o1_mf_ncsnf_TAG20140708T221230_9vqz4jqr_.bkp tag=TAG20140708T221230 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 08-JUL-14
Starting backup at 08-JUL-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=47 RECID=16 STAMP=852416019
channel ORA_DISK_1: starting piece 1 at 08-JUL-14
channel ORA_DISK_1: finished piece 1 at 08-JUL-14
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_08/o1_mf_annnn_TAG20140708T221339_9vqz4mod_.bkp tag=TAG20140708T221339 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/oracle/orcl_arch/1_47_845941826.dbf RECID=16 STAMP=852416019
Finished backup at 08-JUL-14
备份归档日志,并且删除旧的归档日志
RMAN> backup archivelog all delete input;
Starting backup at 08-JUL-14
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=48 RECID=17 STAMP=852416050
channel ORA_DISK_1: starting piece 1 at 08-JUL-14
channel ORA_DISK_1: finished piece 1 at 08-JUL-14
piece handle=/u01/oracle/fast_recovery_area/ORCL/backupset/2014_07_08/o1_mf_annnn_TAG20140708T221410_9vqz5lp8_.bkp tag=TAG20140708T221410 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/u01/oracle/orcl_arch/1_48_845941826.dbf RECID=17 STAMP=852416050
Finished backup at 08-JUL-14
对整个数据库进行全备份(full backup)
RMAN> backup database;
对整个数据库进行全备份(full backup)并且包括control file
RMAN> backup database include current controlfile;
备份控制文件
RMAN>backup current controlfile;
在rman的备份中有两种方式:备份集(backupset)和备份镜像(image copies).镜像备份主要是文件的拷贝:copy datafile ... to ...
RMAN> report schema;
Report of database schema for database with db_unique_name ORCL
List of Permanent Datafiles
===========================
File Size(MB) Tablespace RB segs Datafile Name
---- -------- -------------------- ------- ------------------------
1 730 SYSTEM *** /u01/oracle/oradata/orcl/system01.dbf
2 630 SYSAUX *** /u01/oracle/oradata/orcl/sysaux01.dbf
3 115 UNDOTBS1 *** /u01/oracle/oradata/orcl/undotbs01.dbf
4 13 USERS *** /u01/oracle/oradata/orcl/users01.dbf
5 346 EXAMPLE *** /u01/oracle/oradata/orcl/example01.dbf
6 1000 ICMSSPACE *** /u01/oradata/icms.dbf
List of Temporary Files
=======================
File Size(MB) Tablespace Maxsize(MB) Tempfile Name
---- -------- -------------------- ----------- --------------------
1 29 TEMP 32767 /u01/oracle/oradata/orcl/temp01.dbf
rman>copy datafile 5 to '/u01/rmanbak/tbso1bak.dbf';
单命令: 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>}
这个run中有3条命令,分别用分号来进行分割.
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的简写形式,利用它可以为每一个备份片段(既磁盘文件)生成一个唯一的名称,这是最常用的命名方式;
%t:备份集时间戳;
%T:年月日格式(YYYYMMDD);
channel的概念:一个channel是rman于目标数据库之间的一个连接,"allocate channel"命令在目标数据库启动一个服务器进程,同时必须定义服务器进程执行备份和恢复操作使
用的I/O类型
通道控制命令可以用来:
控制rman使用的OS资源
影响并行度
指定I/O带宽的限制值(设置 limit read rate 参数)
指定备份片大小的限制(设置 limit kbytes)
指定当前打开文件的限制值(设置 limit maxopenfiles)
=================================RMAN一周典型备份方案============================
1.星期天晚上 -level 0 backup performed(全备份)
2.星期一晚上 -level 2 backup performed
3.星期二晚上 -level 2 backup performed
4.星期三晚上 -level 1 backup performed
5.星期四晚上 -level 2 backup performed
6.星期五晚上 -level 2 backup performed
7.星期六晚上 -level 2 backup performed
如果星期二需要恢复的话,只需要1+2,
如果星期四需要恢复的话,只需要1+4,
如果星期五需要恢复的话,只需要1+4+5,
如果星期六需要恢复的话,只需要1+4+5+6.
自动备份:备份脚本+crontab
bakl0
bakl1
bakl2
执行脚本:
rman target / msglog=bakl0.log cmdfile=bakl0 (/表示需要连接的目标数据库,msglog表示日志文件,cmdfile表示的是脚本文件)
rman target / msglog=bakl1.log cmdfile=bakl1
rman target / msglog=bakl2.log cmdfile=bakl2
实例:rman target system/oracle@ora10g(/) msglog=/u01/rmanbak/bakl1.log cmdfile=/u01/rmanbak/bakl0
完整的命令:/u01/oracle/product/10.2.0/bin/rman target system/oracle@ora10g(/) msglog=/u01/rmanbak/bakl1.log cmdfile=/u01/rmanbak/bakl0
把备份脚本放到/u01/rmanbak/script目录下面,vi bakl0,bakl0的内容为:
run{
allocate channel cha1 type disk;
backup
incremental level 0
format '/u01/rmanbak/inc0_%u_%T'(u表示唯一的ID,大T是日期,小t是时间)
tag monday_inc0 //标签可以顺便起,没关系
database;
release channel cha1;
}
,类似就可以写出bakl1,bakl2相应的脚本.
自动备份
crontab
crontab -e -u oracle(改命令的意思是编辑oracle用户的定时执行(-e,edit -u oracle,oracle用户))
分 时 日 月 星期(0代表星期天)
45 23 * * 0 rman target / msglog=bakl0.log cmdfile=bakl0(星期天的23:45会以oracle用户的身份来执行命令)
45 23 * * 1 rman target / msglog=bakl2.log cmdfile=bakl2
45 23 * * 2 rman target / msglog=bakl2.log cmdfile=bakl2
45 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=bakl2
然后启动crontab ,启动crontab的命令:
root> service crond restart
chkconfig crond on开启开机自启动
=======================RMAN恢复================
在非catalog模式下,备份的信息存储在controlfile文件中,如果controlfile文件发生毁坏,那么就不能能够进行恢复,
使用在备份的时候需要把controlfile也进行自动备份
RMAN>show all;
using target database control file instead of recovery catalog
RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO REDUNDANCY 1; # default
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/home/oracle/product/10.20/dbs/snapcf_ora10g.f'; # default
其中CONFIGURE CONTROLFILE AUTOBACKUP OFF; 没有对controlfile进行 autobackup,使用我们需要运行下面命令来对controlfile进行自动备份
RMAN> CONFIGURE CONTROLFILE AUTOBACKUP ON;
RMAN> show all;
手动备份控制文件:
backup current controlfile
Dbid表示database的一个ID,将来用于恢复spfile和controlfile时候要用到.
RMAN> connect target /
connected to target database: ORA10G (DBID=3988862108)
这个Dbid=3988862108
RMAN> list backup;查看以前备份的信息
RMAN>delete backupset 24;//24代表backupset 的编号
RMAN>backup format '/u01/rmanbak/full_%T_%U.bak' database plus archivelog;(进行一次全备份)
验证备份:
RMAN> validate backupset 3; //3代表backupset的编号
口令文件丢失(不属于rman备份的范畴),我们只需要用一个命令来重建这个文件就可以了:
orapw file=orapwsid password=pass entries=5; //口令文件的路径:/u01/oracle/product/10.20/db_1/dbs目录下
oracle> cd /u01/oracle/product/10.20/db_1/dbs
oracle> rm orapwora10g;(文件删除,模拟丢失)
oracle> orapwd file=orapwora10g password=oracle entries=5;(重新建立一个文件),entries的意思(DBA的用户最多有5个)
SPFILE丢失:
startup nomount;
set dbid 3988862108;
restore spfile from autobackup;
shutdown immediate;
set dbid 3988862108;
startup;
模拟操作:
oracle> mv spfileora10g.ora spora10g.ora
oracle>rman target /;
rman> shutdown immediate;
rman> startup nomount;
startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/home/oracle/product/10.20/dbs/initora10g.ora'
rman>set dbid 3988862108;
rman>restore spfile from autobackup;
执行该命令,如果没有找到的话,那可能是文件的路径发生错误.可以通过直接赋予它的文件
rman>restore spfile from '/u01/oracle/flash_recovery_area/ORA10G/autobackup/2008_12_09/o1_mf_s_673025706_4mw7xc79_.bkp
在dbs/目录下产生spfileora10g.ora文件。证明spfile 已经恢复好
rman> shutdown immediate;
rman> startup ;(如果该命令不能够启动数据库,那么需要set dbid 3988862108)
controlfile 丢失:
startup nomount;
restore controlfile from autobackup;
alter database mount;
recover database;
alter database open resetlogs;
注意:在做了alter database open resetlogs;会把online redelog file清空,数据文件丢失.所以这个时候要做一个全备份。
oracle>rm *.ctl
oracle>rman target / ;//不能够连接到rman ,因为controlfile丢失
oracle>sqlplus /nolog;
SQL>shutdown immediate; //因为controlfile丢失,不能够正常shutdown
SQL>shutdown abort;
oracle>rman target /;
rman>startup nomount;
rman>restore controlfile from autobackup;
rman>alter database mount;
rman>alter database open resetlogs;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/09/2008 16:21:13
ORA-01194: file 1 needs more recovery to be consistent
ORA-01110: data file 1: '/home/oracle/oradata/ora10g/system01.dbf
//出错, redo log的scn记录在controlfile里面的,因为我们有新的controlfile,所以需要resetlogs;
/*
resetlogs命令表示一个数据库逻辑生存期的结束和另一个数据库逻辑生存期的开始,每次使用resetlogs命令的时候,SCN不会被重置,不过oracle会重置日志序列号,而且会重置
联机重做日志内容.
这样做是为了防止不完全恢复后日志序列会发生冲突(因为现有日志和数据文件间有了时间差)。
*/
rman>recover database;
rman>alter database open resetlogs;
Redolog file丢失:(下面的这些语句一定要在sqlplus中执行,不是在rman中执行)
(sqlplus/nolog)
1.shutdown immediate;
2.startup mount;
3.recover database until cancel;(media recovery)
4.alter database resetlogs;
数据文件丢失(在rman中执行sql语句,在sql后面用双引号括起来):
1. sql "alter database datafile 3 offline";
2. restore datafile 3
3. recover datafile 3
4. sql "alter database datafile 3 online";
表空间丢失:
1. sql "alter tablespace users offline";//如果文件不存在,则用 sql "alter tablespace users offline immeidate";
2. restore tablespace users;
3. recover tablespace users; //与online redolog file 信息一致
4. sql "alter tablespace users online";
非catalog方式完全恢复
数据库出现问题:
1.startup nomount;
2.restore controlfile from autobackup;
3.alter database mount;
4.restore database;
5.recover database;
6.alter database open resetlogs;
模拟操作:
oracle ora10g> rm *;
oracle ora10g> ls;
oracle ora10g> //数据文件,控制文件全部删除
oracle ora10g> rman target /; //因为controlfile 丢失,不能够连接到rman
oracle ora10g> sqlplus /nolog;
oracle ora10g> connect / as sysdba;
oracle ora10g> shutdown abort;
oracle ora10g> rman target /
rman> startup nomount;
rman> restore controlfile from autabackup;
rman> alter database mount;
rman> restore database;
rman> recover database; //online redolog 不存在
SQL>recover database until cancel; //当redo log丢失,数据库在缺省的方式下,是不容许进行recover操作的,那么如何在这种情况下操作呢
SQL>create pfile from spfile;
vi /u01/product/10.20/dbs/initora10g.ora,在这个文件的最后一行添加
*.allow_resetlogs_corruption='TRUE'; //容许resetlog corruption
SQL>shutdown immediate;
SQL>startup pfile='/u01/product/10.20/dbs/initora10g.ora' mount;
SQL>alter database open resetlogs;
基于时间点的恢复:
run{
set until time "to_date(07/01/02 15:00:00','mm/dd/yy hh24:mi:ss')";
restore database;
recover database;
alter database open resetlogs;
}
ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS';
1.startup mount;
2.restore database until time "to_date('2009-7-19 13:19:00','YYYY-MM-DD HH24:MI:SS')";
3.recover database until time "to_date('2009-7-19 13:19:00','YYYY-MM-DD HH24:MI:SS')";
4.alter database open resetlogs;
如果有open resetlogs,都是不完整恢复.
基于 SCN的恢复:
1.startup mount;
2.restore database until scn 10000;
3.recover database until scn 10000;
4.alter database open resetlogs;
基于日志序列的恢复:
1.startup mount;
2.restore database until SEQUENCE 100 thread 1; //100是日志序列
3.recover database until SEQUENCE 100 thread 1;
4.alter database open resetlogs;
日志序列查看命令: SQL>select * from v$log;其中有一个sequence字段.resetlogs就会把sequence 置为1
=================================RMAN catalog模式下的备份与恢复=====================
1.创建Catalog所需要的表空间
SQL>create tablespace rman_ts size datafile '/u01/oracle/oradata/ora10g/rmants.dbf' 20M;
2.创建RMAN用户并授权
SQL>create user rman identified by rman default tablespace rman_ts quota unlimited on rman_ts;
SQL>grant recovery_catalog_owner to rman;(grant connect to rman)
查看角色所拥有的权限: select * from dba_sys_privs where grantee='RECOVERY_CATALOG_OWNER';
(RECOVER_CATALOG_OWNER,CONNECT,RESOURCE)
3.创建恢复目录
oracle>rman catalog rman/rman
RMAN>create catalog tablespace rman_ts;
RMAN>register database;(database是target database)
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
RMAN> connect target /;
以后要使用备份和恢复,需要连接到两个数据库中,命令:
oracle>rman target / catalog rman/rman (第一斜杠表示target数据库,catalog表示catalog目录 rman/rman表示catalog用户名和密码)
命令执行后显示:
Recovery Manager: Release 10.2.0.1.0 - Production on Wed Dec 10 15:00:42 2008
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: ORA10G (DBID=3988862108)
connected to recovery catalog database
命令解释:
Report schema Report shema是指在数据库中需找schema
List backup 从control读取信息
Crosscheck backup 看一下backup的文件,检查controlfile中的目录或文件是否真正在磁盘上
Delete backupset 24 24代表backupset 的编号, 既delete目录,也delete你的文件
注意:在做了alter database open resetlogs;会把online redelog file清空,数据文件丢失.所以这个时候要做一个全备份。
resetlogs命令表示一个数据库逻辑生存期的结束和另一个数据库逻辑生存期的开始,每次使用resetlogs命令的时候,SCN不会被重置,不过oracle会重置日志序列号,而且会重置
联机重做日志内容.这样做是为了防止不完全恢复后日志序列会发生冲突(因为现有日志和数据文件间有了时间差)。
Rman 归档文件丢失导致不能备份的,在备份前先执行以下两条命令
crosscheck archivelog all;
delete expired archivelog all;