一、冷备份实验模拟当机,加归档补齐
实验步骤:
1.查看要备份的数据文件
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/oracle/oradata/zwb/system01.dbf
/oracle/oradata/zwb/undotbs01.dbf
/oracle/oradata/zwb/sysaux01.dbf
/oracle/oradata/zwb/users01.dbf
/oracle/oradata/zwb/example01.dbf
2、查看要备份的控制文件
SQL> select name from v$controlfile;
NAME
--------------------------------------------------------------------------------
/oracle/oradata/zwb/control01.ctl
/oracle/oradata/zwb/control02.ctl
/oracle/oradata/zwb/control03.ctl
3.查看要备份的日志文件
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/oracle/oradata/zwb/redo03.log
/oracle/oradata/zwb/redo02.log
/oracle/oradata/zwb/redo01.log
4、查看是否归档模式,没有设为归档
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/archlog
Oldest online log sequence 17
Next log sequence to archive 19
Current log sequence 19
5、关数据库
SQL> shutdown immediate
6、开始备份
[oracle@testsvr bak]$ cd /oracle/oradata/zwb/
[oracle@testsvr zwb]$ cp * /oracle/bak ---备份至/oracle/bak
7、开启数据库,切归档
[oracle@testsvr bak]$ sqlplus '/as sysdba'
SQL> startup
SQL> alter system switch logfile;
System altered.
8、换用户做事
SQL> conn zwb/zwb
Connected.
SQL> create table t1 as select * from v$bh; ---随便创建表格
Table created.
SQL> select count(*) from t1; ---看一下建的表的数据
COUNT(*)
----------
4959
9、连续插数据再切归档,提交
SQL> insert into t1 select * from t1;
4959 rows created.
SQL> alter system switch logfile;
System altered.
SQL> commit;
Commit complete.
SQL> insert into t1 select * from t1;
9918 rows created.
SQL> commit;
Commit complete.
SQL> alter system switch logfile;
System altered.
10、假设此时数据库当机
SQL> select count(*) from t1; --当之前的数据
COUNT(*)
----------
19836
***************************************
SQL> insert into t1 select * from t1; --再插数据
19836 rows created.
SQL> commit;
Commit complete.
SQL> select count(*) from t1; ---当后的数据放在redolog里
COUNT(*)
----------
39672
11、查看最后更改值存放在哪里,由于是存放在CURRENT redolog里,所以是存放在2号文件
SQL> select * from v$log ;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS
---------- ---------- ---------- ---------- ---------- --- ----------------
FIRST_CHANGE# FIRST_TIM
------------- ---------
1 1 26 52428800 1 YES ACTIVE
751890 23-MAY-12
2 1 27 52428800 1 NO CURRENT
751893 23-MAY-12
3 1 25 52428800 1 YES ACTIVE
751772 23-MAY-12
即如果/oracle/oradata/zwb/redo02.log 数据损坏,最后插的数据永远丢失
*************************************************** 此时当机
12、当机
SQL> shutdown abort;
ORA-01031: insufficient privileges
SQL> conn /as sysdba
Connected.
SQL> shutdown abort;
ORACLE instance shut down.
13、模拟数据文件、控制文件、日志文件由于当机均丢失
[oracle@testsvr bak]$ pwd ---进入备份目录
/oracle/bak
[oracle@testsvr zwb]$ pwd
/oracle/oradata/zwb
[oracle@testsvr zwb]$ rm -rf *
[oracle@testsvr zwb]$ ls -rtl
total 0
14、将之前的冷备份恢复
[oracle@testsvr bak]$ pwd
/oracle/bak
[oracle@testsvr bak]$ cp * /oracle/oradata/zwb
[oracle@testsvr zwb]$ ls -rtl --查看已恢复
total 1090552
-rw-r----- 1 oracle oinstall 7061504 May 23 23:43 control01.ctl.beifen
-rw-r----- 1 oracle oinstall 7061504 May 23 23:43 control01.ctl.bak
-rw-r----- 1 oracle oinstall 7389184 May 23 23:43 control01.ctl
-rw-r----- 1 oracle oinstall 7389184 May 23 23:43 control03.ctl
-rw-r----- 1 oracle oinstall 7389184 May 23 23:43 control02.ctl
-rw-r----- 1 oracle oinstall 104865792 May 23 23:43 example01.dbf
-rw-r----- 1 oracle oinstall 52429312 May 23 23:43 redo01.log
-rw-r----- 1 oracle oinstall 52429312 May 23 23:43 redo02.log
-rw-r----- 1 oracle oinstall 7061504 May 23 23:43 standby01
-rw-r----- 1 oracle oinstall 52429312 May 23 23:43 redo03.log
-rw-r----- 1 oracle oinstall 251666432 May 23 23:44 sysaux01.dbf
-rw-r----- 1 oracle oinstall 503324672 May 23 23:44 system01.dbf
-rw-r----- 1 oracle oinstall 5251072 May 23 23:44 users01.dbf
-rw-r----- 1 oracle oinstall 31465472 May 23 23:44 undotbs01.dbf
-rw-r----- 1 oracle oinstall 20979712 May 23 23:44 temp01.dbf
15、读归档
SQL> startup mount;
ORACLE instance started.
SQL> recover database; ---不行
ORA-00283: recovery session canceled due to errors
ORA-00264: no recovery required
SQL> recover database using backup controlfile; ---补齐归档
16、最终查看
SQL> alter database open read only; ---需要不完全恢复
alter database open read only
*
ERROR at line 1:
ORA-16004: backup database requires recovery
ORA-01113: file 1 needs media recovery
ORA-01110: data file 1: '/oracle/oradata/zwb/system01.dbf'
SQL> recover database using backup controlfile until cancel; ----不完全恢复
ORA-00279: change 751893 generated at 05/23/2012 23:23:00 needed for thread 1
ORA-00289: suggestion : /oracle/archlog/1_27_765904367.dbf
ORA-00280: change 751893 for thread 1 is in sequence #27
Specify log: {
cancel
SQL> conn zwb/zwb ---最终查看结果
Connected.
SQL> select count(*) from t1;
COUNT(*)
----------
19836
结论:当机前未归档的数据丢失
二、裸设备上做冷备:(以备份1号数据文件为例)
1、SQL> select file#,name,bytes from v$datafile; ---查出1号数据文件大小
FILE# NAME BYTES
---------- ---------------------------------------- ----------
1 /oracle/oradata/zwb/system01.dbf 503316480
2 /oracle/oradata/zwb/undotbs01.dbf 31457280
3 /oracle/oradata/zwb/sysaux01.dbf 251658240
4 /oracle/oradata/zwb/users01.dbf 17039360
5 /oracle/oradata/zwb/example01.dbf 104857600
2、[oracle@testsvr ~]$ ls -l /oracle/oradata/zwb/system01.dbf ---系统上的大小
-rw-r----- 1 oracle oinstall 503324672 May 25 23:08 /oracle/oradata/zwb/system01.dbf
3、SQL> select 503324672-503316480 from dual; --相差8192,是操作系统头
503324672-503316480
-------------------
8192
4、SQL> select (503316480+8192)/8192 from dual; ---count的值
(503316480+8192)/8192
---------------------
61441
SQL> select TABLESPACE_NAME,BLOCK_SIZE from dba_tablespaces; ---bs来源
TABLESPACE_NAME BLOCK_SIZE
------------------------------ ----------
SYSTEM 8192
UNDOTBS1 8192
SYSAUX 8192
TEMP 8192
USERS 8192
EXAMPLE 8192
5、[oracle@testsvr ~]$ dd if=/oracle/oradata/zwb/system01.dbf of=/oracle/bak/system01.dbf.bak bs=8192 count=61441 ---用DD命令备份
注意点:AIX裸设备还有4K的访问头