1、备份的分类
物理备份:备份database的数据文件、控制文件、参数文件等(备份database的物理结构),可以用于任何形式的failure。
1) 手工备份:通过OS 的命令,对要备份的文件拷贝
2)rman 备份:利用oracle 的备份工具rman 备份(或其他备份软件)
逻辑备份:只备份database 的object的数据结构和数据(如对单个表的备份),不能用于media failure ,只能恢复到备份点。
1) exp/imp
2)expd/impd
——完整的备份应该以物理备份为主,逻辑备份辅助(用于备份一些重要的表)
2、手工备份
1)数据库全备:备份database的所有数据块(datafiles、controlfile)
2)部分备份:只备份单个表空间或datafile(archivelog 模式)
3)一致性备份(冷备份):在数据库正常关闭情况下做备份,数据库处于一致性状态。(可以用于archive和noarchive)
4)非一致性备份(热备份):database 在open状态下备份(用于archive 模式)
3、一致性备份和非一致性备份的区别
1)一致性备份(冷备份):在数据库正常关闭情况下做备份,数据库处于一致性状态。(可以用于archive和noarchive)
2)非一致性备份(热备份):database 在open状态下备份(用于archive 模式)
4、手工备份和恢复的命令
1)备份用os 命令
2)恢复用sql命令:restore(cp 备份)、recover(利用redo日志,包括归档的和当前的)
5、备份之前对数据库的检查:
v$datafile\v$controlfile\v$logfile\dba_tablespaces\dba_data_files
1)检查需要备份的数据文件
SQL> col name for a50
SQL> select name from v$datafile;
NAME
--------------------------------------------------
/u01/app/oracle/oradata/anny/system01.dbf
/u01/app/oracle/oradata/anny/lx02.dbf
/u01/app/oracle/oradata/anny/sysaux01.dbf
/u01/app/oracle/oradata/anny/user01.dbf
/u01/app/oracle/oradata/anny/text01.dbf
/u01/app/oracle/oradata/anny/lx01.dbf
/u01/app/oracle/oradata/anny/undotbs01.dbf
/u01/app/oracle/oradata/anny/lx03.dbf
/u01/app/oracle/oradata/anny/lx04.dbf
/u01/app/oracle/oradata/anny/index01.dbf
10 rows selected.
SQL> col file_name for a50
SQL> col tablespace_name for a20
SQL> select file_id,file_name,tablespace_name from dba_data_files;
FILE_ID FILE_NAME TABLESPACE_NAME
---------- -------------------------------------------------- --------------------
5 /u01/app/oracle/oradata/anny/text01.dbf TEXT
4 /u01/app/oracle/oradata/anny/user01.dbf USERS
3 /u01/app/oracle/oradata/anny/sysaux01.dbf SYSAUX
2 /u01/app/oracle/oradata/anny/lx02.dbf LX02
1 /u01/app/oracle/oradata/anny/system01.dbf SYSTEM
6 /u01/app/oracle/oradata/anny/lx01.dbf LX01
7 /u01/app/oracle/oradata/anny/undotbs01.dbf UNDOTBS
8 /u01/app/oracle/oradata/anny/lx03.dbf LX03
9 /u01/app/oracle/oradata/anny/lx04.dbf LX04
10 /u01/app/oracle/oradata/anny/index01.dbf INDEXES
10 rows selected.
2) 检查要备份控制文件
SQL> select name from v$controlfile;
NAME
--------------------------------------------------
/u01/app/oracle/oradata/anny/control01.ctl
/disk1/oradata/anny/control02.ctl
/disk2/oradata/anny/control03.ctl
——redo日志不需要做备份
——查看日志信息
SQL> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARCHIVED STATUS FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --------- --------------- ------------- -------------------
1 1 17 104857600 3 YES INACTIVE 555743 2012-03-16 18:23:17
4 1 16 104857600 3 YES INACTIVE 529570 2012-03-16 15:12:44
3 1 15 104857600 3 YES INACTIVE 494997 2012-03-15 11:03:00
2 1 18 104857600 3 NO CURRENT 576357 2012-03-19 14:09:01
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------
/disk3/oradata/anny/redo01a.log
/disk3/oradata/anny/redo03a.log
/disk3/oradata/anny/redo02a.log
/disk3/oradata/anny/redo04a.log
/disk1/oradata/anny/redo01b.log
/disk1/oradata/anny/redo02b.log
/disk1/oradata/anny/redo03b.log
/disk1/oradata/anny/redo04b.log
/disk2/oradata/anny/redo01c.log
/disk2/oradata/anny/redo02c.log
/disk2/oradata/anny/redo03c.log
/disk2/oradata/anny/redo04c.log
12 rows selected.
3)查看database模式
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /disk1/arch/anny
Oldest online log sequence 15
Next log sequence to archive 18
Current log sequence 18
6、归档和非归档模式备份的区别
1)归档模式可以做一致性备份和非一致性备份,恢复时可做完全恢复和不完全恢复。
2)非归档模式只能用于一致性完全备份,恢复时,只能恢复到最后一次完全备份状态
7、非一致性备份(热备份)的执行方式及热备份的监控(v$backup)
——一致性备份(冷备份)就只需要正常关库,将数据文件和控制文件利用OS的CP命令备份即可。
——对只读的表空间不能做热备份,临时表空间不需要备份
因为只读表空间的检查点是固定不变,在开始热备份时会写入一个新的检查点,这样两者就会相矛盾,所以只读表空间只需要做一次冷备份就行。
1)在备份前执行begin backup (在数据文件上生成检查点,写入scn ,将来恢复的时候以此scn 为起点)
SQL> atler database begin backup ; //对整个库做热备份
alter database end backup;
alter tablespace users begin backup;//对表空间做备份
alter tablespace users end backup;
2)备份期间利用v$backup 监控
SQL> alter tablespace users begin backup;
Tablespace altered.
SQL> select file#,checkpoint_change# from v$datafile_header;
FILE# CHECKPOINT_CHANGE#
---------- ------------------
1 578177
2 578177
3 578177
4 578218 ——备份期间,scn号不变
5 578177
6 578177
7 578177
8 578177
9 578177
10 578177
10 rows selected.
SQL> desc v$backup;
Name Null? Type
----------------------------------------------------------------- -------- --------------------------------------------
FILE# NUMBER
STATUS VARCHAR2(18)
CHANGE# NUMBER
TIME DATE
SQL> select * from v$backup;
FILE# STATUS CHANGE# TIME
---------- --------------- ---------- -------------------
1 NOT ACTIVE 578177 2012-03-19 15:02:07
2 NOT ACTIVE 578177 2012-03-19 15:02:07
3 NOT ACTIVE 578177 2012-03-19 15:02:07
4 ACTIVE 578218 2012-03-19 15:03:39 ——处于活跃状态,说明正在备份
5 NOT ACTIVE 578177 2012-03-19 15:02:07
6 NOT ACTIVE 578177 2012-03-19 15:02:07
7 NOT ACTIVE 578177 2012-03-19 15:02:07
8 NOT ACTIVE 578177 2012-03-19 15:02:07
9 NOT ACTIVE 578177 2012-03-19 15:02:07
10 NOT ACTIVE 578177 2012-03-19 15:02:07
10 rows selected.
3)备份完毕,执行end backup
SQL> alter tablespace users end backup;
Tablespace altered.
SQL> select * from V$backup;
FILE# STATUS CHANGE# TIME
---------- --------------- ---------- -------------------
1 NOT ACTIVE 578177 2012-03-19 15:02:07
2 NOT ACTIVE 578177 2012-03-19 15:02:07
3 NOT ACTIVE 578177 2012-03-19 15:02:07
4 NOT ACTIVE 578218 2012-03-19 15:03:39
5 NOT ACTIVE 578177 2012-03-19 15:02:07
6 NOT ACTIVE 578177 2012-03-19 15:02:07
7 NOT ACTIVE 578177 2012-03-19 15:02:07
8 NOT ACTIVE 578177 2012-03-19 15:02:07
9 NOT ACTIVE 578177 2012-03-19 15:02:07
10 NOT ACTIVE 578177 2012-03-19 15:02:07
10 rows selected.
——进行热备份时一定要有begin backup 和end backup!!!
8、控制文件备份
1) trace 文件:用于控制文件的重建(记录database的物理架构)
SQL> alter database backup controlfile to trace;
——生成的trace 文件保存在udump的目录下
2) 二进制文件:用于database不完全恢复(或控制文件的恢复)
SQL> alter database backup controlfile to '/home/oracle/prod_control.bak';
9、spfile 备份 (pfile)
1)手工时可以不做备份,可以通过pfile 生成
SQL> create pfile from spfile;
File created.
2)rman 自动备份
10、dbv检查数据文件是否有坏块
1)在手工备份前,应该检查datafile 是否有坏块,备份完后对备份也做检查
SQL> !
[oracle@solaris10 ~]$dbv
DBVERIFY: Release 10.2.0.2.0 - Production on Mon Mar 19 15:23:29 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Keyword Description (Default)
----------------------------------------------------
FILE File to Verify (NONE)
START Start Block (First Block of File)
END End Block (Last Block of File)
BLOCKSIZE Logical Block Size (8192)
LOGFILE Output Log (NONE)
FEEDBACK Display Progress (0)
PARFILE Parameter File (NONE)
USERID Username/Password (NONE)
SEGMENT_ID Segment ID (tsn.relfile.block) (NONE)
HIGH_SCN Highest Block SCN To Verify (NONE)
(scn_wrap.scn_base OR scn)
[oracle@solaris10 ~]$dbv file=/u01/app/oracle/oradata/anny/system01.dbf
DBVERIFY: Release 10.2.0.2.0 - Production on Mon Mar 19 15:32:46 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
DBVERIFY - Verification starting : FILE = /u01/app/oracle/oradata/anny/system01.dbf
DBVERIFY - Verification complete
Total Pages Examined : 41600
Total Pages Processed (Data) : 10061
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 3194
Total Pages Failing (Index): 0
Total Pages Processed (Other): 1769
Total Pages Processed (Seg) : 0
Total Pages Failing (Seg) : 0
Total Pages Empty : 26576
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Highest block SCN : 579041 (0.579041)
2)rman备份时,会自动检查
总机:(010)-88589926,88589826,88587026 QQ讨论群:243729577 182441349 邮箱:cuug_bj@cuug.com
通信地址:北京市海淀区紫竹院路98号北京化工大学科技园609室(CUUG)邮政编码:100089
中国UNIX用户协会 Copyright 2010 ALL Rights Reserved 北京神脑资讯技术有限公司
京ICP备11008061号 京公网安备110108006275号