Oracle教程:使用者可管理的備份

來源:互聯網
上載者:User

SQL>host 作業系統命令;在sql*plus執行作業系統命令。
使用者管理的備份
全備:
資料檔案、控制檔案、redo log或歸檔檔案(可選)、參數檔案、口令檔案

得到資料庫檔案資訊以待備份
v$datafile
select name,status from v$datafile;
v$controlfile
select name from v$controlfile;
v$logfile
select member from v$logfile;
DBA_DATA_FILES
select file_name,tablespace_name from dba_data_files;

查詢資料檔案對應的資料表空間
select t.name tablespace, f.name datafile
from v$tablespace t,v$datafile f
where t.ts# = f.ts#
order by t.name;

非歸檔模式只能冷備(關閉Database Backup),歸檔模式可冷備和熱備。

冷備指令碼(linux下)
set feedback off heading off verify off trimspool off
set pagesize 0 linesize 200
define dir='/tmp/wb'
define ws='/tmp/ws.sql'
spool &ws
select '! cp' || name || '&dir' from v$datafile order by 1;//order by 1:按第一個列排序
select '! cp' || member || '&dir' from v$logfile order by 1;
select '! cp' || name || '&dir' from v$controlfile order by 1;
select '! cp' || name || '&dir' from v$tempfile order by 1;
spool off
shutdown immediate
@&ws
startup

熱備:
資料檔案、控制檔案、歸檔檔案、參數檔案、口令檔案

熱備資料表空間三部曲
一、alter tablespace xxwz begin backup;
二、備份資料表空間對應的資料檔案
三、alter tablespace xxwz end backup;
最好還備份歸檔檔案和控制檔案。

alter tablespace xxwz begin backup語句做了3件事
1.資料表空間被checkpoint
2.這個資料表空間對應的資料檔案的頭的SCN停止增長
3.改變的資料區塊整個都會被寫入redo log

SQL>select dbms_rowid.rowid_block_number(rowid) blk,name from bbk;使用PL/SQL查看記錄的塊位置;
$ dd if=example.dbf ibs=8192 skip=1011 count=2 | string;用指定大小的塊拷貝一個檔案。

v$backup查詢備份狀態

熱備資料表空間時突然斷電,資料庫只能啟動到mount狀態,用v$backup查詢備份狀態,end正在備份的資料表空間。alter database datafile 'xxx.dbf' end backup或者alter database end backup。

唯讀資料表空間的備份
alter tablespace xxx read only;設為唯讀,此時控制檔案被改變
備份資料檔案和控制檔案;

熱備控制檔案的備份(控制檔案改變時)
alter database backup controlfile to 'D:/xxxx.ctl';

alter database backup controlfile to trace as 'd:/xxx.sql';會丟失一些資訊

使用DBVERIFY檢查備份檔案是否損壞
dbv file=xxwz_data.dbf feedback=100 //檢測資料檔案
檢測表的損壞
先用select segment_name,tablespace_id,header_file,header_block from sys_dba_segs where segment_name like '%FRUIT%'; FRUIT為表名,要大寫
再用dbv userid=sys/sys segment_id=4.3.395 //4為tablespace_id,3為,header_file,395為header_block。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.