<1>邏輯備份
不用去拷貝數據庫的物理文件
備份邏輯上的結構
外部的工具:導出和導入的工具
DOS下的命令 cmd下執行
導出exp export縮寫形式
查看幫助 exp help=y
使用參數文件導出
exp parfile=c:/abc.par
>>>abc.par的內容
a)scott用戶連接導出自己的所有對象
userid=scott/tiger --連接的用戶scott
file=c:/a1.dmp --導出的文件的名字a1.dmp
--導出了scott用戶的所有對象
b)用system連接來導出scott下的所有對象
exp parfile=c:/sys.par
>>>>sys.par的內容
userid=system/manager
file=c:/b1.dmp
owner=(scott) --導出scott用戶的所有對象
導出多個用戶的數據
建立一個測試用戶 test
grant connect,resource
to test identified by t123;
alter user test
default tablespace users
temporary tablespace temp;
create table student(
stu_id number(4) primary key,
stu_name varchar2(20),
stu_score number(2)
);
insert into student values (1000,
'Mike',95);
insert into student values (1001,
'John',90);
導出scott和test下的所有對象????
>>>userid=system/manager
file=c:/st.dmp
owner=(scott,test)
導出scott下的emp,dept表????
>>>userid=system/manager
file=c:/st.dmp
tables=(scott.emp,scott.dept,test.student)
導出整個數據庫(備份整個數據庫)
必須用超級用戶 system ,sys
exp system/manager file=c:/system.dmp full=y feedback=1000
或者
exp parfile=c:/sys.par
>>>sys.par
userid=system/manager
file=c:/system.dmp
full=y
比較全的一個導出的參數文件
>>>sys.par
userid=system/manager
file=c:/aa.dmp
buffer=1024000 --緩衝
rows=y --是否導出記錄
compress=y --extent是否壓縮
grants=y --grant語句是否導出
indexes=y --導出索引
full=y --全庫導出
feedback=3 --顯示導出進度每3行
導出表scott.dept中部門編號是40的記錄
>>>sys.par
userid=system/manager
file=c:/sys.dmp
tables=(scott.emp)
query="where deptno=10"
導出表scott.emp中的記錄
>>>sys.par
userid=system/manager
file=c:/sys.dmp
tables=(scott.emp)
feedback=3 --每3行記錄顯示一個點進度
如何把導出的數據導入到數據庫中進行恢復??
imp import縮寫形式
dos命令
imp help=y 查看幫助
<1>把scott下的表emp導出 ,
然後刪除表中的內容(truncate table emp),
利用導出的文件來恢復??
a)導出
exp parfile=c:/sys.par
>>> sys.par
userid=system/manager
file=c:/emp.dmp
tables=(scott.emp)
b)刪除
truncate table emp; --刪數據
或者
drop table emp; --刪除結構
( delete from emp; --刪數據可以恢復)
c)恢復
imp prafile=c:/im.par;
>>>im.par
userid=system/manager
file=c:/emp.dmp
fromuser=scott --從哪個用戶來恢復
show=y --顯示導入文件中的SQL語句
<2>scott下的對象全部複製到test用戶下
(克隆用戶scott)
a)導出scott用戶
exp parfile=c:/sys.par
>>>sys.par
userid=system/manager
file=c:/scott.dmp
owner=(scott)
b)導入scott.dmp文件中的內容到test用戶下
imp parfile=c:/im.par
>>>im.par
userid=system/manager
file=c:/scott.dmp
fromuser=scott
touser=test
<3>scott用戶導出數據後
用戶scott被刪除了
怎麼來恢復??????
a)導出scott用戶
exp parfile=c:/sys.par
>>>sys.par
userid=system/manager
file=c:/scott.dmp
owner=(scott)
b)刪除scott用戶
drop user scott cascade;
c)恢復
先建立用戶scott
grant connect,resource to scott
identified by tiger;
alter user scott
default tablespace users
temporary tablespace temp;
然後導入
imp parfile=c:/im.par
>>im.par
userid=system/manager
file=c:/scott.dmp
fromuser=scott
<4>如何進行全庫導入
imp system/manager
file=c:/all.dmp full=y ignore=y
full ---全庫
ignore ---忽略導入過程中的錯誤
如何建立一個新的數據庫 ?????
使用DATABASE CONFIGURATION ASSISTANT
備份的第二種模式 物理備份
拷貝數據文件
數據文件 + 歸檔日誌文件 = 整個數據庫
在數據庫不關閉的情況下備份(熱備份)
<1>數據庫可以關閉的物理備份(冷備份)
a)關閉數據庫
b)拷貝數據文件
c)打開數據庫
數據庫工作在歸檔和非歸檔模式都可以
a)關閉數據庫
connect system/manager
shutdown immediate;
b)拷貝文件
數據文件 v$DATAFILE
控制文件 v$controlfile
日誌文件 v$
臨時數據文件
c)打開數據庫
startup;
寫一個腳本文件 執行上述功能
cold_back.txt
如何用冷備份來恢復數據庫
用備份的文件來覆蓋原來的文件,就OK
<2>數據庫不能關閉的情況下作熱備份
(24x7運行的系統)
a)設置數據庫工作在歸檔模式下
b)備份表空間
c)作一次日誌切換 (把在熱備份過程中產生的數據寫到歸檔日誌中)
d)備份歸檔日誌文件
--數據庫有哪些表空間
select tablespace_name from dba_tablespaces
where status <> 'READ ONLY';
--每個表空間對應的數據文件
select file_name from dba_data_files
where tablespace_name='SYSTEM';
--要拷貝SYSTEM表空間所對應的數據文件
--使表空間system處於熱備份狀態
alter tablespace system begin backup;
--拷數據文件
host copy D:/ORACLE/ORADATA/ACCP/SYSTEM01.DBF c:/backup
--關閉熱備份狀態
alter tablespace system end backup;
--
recover database;
--數據庫損壞的情況下來恢復
recover database datafile 4;
恢復第4個數據文件
Oracle學習筆記摘錄10-----ORACLE備份和恢復
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.