也談ORACLE備份與恢復

2021-09-04 10:33:45 字數 3344 閱讀 3371

經常聽到有人說,某資料庫備份方法好,某備份方法不好,或者說現在都流行用rman來備份了,邏輯備份已經過時了,冷備份就更不值一提了,其實資料庫的備份從來沒有什麼好壞之分、沒有過時之說,合適才是最重要的,自己好才是真的好。各種方法各有長短,誰也代替不了誰,只有根據實際情況搭配使用,才能發揮最大的作用,否則只能是東施效颦。

1. oracle的備份,包括noarchivelog模式的備份(冷備份)、archivelog模式的備份(熱備份、rman備份)、邏輯備份(不分模式)。

1.1. 冷備份:

-- 1)關閉資料庫

shutdown; 

-- 2)備份資料檔案、控制檔案、重做日誌檔案

-- a、 查詢備份檔案的位置

select * from v$datafile;     --查資料檔案

select * from v$controlfile;  --查控制檔案

select * from v$logfile;      --查日誌檔案

-- b、 備份資料檔案、控制檔案、重做日誌檔案

$ copy d:\oracle\oradata\ora9\*.dbf d:\bak\*.*;

$ copy d:\oracle\oradata\ora9\*.ctl d:\bak\*.*;

$ copy d:\oracle\oradata\ora9\*.log d:\bak\*.*;

1.2. 熱備份:

-- 1)查詢備份的資料檔案與哪乙個表空間有關

select v$tablespace.name,v$datafile.name

from v$tablespace join v$datafile using(ts#);

-- 2)備份資料檔案

alter tablespace 表空間 begin backup;

$ copy 資料檔案  存放路徑 

alter tablespace 表空間 end backup;

-- 3)查詢是否還有表空間處於備份模式

select * from v$backup;  --status不是active即可以

select v$tablespace.name,v$backup.status,v$datafile.name

from v$tablespace join v$datafile using (ts#) join v$backup using (file#);

-- 4)備份控制檔案

alter database backup controlfile to '目標路徑及檔名';

1.3. rman備份:

-- 1)乙個簡單的rman全庫備份:

> rman nocatalog target "sys/sys"

rman> restore controlfile from autobackup;

rman> configure controlfile autobackup on;

rman> backup database;

-- 2)備份資料檔案、控制檔案、歸檔日誌

rman> backup datafile 資料檔名;

rman> backup current controlfile;

rman> backup archivelog all;

-- 3)備份控制檔案trace

sql> alter session set tracefile_identifier=system ;

sql> alter database backup controlfile to trace;

sql> alter database backup controlfile to 'd:\temp\controlfile.bak';

-- 4)備份表空間

rman>  backup  tablespace 表空間名;

-- rman備份比較複雜,只舉些簡單的例子。

1.4. 邏輯備份

-- 1)資料庫方式(匯出使用者要具有exp_full_database許可權)

exp scott/tiger@ora9

full=y file="d:\full.dmp"

-- 2)使用者方式

exp userid=scott/tiger@ora9

owner=scott file=d:\scott.dmp log=d:\scott.log

-- 3)表方式

exp scott/tiger@ora9

tables=(emp,dept) file="d:\emp.dmp"

2. oracle的恢復(簡單舉例):

2.1 冷備份的恢復,

1). startup mount;

2). alter database datafile 資料檔案 offline drop; 

3). alter database open;

2.2 熱備份恢復:

1). startup mount;

2). alter database datafile 資料檔案 offline; -- 不能設定未offline狀態

3). alter database open;

2.3 rman備份恢復:

-- 1) 使用rman恢復歸檔資料庫:

rman target /

rman> startup mount

rman> restore database;

rman> recover database;

rman> alter database open;

--2) 使用rman恢復表空間:

rman> restore tablespace

rman> recover tablespace

rman>

run2.4 .邏輯恢復

--1)資料庫方式(匯入使用者要具有exp_full_database許可權)

imp system/system@ora10

full=y file="f:\full.dmp"

--2)使用者方式

imp userid=scott/tiger@ora10

fromuser=scott  touser=scott file=d:\scott.dmp log=d:\scott.log

--3)表方式

imp system/system@ora10

fromuser=scott touser=scott file="f:\emp.dmp"

--注意:匯出使用者要和匯入使用者相同可以用上面的方法,否則用

imp scott/tiger@ora10

full=y file="f:\emp.dmp"

本文出自 「srsunbing

」 部落格,請務必保留此出處

也談ORACLE備份與恢復

經常聽到有人說,某資料庫備份方法好,某備份方法不好,或者說現在都流行用rman來備份了,邏輯備份已經過時了,冷備份就更不值一提了,其實資料庫的備份從來沒有什麼好壞之分 沒有過時之說,合適才是最重要的,自己好才是真的好。各種方法各有長短,誰也代替不了誰,只有根據實際情況搭配使用,才能發揮最大的作用,否...

Oracle備份與恢復

oracle的備份與恢復有三種標準的模式,大致分為兩大類,備份恢復 物理上的 以及匯入匯出 邏輯上的 而備份恢復又可以根據資料庫的工作模式分為非歸檔模式 nonarchivelog style 和歸檔模式 archivelog style 通常,我們把非歸檔模式稱為冷備份,而相應的把歸檔模式稱為熱備...

oracle備份與恢復

完全恢復 前提條件 所需要的歸檔日誌檔案和online redolog都在 方式一 資料庫在開啟的情況下進行恢復 適合的環境 普通資料檔案損壞 非system undo的表空間的資料檔案 環境準備 1 以scott使用者登入,往test表當中插入資料,並導致日誌切換至少3組以上。sql select...