rman备份演练

一、备份前准备工作
--创建备份目录
[oracle@localhost control]$ cd /home/oracle
[oracle@localhost ~]$ ls
afiedt.buf backup contrl01.bak Desktop ed.hup flash oracle_11g.tar.gz oradiag_oracle PROD prod_bak
[oracle@localhost ~]$ mkdir rman_bak
[oracle@localhost ~]$ cd rman_bak
[oracle@localhost rman_bak]$ mkdir cold_bak hot_bak copy
[oracle@localhost rman_bak]$ ls
cold_bak copy hot_bak
[oracle@localhost rman_bak]$ pwd
/home/oracle/rman_bak
[oracle@localhost rman_bak]$ vi rman.sql
show all;
~
~
"rman.sql" [New] 1L, 10C written
[oracle@localhost rman_bak]$ ls
cold_bak copy hot_bak rman.sql
--执行rman,记日志
[oracle@localhost rman_bak]$  rman target / log /home/oracle/rman_bak/rman.log @/home/oracle/rman_bak/rman.sql
RMAN> 2> [oracle@localhost rman_bak]$ 
--查看rman日志
[oracle@localhost rman_bak]$ ls
cold_bak copy hot_bak rman.log rman.sql
[oracle@localhost rman_bak]$ more rman.log
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Apr 14 09:16:16 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=239015079)
RMAN> show all;
2>
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name PROD are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/backup/control/%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COMPRESSED BACKUPSET;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/home/oracle/backup/%d_%T_%U.bak' MAXPIECESIZE 2 G;
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_PROD.f'; # default
Recovery Manager complete.
--执行rman,不记日志
[oracle@localhost rman_bak]$ rman target / @/home/oracle/rman_bak/rman.sql
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Apr 14 09:19:43 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=239015079)
RMAN> show all;
2>
using target database control file instead of recovery catalog
RMAN configuration parameters for database with db_unique_name PROD are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION ON;
CONFIGURE DEFAULT DEVICE TYPE TO DISK;
CONFIGURE CONTROLFILE AUTOBACKUP ON;
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '/home/oracle/backup/control/%F';
CONFIGURE DEVICE TYPE DISK PARALLELISM 2 BACKUP TYPE TO COMPRESSED BACKUPSET;
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE CHANNEL DEVICE TYPE DISK FORMAT '/home/oracle/backup/%d_%T_%U.bak' MAXPIECESIZE 2 G;
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE COMPRESSION ALGORITHM 'BASIC' AS OF RELEASE 'DEFAULT' OPTIMIZE FOR LOAD TRUE ; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/u01/app/oracle/product/11.2.0/db_1/dbs/snapcf_PROD.f'; # default
Recovery Manager complete.
注意:不记日志的话,就会把脚本中内容即时打印出来。记日志的话就会将执行结果写入日志文件中,前台不显示。
二、rman冷热全备
冷备脚本:
[oracle@localhost rman_bak]$ pwd
/home/oracle/rman_bak
[oracle@localhost rman_bak]$ ls
cold_bak copy hot_bak rman.log rman.sql
[oracle@localhost rman_bak]$ vi cold_bak.sql
run{
shutdown immediate;
startup mount;
allocate channel c1 type disk;
allocate channel c2 type disk;
backup database format'/home/oracle/rman_bak/cold_bak/%d_%s_%p.bak';
alter database open;
}
~
~
"cold_bak.sql" [New] 8L, 194C written
[oracle@localhost rman_bak]$ 
注意:因为元数据meta data是存放于控制文件中的,因此rman备份数据库应启致mount状态执行。format是指定备份路径及生成的备份文件名。其中%d指数据库名、%s备份集、%p备份片。另外为提高效率,开通了二个channel。
冷备演练(备份database)
[oracle@localhost ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Apr 14 09:41:10 2014
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=239015079)
RMAN> run{
2> shutdown immediate;
3> startup mount;
4> allocate channel c1 type disk;
allocate channel c2 type disk;
backup database format'/home/oracle/rman_bak/cold_bak/%d_%s_%p.bak';
5> 6> alter database open;
}7> 8>
using target database control file instead of recovery catalog
database closed
database dismounted
Oracle instance shut down
connected to target database (not started)
Oracle instance started
database mounted
Total System Global Area 836976640 bytes
Fixed Size 1339740 bytes
Variable Size 490737316 bytes
Database Buffers 339738624 bytes
Redo Buffers 5160960 bytes
allocated channel: c1
channel c1: SID=19 device type=DISK
allocated channel: c2
channel c2: SID=21 device type=DISK
Starting backup at 14-APR-14
channel c1: starting compressed full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/disk3/users01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/disk5/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD/disk3/fba01.dbf
channel c1: starting piece 1 at 14-APR-14
channel c2: starting compressed full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/disk3/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/disk4/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
channel c2: starting piece 1 at 14-APR-14
channel c1: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/cold_bak/PROD_9_1.bak tag=TAG20140414T094212 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:17
channel c2: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/cold_bak/PROD_10_1.bak tag=TAG20140414T094212 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:37
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-00 comment=NONE
Finished Control File Autobackup at 14-APR-14
database opened
released channel: c1
released channel: c2
--查看备份结果
[oracle@localhost rman_bak]$ cd cold_bak
[oracle@localhost cold_bak]$ ls
PROD_10_1.bak PROD_9_1.bak
--查看控制文件备份结果
[oracle@localhost cold_bak]$ cd /home/oracle/backup/control
[oracle@localhost control]$ ls
c-239015079-20140414-00

热备脚本:
[oracle@localhost rman_bak]$ vi hot_bak.sql
run{
sql 'alter system switch logfile';
allocate channel c1 type disk;
allocate channel c2 type disk;
backup database format'/home/oracle/rman_bak/hot_bak/%d_%s_%u.bak' filesperset 3;
sql 'alter system switch logfile';
}
"hot_bak.sql" [New] 8L, 222C written
[oracle@localhost rman_bak]$ 
注意:热备是在开库状态进行的,因此不需要关开库,filesperset是设置一个备份集最多3个备份片。前后切换日志组是为了归档,热备依赖于归档日志。
热备演练:
RMAN> run{
2> sql 'alter system switch logfile';
3> allocate channel c1 type disk;
4> allocate channel c2 type disk;
5> backup database format'/home/oracle/rman_bak/hot_bak/%d_%s_%u.bak' filesperset 3;
6> sql 'alter system switch logfile';
7> }
sql statement: alter system switch logfile
allocated channel: c1
channel c1: SID=19 device type=DISK
allocated channel: c2
channel c2: SID=21 device type=DISK
Starting backup at 14-APR-14
channel c1: starting compressed full datafile backup set
channel c1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/disk3/users01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/PROD/disk5/undotbs01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD/disk3/fba01.dbf
channel c1: starting piece 1 at 14-APR-14
channel c2: starting compressed full datafile backup set
channel c2: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/PROD/disk3/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/PROD/disk4/sysaux01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
channel c2: starting piece 1 at 14-APR-14
channel c1: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/PROD_12_0cp5mufv.bak tag=TAG20140414T101007 comment=NONE
channel c1: backup set complete, elapsed time: 00:00:03
channel c2: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/PROD_13_0dp5mufv.bak tag=TAG20140414T101007 comment=NONE
channel c2: backup set complete, elapsed time: 00:00:25
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-01 comment=NONE
Finished Control File Autobackup at 14-APR-14
sql statement: alter system switch logfile
released channel: c1
released channel: c2
注意:如果要备份控制文件和归档并删除归档,热备脚本可改写如下:
run{
sql 'alter system switch logfile';
allocate channel c1 type disk;
allocate channel c2 type disk;
backup database format'/home/oracle/rman_bak/hot_bak/%d_%s_%u.bak'
include current controlfile plus archivelog delete input format
'/home/oracle/rman_bak/hot_bak/arch_%U.bak'
filesperset 3;
sql 'alter system switch logfile';
}
三、rman备份表空间/数据文件/控制文件
--查看表空间及数据文件信息
SQL> select tablespace_name,contents,status from dba_tablespaces;
TABLESPACE_NAME CONTENTS STATUS
------------------------------ --------- ---------
SYSTEM PERMANENT ONLINE
SYSAUX PERMANENT ONLINE
UNDOTBS UNDO ONLINE
TEMPTS TEMPORARY ONLINE
USERS PERMANENT ONLINE
LXTBS PERMANENT ONLINE
FBA PERMANENT ONLINE
7 rows selected.
SQL> col name for a50;
SQL> select file#,name from v$datafile;
     FILE# NAME
---------- --------------------------------------------------
         1 /u01/app/oracle/oradata/PROD/disk3/system01.dbf
         2 /u01/app/oracle/oradata/PROD/disk4/sysaux01.dbf
         3 /u01/app/oracle/oradata/PROD/disk5/undotbs01.dbf
         4 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
         5 /u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
         6 /u01/app/oracle/oradata/PROD/disk3/fba01.dbf
6 rows selected.
--备份users表空间
RMAN>  backup tablespace users format '/home/oracle/rman_bak/hot_bak/users_%s.bak';
Starting backup at 14-APR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=21 device type=DISK
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/disk3/users01.dbf
channel ORA_DISK_1: starting piece 1 at 14-APR-14
channel ORA_DISK_1: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/users_15.bak tag=TAG20140414T104341 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-02 comment=NONE
Finished Control File Autobackup at 14-APR-14
--备份数据文件5和6
RMAN>  backup datafile 5,6 format '/home/oracle/rman_bak/hot_bak/files_%U.bak';
Starting backup at 14-APR-14
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
channel ORA_DISK_1: starting piece 1 at 14-APR-14
channel ORA_DISK_2: starting compressed full datafile backup set
channel ORA_DISK_2: specifying datafile(s) in backup set
input datafile file number=00006 name=/u01/app/oracle/oradata/PROD/disk3/fba01.dbf
channel ORA_DISK_2: starting piece 1 at 14-APR-14
channel ORA_DISK_1: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/files_0hp5n0g6_1_1.bak tag=TAG20140414T104422 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
channel ORA_DISK_2: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/files_0ip5n0g6_1_1.bak tag=TAG20140414T104422 comment=NONE
channel ORA_DISK_2: backup set complete, elapsed time: 00:00:01
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-03 comment=NONE
Finished Control File Autobackup at 14-APR-14
--查看users表空间备份信息
RMAN>  list backup of tablespace users;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8 Full 1.38M DISK 00:00:09 14-APR-14
        BP Key: 8 Status: AVAILABLE Compressed: YES Tag: TAG20140414T094212
        Piece Name: /home/oracle/rman_bak/cold_bak/PROD_9_1.bak
  List of Datafiles in backup set 8
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  4 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
11 Full 1.53M DISK 00:00:02 14-APR-14
        BP Key: 11 Status: AVAILABLE Compressed: YES Tag: TAG20140414T101007
        Piece Name: /home/oracle/rman_bak/hot_bak/PROD_12_0cp5mufv.bak
  List of Datafiles in backup set 11
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  4 Full 618812 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
14 Full 1.02M DISK 00:00:01 14-APR-14
        BP Key: 14 Status: AVAILABLE Compressed: YES Tag: TAG20140414T104341
        Piece Name: /home/oracle/rman_bak/hot_bak/users_15.bak
  List of Datafiles in backup set 14
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  4 Full 619531 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
--列出datafile 5的备份信息
RMAN>  list backup of datafile 5;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
9 Full 42.52M DISK 00:00:30 14-APR-14
        BP Key: 9 Status: AVAILABLE Compressed: YES Tag: TAG20140414T094212
        Piece Name: /home/oracle/rman_bak/cold_bak/PROD_10_1.bak
  List of Datafiles in backup set 9
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  5 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
12 Full 42.68M DISK 00:00:25 14-APR-14
        BP Key: 12 Status: AVAILABLE Compressed: YES Tag: TAG20140414T101007
        Piece Name: /home/oracle/rman_bak/hot_bak/PROD_13_0dp5mufv.bak
  List of Datafiles in backup set 12
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  5 Full 618813 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
16 Full 1.02M DISK 00:00:01 14-APR-14
        BP Key: 16 Status: AVAILABLE Compressed: YES Tag: TAG20140414T104422
        Piece Name: /home/oracle/rman_bak/hot_bak/files_0hp5n0g6_1_1.bak
  List of Datafiles in backup set 16
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  5 Full 619582 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
--备份控制文件
RMAN> backup current controlfile format '/home/oracle/rman_bak/hot_bak/control.bak';
Starting backup at 14-APR-14
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting compressed full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
channel ORA_DISK_1: starting piece 1 at 14-APR-14
channel ORA_DISK_1: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/control.bak tag=TAG20140414T183908 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-0c comment=NONE
Finished Control File Autobackup at 14-APR-14
--备份归档日志
RMAN>  backup archivelog all delete input;
注意:以上命令表示备份所有归档信息且删除之前的归档备份。备份成功后,使用list backup of archivelog all查看备份结果,然后再用list copy命令查看镜像备份时,会发现之前查出的archivelog备份信息全被删除了(这是因为backup archive all命令中带了delete input原因所致)。
四、查看备份结果信息
--列出数据文件备份
RMAN>  list backup of database;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8 Full 1.38M DISK 00:00:09 14-APR-14
        BP Key: 8 Status: AVAILABLE Compressed: YES Tag: TAG20140414T094212
        Piece Name: /home/oracle/rman_bak/cold_bak/PROD_9_1.bak
  List of Datafiles in backup set 8
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  3 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk5/undotbs01.dbf
  4 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
  6 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/fba01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
9 Full 42.52M DISK 00:00:30 14-APR-14
        BP Key: 9 Status: AVAILABLE Compressed: YES Tag: TAG20140414T094212
        Piece Name: /home/oracle/rman_bak/cold_bak/PROD_10_1.bak
  List of Datafiles in backup set 9
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  1 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/system01.dbf
  2 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk4/sysaux01.dbf
  5 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
11 Full 1.53M DISK 00:00:02 14-APR-14
        BP Key: 11 Status: AVAILABLE Compressed: YES Tag: TAG20140414T101007
        Piece Name: /home/oracle/rman_bak/hot_bak/PROD_12_0cp5mufv.bak
  List of Datafiles in backup set 11
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  3 Full 618812 14-APR-14 /u01/app/oracle/oradata/PROD/disk5/undotbs01.dbf
  4 Full 618812 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
  6 Full 618812 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/fba01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
12 Full 42.68M DISK 00:00:25 14-APR-14
        BP Key: 12 Status: AVAILABLE Compressed: YES Tag: TAG20140414T101007
        Piece Name: /home/oracle/rman_bak/hot_bak/PROD_13_0dp5mufv.bak
  List of Datafiles in backup set 12
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  1 Full 618813 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/system01.dbf
  2 Full 618813 14-APR-14 /u01/app/oracle/oradata/PROD/disk4/sysaux01.dbf
  5 Full 618813 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf

--列出所有备份
RMAN>  list backup;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8 Full 1.38M DISK 00:00:09 14-APR-14
        BP Key: 8 Status: AVAILABLE Compressed: YES Tag: TAG20140414T094212
        Piece Name: /home/oracle/rman_bak/cold_bak/PROD_9_1.bak
  List of Datafiles in backup set 8
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  3 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk5/undotbs01.dbf
  4 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
  6 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/fba01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
9 Full 42.52M DISK 00:00:30 14-APR-14
        BP Key: 9 Status: AVAILABLE Compressed: YES Tag: TAG20140414T094212
        Piece Name: /home/oracle/rman_bak/cold_bak/PROD_10_1.bak
  List of Datafiles in backup set 9
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  1 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/system01.dbf
  2 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk4/sysaux01.dbf
  5 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
10 Full 7.52M DISK 00:00:01 14-APR-14
        BP Key: 10 Status: AVAILABLE Compressed: NO Tag: TAG20140414T094253
        Piece Name: /home/oracle/backup/control/c-239015079-20140414-00
  Control File Included: Ckp SCN: 618106 Ckp time: 14-APR-14
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
11 Full 1.53M DISK 00:00:02 14-APR-14
        BP Key: 11 Status: AVAILABLE Compressed: YES Tag: TAG20140414T101007
        Piece Name: /home/oracle/rman_bak/hot_bak/PROD_12_0cp5mufv.bak
  List of Datafiles in backup set 11
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  3 Full 618812 14-APR-14 /u01/app/oracle/oradata/PROD/disk5/undotbs01.dbf
  4 Full 618812 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
  6 Full 618812 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/fba01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
12 Full 42.68M DISK 00:00:25 14-APR-14
        BP Key: 12 Status: AVAILABLE Compressed: YES Tag: TAG20140414T101007
        Piece Name: /home/oracle/rman_bak/hot_bak/PROD_13_0dp5mufv.bak
  List of Datafiles in backup set 12
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  1 Full 618813 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/system01.dbf
  2 Full 618813 14-APR-14 /u01/app/oracle/oradata/PROD/disk4/sysaux01.dbf
  5 Full 618813 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
13 Full 7.52M DISK 00:00:01 14-APR-14
        BP Key: 13 Status: AVAILABLE Compressed: NO Tag: TAG20140414T101033
        Piece Name: /home/oracle/backup/control/c-239015079-20140414-01
  Control File Included: Ckp SCN: 618824 Ckp time: 14-APR-14
--查看所有归档备份信息
RMAN> list backup of archivelog all;
--查看某tablespace的rman备份信息(如lxtbs)
RMAN> list backup of tablespace lxtbs;
--查看具体datafile的rman备份信息(如datafile 5)
RMAN> list backup of datafile 5;

五、增量备份
定义:只备份从上次备份发生变化的块。增量备份首先要做全备:
0,1,2,3,4,5
优势:加快备份时间。
分类: 1差异增量备份,2累计增量备份。
0级备份就是全备,做其它级别的备份前必须有0级备份,否则系统会做0级备份。
差异增量备份:备份快,恢复慢,数据库默认为此方式
       只要等于或小于自己的级别 ,前面的备份就可以作为备份的起点。如备份策略为一周,分配如下:
日    一    二    三    四    五    六    日
0      2      2      1     2      2      1      0
全    一    一    三    一    一    三    全
即:周一周二只备份一天就可以,但周三要把周一二三的都备一遍,因为它级别比前面的备份低,周四就只备一天就行了,同理周五备一天,周六备三天,周日做全备。恢复时,比如周三早晨挂了,需要周日周一周二才能恢复到周三早晨,但如果周四早晨,就只需周日,周三就能恢复。周六挂需要周日,周三四五四个备份集来恢复。
累计增量备份:备份慢,但恢复快
      小于自己级别的 。又拿一周来分配如下:
日    一    二    三    四    五    六    日
0      2      2      1     2      2      2      0
全    一    二    三    一    二    三    全
即:周日全备,周一备份一天的,周二备二天,周三备周一二三的。周四只备一天,周五备二天,周六备三天,周日全备。
假如周三恢复,需要0级和一个到周二的备份就行了。恢复更快,周六挂,需要周日,周三,周五三个备份集即可。
实例演练
增量备份user表空间(先备0级全备)
RMAN>  backup incremental level 0 format '/home/oracle/rman_bak/hot_bak/users_%s_0.bak' tablespace users;

Starting backup at 14-APR-14
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting compressed incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/disk3/users01.dbf
channel ORA_DISK_1: starting piece 1 at 14-APR-14
channel ORA_DISK_1: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/users_20_0.bak tag=TAG20140414T130143 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-04 comment=NONE
Finished Control File Autobackup at 14-APR-14
RMAN> backup incremental level 0  cumulative  format '/home/oracle/rman_bak/hot_bak/users_%s_cu0.bak' datafile 4;
Starting backup at 14-APR-14
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting compressed incremental level 0 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/disk3/users01.dbf
channel ORA_DISK_1: starting piece 1 at 14-APR-14
channel ORA_DISK_1: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/users_28_cu0.bak tag=TAG20140414T131952 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-06 comment=NONE
Finished Control File Autobackup at 14-APR-14

RMAN> list backup of tablespace users;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8 Full 1.38M DISK 00:00:09 14-APR-14
        BP Key: 8 Status: AVAILABLE Compressed: YES Tag: TAG20140414T094212
        Piece Name: /home/oracle/rman_bak/cold_bak/PROD_9_1.bak
  List of Datafiles in backup set 8
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  4 Full 618106 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
11 Full 1.53M DISK 00:00:02 14-APR-14
        BP Key: 11 Status: AVAILABLE Compressed: YES Tag: TAG20140414T101007
        Piece Name: /home/oracle/rman_bak/hot_bak/PROD_12_0cp5mufv.bak
  List of Datafiles in backup set 11
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  4 Full 618812 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
14 Full 1.02M DISK 00:00:01 14-APR-14
        BP Key: 14 Status: AVAILABLE Compressed: YES Tag: TAG20140414T104341
        Piece Name: /home/oracle/rman_bak/hot_bak/users_15.bak
  List of Datafiles in backup set 14
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  4 Full 619531 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
19 Incr 0 1.02M DISK 00:00:00 14-APR-14
        BP Key: 19 Status: AVAILABLE Compressed: YES Tag: TAG20140414T130143
        Piece Name: /home/oracle/rman_bak/hot_bak/users_20_0.bak
  List of Datafiles in backup set 19
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  4 0 Incr 621894 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
21 Incr 0 1.02M DISK 00:00:00 14-APR-14
        BP Key: 21 Status: AVAILABLE Compressed: YES Tag: TAG20140414T130557
        Piece Name:  /home/oracle/rman_bak/hot_bak/users_22_cu0.bak
  List of Datafiles in backup set 21
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  4 0 Incr 621989 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
23 Incr 0 1.02M DISK 00:00:00 14-APR-14
        BP Key: 23 Status: AVAILABLE Compressed: YES Tag: TAG20140414T131952
        Piece Name:  /home/oracle/rman_bak/hot_bak/users_28_cu0.bak
  List of Datafiles in backup set 23
  File LV Type Ckp SCN Ckp Time Name
  ---- -- ---- ---------- --------- ----
  4 0 Incr 622312 14-APR-14 /u01/app/oracle/oradata/PROD/disk3/users01.dbf

注意:系统默认的增量备份为差异增量备份,若要做累计增量备份需添加关键字 cumulative
下面演练级别为2的差异增量备份与级别为1的累计增量备份
RMAN>  backup incremental level 2 format'/home/oracle/rman_bak/hot_bak/users_%s_2.bak' tablespace users;
Starting backup at 14-APR-14
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting compressed incremental level 2 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/disk3/users01.dbf
channel ORA_DISK_1: starting piece 1 at 14-APR-14
channel ORA_DISK_1: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/users_30_2.bak tag=TAG20140414T132911 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:26
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-07 comment=NONE
Finished Control File Autobackup at 14-APR-14
RMAN>  backup incremental level 1 format'/home/oracle/rman_bak/hot_bak/users_%s_cu1.bak' datafile 4;
Starting backup at 14-APR-14
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting compressed incremental level 1 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00004 name=/u01/app/oracle/oradata/PROD/disk3/users01.dbf
channel ORA_DISK_1: starting piece 1 at 14-APR-14
channel ORA_DISK_1: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/users_32_cu1.bak tag=TAG20140414T133037 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-08 comment=NONE
Finished Control File Autobackup at 14-APR-14

附录:rman备份文件命名参数设置收集
六、copy镜像备份
--查看镜像备份
RMAN> list copy;
using target database control file instead of recovery catalog
specification does not match any datafile copy in the repository
List of Control File Copies
===========================
Key S Completion Time Ckp SCN Ckp Time
------- - --------------- ---------- ---------------
2 A 10-APR-14 470812 10-APR-14
        Name: /home/oracle/prod_bak/hot_bak/control01.dbf
        Tag: TAG20140410T163911
List of Archived Log Copies for database with db_unique_name PROD
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
1 1 16 A 07-APR-14
        Name: /home/oracle/PROD/1_16_827176743.dbf
2 1 17 A 09-APR-14
        Name: /home/oracle/PROD/1_17_827176743.dbf
3 1 18 A 09-APR-14
        Name: /home/oracle/PROD/1_18_827176743.dbf
4 1 19 A 09-APR-14
        Name: /home/oracle/PROD/1_19_827176743.dbf
5 1 20 A 09-APR-14
        Name: /home/oracle/PROD/1_20_827176743.dbf
……
由此可见list copy会列出镜像备份,也会列出归档日志备份信息。
--datafile 5做镜像备份
RMAN>  copy datafile 5 to '/home/oracle/rman_bak/copy/lxtbs.bak';
Starting backup at 14-APR-14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=46 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=47 device type=DISK
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
output file name=/home/oracle/rman_bak/copy/lxtbs.bak tag=TAG20140414T181036 RECID=3 STAMP=844884640
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-09 comment=NONE
Finished Control File Autobackup at 14-APR-14
RMAN> list copy;
List of Datafile Copies
=======================
Key File S Completion Time Ckp SCN Ckp Time
------- ---- - --------------- ---------- ---------------
3 5 A 14-APR-14 623119 14-APR-14
        Name:  /home/oracle/rman_bak/copy/lxtbs.bak
        Tag: TAG20140414T181036
List of Control File Copies
===========================
Key S Completion Time Ckp SCN Ckp Time
------- - --------------- ---------- ---------------
2 A 10-APR-14 470812 10-APR-14
        Name: /home/oracle/prod_bak/hot_bak/control01.dbf
        Tag: TAG20140410T163911
List of Archived Log Copies for database with db_unique_name PROD
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
1 1 16 A 07-APR-14
        Name: /home/oracle/PROD/1_16_827176743.dbf
2 1 17 A 09-APR-14
        Name: /home/oracle/PROD/1_17_827176743.dbf
3 1 18 A 09-APR-14
        Name: /home/oracle/PROD/1_18_827176743.dbf
4 1 19 A 09-APR-14
        Name: /home/oracle/PROD/1_19_827176743.dbf
5 1 20 A 09-APR-14
        Name: /home/oracle/PROD/1_20_827176743.dbf
--删除镜像备份
RMAN> delete copy;
注意:此命令慎用,因为会删除所有归档备份信息。所以删除镜像时最好指定具体要删除的备份文件信息。如删除刚备份的datafile 5:
RMAN> delete datafilecopy  3;
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=43 device type=DISK
allocated channel: ORA_DISK_2
channel ORA_DISK_2: SID=45 device type=DISK
List of Datafile Copies
=======================
Key File S Completion Time Ckp SCN Ckp Time
------- ---- - --------------- ---------- ---------------
3 5 A 14-APR-14 623119 14-APR-14
        Name: /home/oracle/rman_bak/copy/lxtbs.bak
        Tag: TAG20140414T181036
Do you really want to delete the above objects (enter YES or NO)? yes
deleted datafile copy
datafile copy file name=/home/oracle/rman_bak/copy/lxtbs.bak RECID=3 STAMP=844884640
Deleted 1 objects
注意:delete datafilecopy 3这里的3是指list copy列出的key值,即备份文件对应序列号。
--查看删除后的copy信息
RMAN> list copy;
specification does not match any datafile copy in the repository
List of Control File Copies
===========================
Key S Completion Time Ckp SCN Ckp Time
------- - --------------- ---------- ---------------
2 A 10-APR-14 470812 10-APR-14
        Name: /home/oracle/prod_bak/hot_bak/control01.dbf
        Tag: TAG20140410T163911
List of Archived Log Copies for database with db_unique_name PROD
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
1 1 16 A 07-APR-14
        Name: /home/oracle/PROD/1_16_827176743.dbf
2 1 17 A 09-APR-14
        Name: /home/oracle/PROD/1_17_827176743.dbf
3 1 18 A 09-APR-14
        Name: /home/oracle/PROD/1_18_827176743.dbf
4 1 19 A 09-APR-14
        Name: /home/oracle/PROD/1_19_827176743.dbf
5 1 20 A 09-APR-14
        Name: /home/oracle/PROD/1_20_827176743.dbf
……
另一种方式做copy备份
RMAN>  backup  as copy  datafile 5 format '/home/oracle/rman_bak/copy/lxtbs01.bak';
Starting backup at 14-APR-14
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
output file name=/home/oracle/rman_bak/copy/lxtbs01.bak tag=TAG20140414T182449 RECID=4 STAMP=844885493
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:07
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-0a comment=NONE
Finished Control File Autobackup at 14-APR-14
注意:这里的copy备份命令与一般的rman命令很像,只是多了 as copy关键词
RMAN> list copy;
List of Datafile Copies
=======================
Key File S Completion Time Ckp SCN Ckp Time
------- ---- - --------------- ---------- ---------------
4 5 A 14-APR-14 623386 14-APR-14
        Name:  /home/oracle/rman_bak/copy/lxtbs01.bak
        Tag: TAG20140414T182449
List of Control File Copies
===========================
Key S Completion Time Ckp SCN Ckp Time
------- - --------------- ---------- ---------------
2 A 10-APR-14 470812 10-APR-14
        Name: /home/oracle/prod_bak/hot_bak/control01.dbf
        Tag: TAG20140410T163911
List of Archived Log Copies for database with db_unique_name PROD
=====================================================================
Key Thrd Seq S Low Time
------- ---- ------- - ---------
1 1 16 A 07-APR-14
        Name: /home/oracle/PROD/1_16_827176743.dbf
2 1 17 A 09-APR-14
        Name: /home/oracle/PROD/1_17_827176743.dbf
3 1 18 A 09-APR-14
        Name: /home/oracle/PROD/1_18_827176743.dbf
4 1 19 A 09-APR-14
        Name: /home/oracle/PROD/1_19_827176743.dbf
5 1 20 A 09-APR-14
        Name: /home/oracle/PROD/1_20_827176743.dbf
注意:镜像不能做增量备份,但可作为备份集增量备份的0级备份。
例如,这里直接做lxtbs01的level 2的增量备份(之前未做0级备份)
RMAN> backup incremental level 2 format'/home/oracle/rman_bak/hot_bak/lxtbs_%s_2.bak' tablespace lxtbs;
Starting backup at 14-APR-14
using channel ORA_DISK_1
using channel ORA_DISK_2
channel ORA_DISK_1: starting compressed incremental level 2 datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00005 name=/u01/app/oracle/oradata/PROD/disk3/lxtbs01.dbf
channel ORA_DISK_1: starting piece 1 at 14-APR-14
channel ORA_DISK_1: finished piece 1 at 14-APR-14
piece handle=/home/oracle/rman_bak/hot_bak/lxtbs_38_2.bak tag=TAG20140414T183252 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:07
Finished backup at 14-APR-14
Starting Control File Autobackup at 14-APR-14
piece handle=/home/oracle/backup/control/c-239015079-20140414-0b comment=NONE
Finished Control File Autobackup at 14-APR-14
这里能成功备份,一般来做,未做0级备份,直接做其它级别备份会报错,因为之前做了镜像备份(等同于0级备份),所以这里可成功。
附:备份文件名命名相关参数收集:
A9F8D3A2FE194FD9B46F750D097DCA34

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/21251711/viewspace-1167979/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/21251711/viewspace-1167979/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值