oracle 10g rman 备份与恢复 之一

时间:2023-02-14 13:07:11

播布客海明老师第一讲和第二讲笔记

rman 10g备份与恢复
海明老实第一讲
一、recovery management(恢复管理器)

rman可以连接数据库的类型
1、target database
   sysdba权限才能target database,如果没有连接失败。
2、recovery catalog database
   可选的,可以用catalog或者nocatalog,使用rman备份时候产生的信息,存到catalog,当然如果没有catalog就放到controlfile里面
3、auxiliary database(辅助数据库)
    连接生产数据库时候可以连接辅助数据库,可以将生产数据库copy到辅助数据库

 rman可以连接以上三个数据库,这三种数据库可以在一台oracle server上面;也可以在不同的oracle server上面,oracle建议将catalog
目录数据库和生产数据库不要放到一个oracle server上面。还有辅助数据也放到单独的oracle server上。这样可以通过rman把生产数据库copy
到辅助数据库上面,这样更安全。
--------------------------------------------------------------------------------------------------
二、rman备份方式  (归档模式)
非catalog方式
全备份
0级增量
1级增量


找一下rman文件
[root@redhat wolf]# find / -name rman
/oracle/ora10g/product/10.2.0/db_1/bin/rman
/oracle/ora10g/product/10.2.0/db_1/oc4j/j2ee/oc4j_applications/applications/em/em/WEB-INF/perl/db/rman
/oracle/ora10g/product/10.2.0/db_1/oc4j/j2ee/oc4j_applications/applications/em/em/database/rman
/oracle/ora10g/product/10.2.0/db_1/sysman/admin/scripts/db/rman

[root@redhat wolf]# su - oracle
[oracle@redhat ~]$ echo @PATH
@PATH
[oracle@redhat ~]$ echo $PATH  (这里面出来的bin一定先是oracle的bin,不然rman会认为linux子的rman)
/oracle/ora10g/product/10.2.0/db_1/bin:/usr/sbin:/usr/lib/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin

[root@redhat wolf]# vi ./.bash_profile
export PATH
export TMP=/tmp
export TMPDIR=$TMP
export ORACLE_BASE=/oracle/ora10g
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=wolf
export ORACLE_TERM=xterm
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH (执行顺序,不然有可能执行linux上的rman)
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/usr/x11R6/lib64
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export LD_ASSUME_KERNEL=2.6.18
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.UTF8"
umask 022
if [ $USER = "oracle" ]; then
    if [ $SHELL = "/bin/ksh" ]; then
       ulimit -p 16384
       ulimit -n 65536
   fi
fi
"./.bash_profile" 31L, 787C    
-----------------------------------------------------------------------------------
三、备份(多练)
[oracle@redhat ~]$ rman nocatalog
Recovery Manager: Release 10.2.0.1.0 - Production on 星期六 4月 20 02:42:15 2013
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
RMAN> conn target /
RMAN> connect target /
connected to target database: WOLF (DBID=3778783462)
using target database control file instead of recovery catalog
RMAN>list backupset;
RMAN>backup database;(全备份)
RMAN> backup database;   (仔细观测产生了两个备份集,一个是数据库文件,一个是控制文件和参数文件,分别在不同的目录)

Starting backup at 20-4月 -13
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/oracle/ora10g/oradata/wolf/system01.dbf
input datafile fno=00003 name=/oracle/ora10g/oradata/wolf/sysaux01.dbf
input datafile fno=00002 name=/oracle/ora10g/oradata/wolf/undotbs01.dbf
input datafile fno=00005 name=/oracle/ora10g/oradata/wolf/rmanwolf.dbf
input datafile fno=00004 name=/oracle/ora10g/oradata/wolf/users01.dbf
channel ORA_DISK_1: starting piece 1 at 20-4月 -13
channel ORA_DISK_1: finished piece 1 at 20-4月 -13
piece handle=/oracle/ora10g/flash_recovery_area/WOLF/backupset/2013_04_20/o1_mf_nnndf_TAG20130420T025250_8q4gt34k_.bkp tag=TAG20130420T025250 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:04:56
Finished backup at 20-4月 -13

Starting Control File and SPFILE Autobackup at 20-4月 -13
piece handle=/oracle/ora10g/flash_recovery_area/WOLF/autobackup/2013_04_20/o1_mf_s_813207467_8q4h3cvp_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 20-4月 -13

[oracle@redhat WOLF]$ ls
archivelog  autobackup  backupset  onlinelog
[oracle@redhat WOLF]$ cd autobackup
[oracle@redhat autobackup]$ ls
2013_04_17  2013_04_19  2013_04_20
[oracle@redhat autobackup]$ cd 2013_04_20/
[oracle@redhat 2013_04_20]$ ls
o1_mf_s_813207467_8q4h3cvp_.bkp
[oracle@redhat 2013_04_20]$ cd ..
[oracle@redhat autobackup]$ ls
2013_04_17  2013_04_19  2013_04_20
[oracle@redhat autobackup]$ cd ..
[oracle@redhat WOLF]$ ls
archivelog  autobackup  backupset  onlinelog
[oracle@redhat WOLF]$ cd backupset/
[oracle@redhat backupset]$ ls
2013_04_17  2013_04_19  2013_04_20
[oracle@redhat backupset]$ cd 2013_04_20/
[oracle@redhat 2013_04_20]$ ls
o1_mf_nnndf_TAG20130420T025250_8q4gt34k_.bkp
[oracle@redhat 2013_04_20]$
这里备份的文件可以copy到硬盘然后删除,当需要恢复的时候在copy到这个目录,然今后进行恢复

 

 

====================================================================================================
oracle 10grman备份与恢复
海明老师第二讲

备份内容格式是由rman内部默认格式决定的。nocatalog方式备份信息写入control
可以到control目录进入controlfile查看
[oracle@redhat wolf]$ pwd
/oracle/ora10g/oradata/wolf
[oracle@redhat wolf]$ strings control01.ctl
。。。。
delete
2013-04-19T10:39:43
delete
2013-04-19T10:39:43
list
2013-04-19T10:39:43
delete
2013-04-20T02:42:15
RMAN
2013-04-20T02:42:15
list
2013-04-20T02:42:15
delete
2013-04-20T02:42:15
list
2013-04-19T10:39:43
list
。。。。
当然所显示的信息就是一些备份的时间内容等。
RMAN> show all;
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 ON;
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 '/oracle/ora10g/product/10.2.0/db_1/dbs/snapcf_wolf.f'; # default

RMAN> list backupset;


List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
18      Full    529.59M    DISK        00:04:53     20-4月 -13    
        BP Key: 18   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T025250
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/backupset/2013_04_20/o1_mf_nnndf_TAG20130420T025250_8q4gt34k_.bkp
  List of Datafiles in backup set 18
  File LV Type Ckp SCN    Ckp Time   Name
  ---- -- ---- ---------- ---------- ----
  1       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/system01.dbf
  2       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/undotbs01.dbf
  3       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/sysaux01.dbf
  4       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/users01.dbf
  5       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/rmanwolf.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
19      Full    6.80M      DISK        00:00:01     20-4月 -13    
        BP Key: 19   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T025747
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/autobackup/2013_04_20/o1_mf_s_813207467_8q4h3cvp_.bkp
  Control File Included: Ckp SCN: 476395       Ckp time: 20-4月 -13
  SPFILE Included: Modification time: 20-4月 -13


backup set(备份集)
backup piece (备份片)

0级备份和全备份几乎一样,唯一的区别是全备份不能作为一级备份的基础。
参考:
    增量备份0级与全备份都是全备份,但是增量备份0级使用rman备份的话就只备份了used block,而全备份备份了used and unused block
总结一下,二者有两个地方不同
    1、全备份不能被用作1级增量备份的基础
    2、使用rman备份的时候,全备份备份了used and unused block,0级使用rman备份的话就只备份了used block
http://blog.csdn.net/wh62592855/article/details/5082505(网上资料说明0级备份和全备的区别)
 

0级增量:
backup incremental level=0 database;
RMAN> backup incremental level=0 database;
Starting backup at 20-4月 -13
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=155 devtype=DISK
channel ORA_DISK_1: starting incremental level 0 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/oracle/ora10g/oradata/wolf/system01.dbf
input datafile fno=00003 name=/oracle/ora10g/oradata/wolf/sysaux01.dbf
input datafile fno=00002 name=/oracle/ora10g/oradata/wolf/undotbs01.dbf
input datafile fno=00005 name=/oracle/ora10g/oradata/wolf/rmanwolf.dbf
input datafile fno=00004 name=/oracle/ora10g/oradata/wolf/users01.dbf
channel ORA_DISK_1: starting piece 1 at 20-4月 -13
channel ORA_DISK_1: finished piece 1 at 20-4月 -13
piece handle=/oracle/ora10g/flash_recovery_area/WOLF/backupset/2013_04_20/o1_mf_nnnd0_TAG20130420T032742_8q4jvgyw_.bkp tag=TAG20130420T032742 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:05:36
Finished backup at 20-4月 -13

Starting Control File and SPFILE Autobackup at 20-4月 -13
piece handle=/oracle/ora10g/flash_recovery_area/WOLF/autobackup/2013_04_20/o1_mf_s_813209598_8q4k5yqq_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 20-4月 -13

RMAN> list backup;

List of Backup Sets
===================
BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
18      Full    529.59M    DISK        00:04:53     20-4月 -13    
        BP Key: 18   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T025250
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/backupset/2013_04_20/o1_mf_nnndf_TAG20130420T025250_8q4gt34k_.bkp
  List of Datafiles in backup set 18
  File LV Type Ckp SCN    Ckp Time   Name
  ---- -- ---- ---------- ---------- ----
  1       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/system01.dbf
  2       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/undotbs01.dbf
  3       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/sysaux01.dbf
  4       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/users01.dbf
  5       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/rmanwolf.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
19      Full    6.80M      DISK        00:00:01     20-4月 -13    
        BP Key: 19   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T025747
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/autobackup/2013_04_20/o1_mf_s_813207467_8q4h3cvp_.bkp
  Control File Included: Ckp SCN: 476395       Ckp time: 20-4月 -13
  SPFILE Included: Modification time: 20-4月 -13

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
20      Incr 0  529.64M    DISK        00:05:25     20-4月 -13    
        BP Key: 20   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T032742
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/backupset/2013_04_20/o1_mf_nnnd0_TAG20130420T032742_8q4jvgyw_.bkp
  List of Datafiles in backup set 20
  File LV Type Ckp SCN    Ckp Time   Name
  ---- -- ---- ---------- ---------- ----
  1    0  Incr 477469     20-4月 -13 /oracle/ora10g/oradata/wolf/system01.dbf
  2    0  Incr 477469     20-4月 -13 /oracle/ora10g/oradata/wolf/undotbs01.dbf
  3    0  Incr 477469     20-4月 -13 /oracle/ora10g/oradata/wolf/sysaux01.dbf
  4    0  Incr 477469     20-4月 -13 /oracle/ora10g/oradata/wolf/users01.dbf
  5    0  Incr 477469     20-4月 -13 /oracle/ora10g/oradata/wolf/rmanwolf.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
21      Full    6.80M      DISK        00:00:00     20-4月 -13    
        BP Key: 21   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T033318
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/autobackup/2013_04_20/o1_mf_s_813209598_8q4k5yqq_.bkp
  Control File Included: Ckp SCN: 477636       Ckp time: 20-4月 -13
  SPFILE Included: Modification time: 20-4月 -13

RMAN>

一级增量备份(controlfile和spfile都是全备份,没有增量仔细观测)
backup incremental level 1 database   速度也是很慢,因为里面要和0级对比一些信息
RMAN> backup incremental level 1 database
2> ;

Starting backup at 20-4月 -13
using channel ORA_DISK_1
channel ORA_DISK_1: starting incremental level 1 datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/oracle/ora10g/oradata/wolf/system01.dbf
input datafile fno=00003 name=/oracle/ora10g/oradata/wolf/sysaux01.dbf
input datafile fno=00002 name=/oracle/ora10g/oradata/wolf/undotbs01.dbf
input datafile fno=00005 name=/oracle/ora10g/oradata/wolf/rmanwolf.dbf
input datafile fno=00004 name=/oracle/ora10g/oradata/wolf/users01.dbf
channel ORA_DISK_1: starting piece 1 at 20-4月 -13
channel ORA_DISK_1: finished piece 1 at 20-4月 -13
piece handle=/oracle/ora10g/flash_recovery_area/WOLF/backupset/2013_04_20/o1_mf_nnnd1_TAG20130420T034525_8q4kwod7_.bkp tag=TAG20130420T034525 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:04:56
Finished backup at 20-4月 -13

Starting Control File and SPFILE Autobackup at 20-4月 -13
piece handle=/oracle/ora10g/flash_recovery_area/WOLF/autobackup/2013_04_20/o1_mf_s_813210622_8q4l5yy1_.bkp comment=NONE
Finished Control File and SPFILE Autobackup at 20-4月 -13

RMAN> list backupset;


List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
18      Full    529.59M    DISK        00:04:53     20-4月 -13    
        BP Key: 18   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T025250
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/backupset/2013_04_20/o1_mf_nnndf_TAG20130420T025250_8q4gt34k_.bkp
  List of Datafiles in backup set 18
  File LV Type Ckp SCN    Ckp Time   Name
  ---- -- ---- ---------- ---------- ----
  1       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/system01.dbf
  2       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/undotbs01.dbf
  3       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/sysaux01.dbf
  4       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/users01.dbf
  5       Full 476267     20-4月 -13 /oracle/ora10g/oradata/wolf/rmanwolf.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
19      Full    6.80M      DISK        00:00:01     20-4月 -13    
        BP Key: 19   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T025747
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/autobackup/2013_04_20/o1_mf_s_813207467_8q4h3cvp_.bkp
  Control File Included: Ckp SCN: 476395       Ckp time: 20-4月 -13
  SPFILE Included: Modification time: 20-4月 -13

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
20      Incr 0  529.64M    DISK        00:05:25     20-4月 -13    
        BP Key: 20   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T032742
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/backupset/2013_04_20/o1_mf_nnnd0_TAG20130420T032742_8q4jvgyw_.bkp
  List of Datafiles in backup set 20
  File LV Type Ckp SCN    Ckp Time   Name
  ---- -- ---- ---------- ---------- ----
  1    0  Incr 477469     20-4月 -13 /oracle/ora10g/oradata/wolf/system01.dbf
  2    0  Incr 477469     20-4月 -13 /oracle/ora10g/oradata/wolf/undotbs01.dbf
  3    0  Incr 477469     20-4月 -13 /oracle/ora10g/oradata/wolf/sysaux01.dbf
  4    0  Incr 477469     20-4月 -13 /oracle/ora10g/oradata/wolf/users01.dbf
  5    0  Incr 477469     20-4月 -13 /oracle/ora10g/oradata/wolf/rmanwolf.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
21      Full    6.80M      DISK        00:00:00     20-4月 -13    
        BP Key: 21   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T033318
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/autobackup/2013_04_20/o1_mf_s_813209598_8q4k5yqq_.bkp
  Control File Included: Ckp SCN: 477636       Ckp time: 20-4月 -13
  SPFILE Included: Modification time: 20-4月 -13

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
22      Incr 1  640.00K    DISK        00:04:44     20-4月 -13    
        BP Key: 22   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T034525
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/backupset/2013_04_20/o1_mf_nnnd1_TAG20130420T034525_8q4kwod7_.bkp
  List of Datafiles in backup set 22
  File LV Type Ckp SCN    Ckp Time   Name
  ---- -- ---- ---------- ---------- ----
  1    1  Incr 478003     20-4月 -13 /oracle/ora10g/oradata/wolf/system01.dbf
  2    1  Incr 478003     20-4月 -13 /oracle/ora10g/oradata/wolf/undotbs01.dbf
  3    1  Incr 478003     20-4月 -13 /oracle/ora10g/oradata/wolf/sysaux01.dbf
  4    1  Incr 478003     20-4月 -13 /oracle/ora10g/oradata/wolf/users01.dbf
  5    1  Incr 478003     20-4月 -13 /oracle/ora10g/oradata/wolf/rmanwolf.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
23      Full    6.80M      DISK        00:00:01     20-4月 -13    
        BP Key: 23   Status: AVAILABLE  Compressed: NO  Tag: TAG20130420T035022
        Piece Name: /oracle/ora10g/flash_recovery_area/WOLF/autobackup/2013_04_20/o1_mf_s_813210622_8q4l5yy1_.bkp
  Control File Included: Ckp SCN: 478120       Ckp time: 20-4月 -13
  SPFILE Included: Modification time: 20-4月 -13

RMAN>