实例:
1:排除指定的表空间不备份
RMAN> configure exclude for tablespace newadunion; --不备份newadunion表空间,加clear清除配置
tablespace NEWADUNION will be excluded from future whole database backupsnew RMAN configuration parameters are successfully stored
run{ allocate channel ch1 device type disk;allocate channel ch2 device type disk;backup database format '/data/backup/rmanback/db_%d_%T_%U';crosscheck backup;release channel ch1;release channel ch2;}
allocated channel: ch1channel ch1: sid=98 devtype=DISK
allocated channel: ch2channel ch2: sid=119 devtype=DISK
Starting backup at 12-6月 -12file 5 is excluded from whole database backupfile 13 is excluded from whole database backupfile 14 is excluded from whole database backupfile 15 is excluded from whole database backupfile 16 is excluded from whole database backupfile 17 is excluded from whole database backupfile 18 is excluded from whole database backupfile 19 is excluded from whole database backupfile 20 is excluded from whole database backupfile 21 is excluded from whole database backupchannel ch1: starting full datafile backupsetchannel ch1: specifying datafile(s) in backupsetinput datafile fno=00023 name=/data/oradata/eagaodb/newadunion_log01.dbfinput datafile fno=00022 name=/data/oradata/eagaodb/smsway01.dbfinput datafile fno=00002 name=/data/oradata/eagaodb/eaindex_data02.dbfinput datafile fno=00007 name=/data/oradata/eagaodb/system02.dbfinput datafile fno=00008 name=/data/oradata/eagaodb/wz_data01.dbfinput datafile fno=00010 name=/data/oradata/eagaodb/eaindex_data.dbfinput datafile fno=00003 name=/data/oradata/eagaodb/sysaux01.dbfchannel ch1: starting piece 1 at 12-6月 -12channel ch2: starting full datafile backupsetchannel ch2: specifying datafile(s) in backupsetinput datafile fno=00006 name=/log//undotbs2.dbfinput datafile fno=00001 name=/data/oradata/eagaodb/system01.dbfinput datafile fno=00009 name=/data/oradata/eagaodb/flink_data.dbfinput datafile fno=00004 name=/data/oradata/eagaodb/users01.dbfinput datafile fno=00011 name=/data/oradata/eagaodb/eaindex_idx01.dbfinput datafile fno=00012 name=/data/oradata/eagaodb/chris01.dbfchannel ch2: starting piece 1 at 12-6月 -12channel ch2: finished piece 1 at 12-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0cndc5v3_1_1 tag=TAG20120612T165915 comment=NONEchannel ch2: backup set complete, elapsed time: 00:06:36channel ch2: starting full datafile backupsetchannel ch2: specifying datafile(s) in backupsetincluding current control file in backupsetchannel ch2: starting piece 1 at 12-6月 -12channel ch2: finished piece 1 at 12-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0dndc6bf_1_1 tag=TAG20120612T165915 comment=NONEchannel ch2: backup set complete, elapsed time: 00:00:03channel ch2: starting full datafile backupsetchannel ch2: specifying datafile(s) in backupsetincluding current SPFILE in backupsetchannel ch2: starting piece 1 at 12-6月 -12channel ch2: finished piece 1 at 12-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0endc6bj_1_1 tag=TAG20120612T165915 comment=NONEchannel ch2: backup set complete, elapsed time: 00:00:02channel ch1: finished piece 1 at 12-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0bndc5v3_1_1 tag=TAG20120612T165915 comment=NONEchannel ch1: backup set complete, elapsed time: 00:11:27Finished backup at 12-6月 -12
crosschecked backup piece: found to be 'AVAILABLE'backup piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0cndc5v3_1_1 recid=5 stamp=785782755crosschecked backup piece: found to be 'AVAILABLE'backup piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0dndc6bf_1_1 recid=6 stamp=785783151crosschecked backup piece: found to be 'AVAILABLE'backup piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0endc6bj_1_1 recid=7 stamp=785783156crosschecked backup piece: found to be 'AVAILABLE'backup piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0bndc5v3_1_1 recid=8 stamp=785782755Crosschecked 4 objects
released channel: ch1released channel: ch2
2:监控执行的进度: SQL> select sid,SERIAL# ,CONTEXT,SOFAR,TOTALWORK,round(SOFAR/TOTALWORK*100,2) "_%"from v$session_longops where OPNAME like 'RMAN%' and SOFAR<>TOTALWORK and TOTALWORK<>0;no rows selected
SQL> /
SID SERIAL# CONTEXT SOFAR TOTALWORK _%---- ---------- ---------- ---------- --------------- -----119 1973 1 276799 3031040 9.1399 155 11 0 7963084 098 75 1 106489 4930304 2.16
SQL> /
SID SERIAL# CONTEXT SOFAR TOTALWORK _%---- ---------- ---- ---------- ---------- ----------119 1973 1 276799 3031040 13.1499 155 11 0 7963084 098 75 1 106489 4930304 8.24
查看备份集的大小:[@st8cserver16 ~]$ ls /data/backup/rmanback/ -lhtotal 30G-rw-r----- 1 oracle oinstall 7.6G Jun 12 17:10 db_EAGAODB_20120612_0bndc5v3_1_1-rw-r----- 1 oracle oinstall 23G Jun 12 17:05 db_EAGAODB_20120612_0cndc5v3_1_1-rw-r----- 1 oracle oinstall 25M Jun 12 17:05 db_EAGAODB_20120612_0dndc6bf_1_1-rw-r----- 1 oracle oinstall 96K Jun 12 17:05 db_EAGAODB_20120612_0endc6bj_1_1
3:以上是10.2.0.1备份完毕,注意11g可以使用RMAN> backup validate database 计算RMAN备份集的大小,如:
[oracle@mlydserver22 ~]$ rman target /
Recovery Manager: Release 11.2.0.1.0 - Production on Mon Jun 11 16:52:33 2012
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: EAGAODB (DBID=1839368230)
RMAN> backup validate datafile 12;
Starting backup at 11-JUN-12using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=774 device type=DISKchannel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setinput datafile file number=00012 name=/data/oradata/eagaodb/NEWADUNION08.dbfchannel ORA_DISK_1: backup set complete, elapsed time: 00:05:56List of Datafiles=================File Status Marked Corrupt Empty Blocks Blocks Examined High SCN---- ------ ---------- ------------ --------------- ---------------- --------------12 OK 0 7 4194302 18169151887 File Name: /data/oradata/eagaodb/NEWADUNION08.dbf Block Type Blocks Failing Blocks Processed ---------- -------------- ---------------- Data 0 4148094 Index 0 39270 Other 0 6931
Finished backup at 11-JUN-12
> show parameter db_block_size
NAME TYPE VALUE------------------------------------ ----------- ------------------------------db_block_size integer 8192
可以看出RMAN备份datafile 12时,需要(4194302-7)*8/1024/1024=31.99G,如果要降低RMAN备份大小,可以考虑shrink释放一些空间,以及启用RMAN的压缩功能:run{ allocate channel ch1 device type disk;allocate channel ch2 device type disk;backup as compressed backupset database format '/data/backup/rmanback/db_%d_%T_%U';crosscheck backup;release channel ch1;release channel ch2;}using target database control file instead of recovery catalogallocated channel: ch1channel ch1: sid=136 devtype=DISK
allocated channel: ch2channel ch2: sid=99 devtype=DISK
Starting backup at 12-6月 -12file 5 is excluded from whole database backupfile 13 is excluded from whole database backupfile 14 is excluded from whole database backupfile 15 is excluded from whole database backupfile 16 is excluded from whole database backupfile 17 is excluded from whole database backupfile 18 is excluded from whole database backupfile 19 is excluded from whole database backupfile 20 is excluded from whole database backupfile 21 is excluded from whole database backupchannel ch1: starting compressed full datafile backupsetchannel ch1: specifying datafile(s) in backupsetinput datafile fno=00023 name=/data/oradata/eagaodb/newadunion_log01.dbfinput datafile fno=00022 name=/data/oradata/eagaodb/smsway01.dbfinput datafile fno=00002 name=/data/oradata/eagaodb/eaindex_data02.dbfinput datafile fno=00007 name=/data/oradata/eagaodb/system02.dbfinput datafile fno=00008 name=/data/oradata/eagaodb/wz_data01.dbfinput datafile fno=00010 name=/data/oradata/eagaodb/eaindex_data.dbfinput datafile fno=00003 name=/data/oradata/eagaodb/sysaux01.dbfchannel ch1: starting piece 1 at 12-6月 -12channel ch2: starting compressed full datafile backupsetchannel ch2: specifying datafile(s) in backupsetinput datafile fno=00006 name=/log/oracle/undotbs2.dbfinput datafile fno=00001 name=/data/oradata/eagaodb/system01.dbfinput datafile fno=00009 name=/data/oradata/eagaodb/flink_data.dbfinput datafile fno=00004 name=/data/oradata/eagaodb/users01.dbfinput datafile fno=00011 name=/data/oradata/eagaodb/eaindex_idx01.dbfinput datafile fno=00012 name=/data/oradata/eagaodb/chris01.dbfchannel ch2: starting piece 1 at 12-6月 -12channel ch1: finished piece 1 at 12-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0fndcc4a_1_1 tag=TAG20120612T184426 comment=NONEchannel ch1: backup set complete, elapsed time: 00:09:55channel ch1: starting compressed full datafile backupsetchannel ch1: specifying datafile(s) in backupsetincluding current control file in backupsetchannel ch1: starting piece 1 at 12-6月 -12channel ch1: finished piece 1 at 12-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0hndccmt_1_1 tag=TAG20120612T184426 comment=NONEchannel ch1: backup set complete, elapsed time: 00:00:02channel ch1: starting compressed full datafile backupsetchannel ch1: specifying datafile(s) in backupsetincluding current SPFILE in backupsetchannel ch1: starting piece 1 at 12-6月 -12channel ch1: finished piece 1 at 12-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0indccmv_1_1 tag=TAG20120612T184426 comment=NONEchannel ch1: backup set complete, elapsed time: 00:00:02channel ch2: finished piece 1 at 12-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0gndcc4a_1_1 tag=TAG20120612T184426 comment=NONEchannel ch2: backup set complete, elapsed time: 00:23:24Finished backup at 12-6月 -12
crosschecked backup piece: found to be 'AVAILABLE'backup piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0fndcc4a_1_1 recid=9 stamp=785789066crosschecked backup piece: found to be 'AVAILABLE'backup piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0hndccmt_1_1 recid=10 stamp=785789662crosschecked backup piece: found to be 'AVAILABLE'backup piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0indccmv_1_1 recid=11 stamp=785789664crosschecked backup piece: found to be 'AVAILABLE'backup piece handle=/data/backup/rmanback/db_EAGAODB_20120612_0gndcc4a_1_1 recid=12 stamp=785789066Crosschecked 4 objects
released channel: ch1released channel: ch2
观察:top - 18:51:52 up 817 days, 7:17, 3 users, load average: 2.20, 1.62, 0.78 --整体压力不大Tasks: 333 total, 2 running, 319 sleeping, 7 stopped, 5 zombieCpu(s): 20.5%us, 1.5%sy, 0.0%ni, 74.3%id, 3.4%wa, 0.1%hi, 0.1%si, 0.0%stMem: 4031676k total, 4000272k used, 31404k free, 2640k buffersSwap: 8193108k total, 952108k used, 7241000k free, 3213644k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 26746 oracle 25 0 1709m 56m 26m D 92.7 1.4 6:16.53 oracle --CPU占用比较大 26745 oracle 18 0 1709m 56m 27m R 80.7 1.4 4:41.24 oracle 353 root 10 -5 0 0 0 S 2.0 0.0 887:48.89 kswapd0 2156 root 11 -5 0 0 0 S 1.0 0.0 78:52.57 kjournald 26455 root 15 0 0 0 0 S 0.7 0.0 0:00.81 pdflush
[oracle@st8cserver16 backup]$ ls rmanback/ -lhttotal 8.5G-rw-r----- 1 oracle oinstall 7.2G Jun 12 19:07 db_EAGAODB_20120612_0gndcc4a_1_1-rw-r----- 1 oracle oinstall 96K Jun 12 18:54 db_EAGAODB_20120612_0indccmv_1_1-rw-r----- 1 oracle oinstall 2.1M Jun 12 18:54 db_EAGAODB_20120612_0hndccmt_1_1-rw-r----- 1 oracle oinstall 1.4G Jun 12 18:54 db_EAGAODB_20120612_0fndcc4a_1_1
和上面的备份比较:无压缩时间:00:06:36+00:00:03+00:00:02+00:11:2=18分钟左右,备份集为30G有压缩时间:00:09:55+00:00:02+00:00:02+00:23:24=34分钟左右 备份集为8.5G总结:时间将近多了2倍,但占用空间少了将近4倍;系统整体压力不大,CPU占比大。
4:证明RMAN备份集远远大于数据大小:[oracle@st8cserver16 /]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期一 6月 11 14:12:41 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bit ProductionWith the Partitioning, OLAP and Data Mining optionsSQL> select sum1-sum2 from (select sum(bytes)/1024/1024 sum1 from dba_data_files), (select sum(bytes)/1024/1024 sum2 from dba_free_space);
SUM1-SUM2----------109394.375
SQL> select * from (select owner,segment_name,TABLESPACE_NAME,BYTES/1024/1024 M from dba_segments order by BYTES desc)a where rownum<20;
OWNER------------------------------SEGMENT_NAME---------------------------------------------------------------------------------TABLESPACE_NAME M------------------------------ ----------WONDERLIANMENG_DATA_LOG_STAT301201NEWADUNION 47628
WONDERLIANMENG_DATA_LOG_STAT201201NEWADUNION 13445
WONDERLIANMENG_DATA_LOG_STAT12NEWADUNION 12253
J10DBATESTEXT_FACT_MCHN_VSTNEWADUNION 11511
SQL> truncate table wonder.LIANMENG_DATA_LOG_STAT301201;
Table truncated.
SQL> truncate table wonder.LIANMENG_DATA_LOG_STAT201201;
Table truncated.
SQL> truncate table wonder.LIANMENG_DATA_LOG_STAT12;
Table truncated.
SQL> select sum1-sum2 from (select sum(bytes)/1024/1024 sum1 from dba_data_files), (select sum(bytes)/1024/1024 sum2 from dba_free_space);
SUM1-SUM2---------- 24850.375SQL> select COUNT(*) from dba_recyclebin;
COUNT(*)---------- 1302
SQL> purge dba_recyclebin;
DBA Recyclebin purged.
SQL> select COUNT(*) from dba_recyclebin;
COUNT(*)---------- 0
SQL> create tablespace newadunion_log datafile '/data/oradata/eagaodb/newadunion_log01.dbf' size 20g;
Tablespace created.
RMAN备份:
[oracle@st8cserver16 backup]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on 星期一 6月 11 15:07:10 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database: EAGAODB (DBID=1798905771)
run{ allocate channel ch1 device type disk;allocate channel ch2 device type disk;backup database format '/data/backup/rmanback/db_%d_%T_%U';crosscheck backup;release channel ch1;release channel ch2; }
using target database control file instead of recovery catalogallocated channel: ch1channel ch1: sid=125 devtype=DISK
allocated channel: ch2channel ch2: sid=126 devtype=DISK
Starting backup at 11-6月 -12channel ch1: starting full datafile backupsetchannel ch1: specifying datafile(s) in backupsetinput datafile fno=00018 name=/data/oradata/eagaodb/newadunion07.dbfinput datafile fno=00006 name=/log/oracle/undotbs2.dbfinput datafile fno=00019 name=/data/oradata/eagaodb/newadunion08.dbfinput datafile fno=00020 name=/data/oradata/eagaodb/newadunion09.dbfinput datafile fno=00021 name=/data/oradata/eagaodb/newadunion10.dbfinput datafile fno=00005 name=/data/oradata/eagaodb/newadunion01.dbfinput datafile fno=00013 name=/data/oradata/eagaodb/newadunion02.dbfinput datafile fno=00014 name=/data/oradata/eagaodb/newadunion03.dbfinput datafile fno=00015 name=/data/oradata/eagaodb/newadunion04.dbfinput datafile fno=00016 name=/data/oradata/eagaodb/newadunion05.dbfinput datafile fno=00017 name=/data/oradata/eagaodb/newadunion06.dbfinput datafile fno=00023 name=/data/oradata/eagaodb/newadunion_log01.dbfchannel ch1: starting piece 1 at 11-6月 -12channel ch2: starting full datafile backupsetchannel ch2: specifying datafile(s) in backupsetinput datafile fno=00022 name=/data/oradata/eagaodb/smsway01.dbfinput datafile fno=00007 name=/data/oradata/eagaodb/system02.dbfinput datafile fno=00008 name=/data/oradata/eagaodb/wz_data01.dbfinput datafile fno=00010 name=/data/oradata/eagaodb/eaindex_data.dbfinput datafile fno=00012 name=/data/oradata/eagaodb/chris01.dbfchannel ch2: starting piece 1 at 11-6月 -12channel ch2: finished piece 1 at 11-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120611_02nd9bae_1_1 tag=TAG20120611T151213 comment=NONEchannel ch2: backup set complete, elapsed time: 00:01:35channel ch2: starting full datafile backupsetchannel ch2: specifying datafile(s) in backupsetinput datafile fno=00002 name=/data/oradata/eagaodb/eaindex_data02.dbfinput datafile fno=00003 name=/data/oradata/eagaodb/sysaux01.dbfinput datafile fno=00001 name=/data/oradata/eagaodb/system01.dbfinput datafile fno=00009 name=/data/oradata/eagaodb/flink_data.dbfinput datafile fno=00004 name=/data/oradata/eagaodb/users01.dbfinput datafile fno=00011 name=/data/oradata/eagaodb/eaindex_idx01.dbfchannel ch2: starting piece 1 at 11-6月 -12channel ch2: finished piece 1 at 11-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120611_03nd9bdd_1_1 tag=TAG20120611T151213 comment=NONEchannel ch2: backup set complete, elapsed time: 00:02:05channel ch2: starting full datafile backupsetchannel ch2: specifying datafile(s) in backupsetincluding current control file in backupsetchannel ch2: starting piece 1 at 11-6月 -12channel ch2: finished piece 1 at 11-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120611_04nd9bha_1_1 tag=TAG20120611T151213 comment=NONEchannel ch2: backup set complete, elapsed time: 00:00:04channel ch2: starting full datafile backupsetchannel ch2: specifying datafile(s) in backupsetincluding current SPFILE in backupsetchannel ch2: starting piece 1 at 11-6月 -12channel ch2: finished piece 1 at 11-6月 -12piece handle=/data/backup/rmanback/db_EAGAODB_20120611_05nd9bhe_1_1 tag=TAG20120611T151213 comment=NONEchannel ch2: backup set complete, elapsed time: 00:00:02
user interrupt receivedFinished backup at 11-6月 -12
user interrupt receivedRMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03099: job cancelled at user request
备份集对应占用的空间:[oracle@st8cserver16 ~]$ df -hFilesystem Size Used Avail Use% Mounted on/dev/sda8 446G 361G 63G 86% /data[oracle@st8cserver16 ~]$ df -hFilesystem Size Used Avail Use% Mounted on/dev/sda8 446G 365G 59G 87% /data[oracle@st8cserver16 ~]$ df -h/dev/sda8 446G 369G 55G 88% /data[oracle@st8cserver16 ~]$ du -sh /data/backup/rmanback/46G /data/backup/rmanback/[oracle@st8cserver16 ~]$ du -sh /data/backup/rmanback/51G /data/backup/rmanback/
在取消备份之前,只有/data只有55G剩余空间,此时看看还剩下多少工作量没做:SQL> select sid,SERIAL# ,CONTEXT,SOFAR,TOTALWORK,round(SOFAR/TOTALWORK*100,2) "_%"from v$session_longops where OPNAME like 'RMAN%' and SOFAR<>TOTALWORK and TOTALWORK<>0;
SID SERIAL# CONTEXT SOFAR TOTALWORK _%---------- ---------- ---------- ---------- ---------- ---------- 125 27 1 6187576 36903680 16.77 --只备份了16.77%数据 137 44 3 8318776 39420364 21.1 --只备份了21.1%数据
SQL> select sid,SERIAL# ,CONTEXT,SOFAR,TOTALWORK,round(SOFAR/TOTALWORK*100,2) "_%" 2 from v$session_longops where OPNAME like 'RMAN%' and SOFAR<>TOTALWORK and TOTALWORK<>0;SID SERIAL# CONTEXT SOFAR TOTALWORK _%---------- ---------- ---------- ---------- ---------- ---------- 125 27 1 6286392 36903680 17.03 137 44 3 39420363 39420364 100 --取消后
SQL> select sid,SERIAL# ,CONTEXT,SOFAR,TOTALWORK,round(SOFAR/TOTALWORK*100,2) "_%" 2 from v$session_longops where OPNAME like 'RMAN%' and SOFAR<>TOTALWORK and TOTALWORK<>0;no rows selected --再过一分钟后消失
此时再看备份集多大:[oracle@st8cserver16 ~]$ df -h |grep data/dev/sda8 446G 327G 97G 78% /data
[oracle@st8cserver16 ~]$ du -sh /data/backup/rmanback/3.2G /data/backup/rmanback/
发现取消后,ORACLE删除了那个最大的备份集
由上面的数据可以看出:基本增长1%,备份集就要加大1G,所以完成备份,至少需要200G左右的磁盘空间,但实际的数据量只有SQL> select sum1-sum2 from (select sum(bytes)/1024/1024 sum1 from dba_data_files), (select sum(bytes)/1024/1024 sum2 from dba_free_space);
SUM1-SUM2----------24850.5625 --24G左右
所以结论:RMAN会备份之前分配过了的但现在没数据的空间也会备份,所以要建立多个表空间,分别存放需要备份,与不需要备份的数据。