oracle備份

lelepapa發表於2011-11-09

備份

1 冷備份
完全離線備份(achivelog|noarchivelog)
shutdown
copy


2部分離線備份(歸檔模式)表空間
offline
os copy


3部分聯機備份
alter tablespace users begin backup;

oracle10g支援alter database begin backup;
select * from v$backup(裡面就是恢復的起點);
比change#小得都已經記錄在資料檔案裡面

備份也需要copy資料
這個我覺得只是記錄一個點。。就是從哪裡開始恢復

alter tablespace users end backup;
copy完需要給這個命令來結束備份

這種備份有風險

看看oracle的解釋

Detection of Fractured Blocks During Open Backups

One danger in making online backups is the possibility of inconsistent data within a block. For example, assume that you are backing up block 100 in datafile users.dbf. Also, assume that the copy utility reads the entire block while DBWR is in the middle of updating the block. In this case, the copy utility may read the old data in the top half of the block and the new data in the bottom top half of the block. The result is called a fractured block, meaning that the data contained in this block is not consistent. at a given SCN.

When performing backups of an open tablespace without using RMAN, you must put tablespaces in backup mode to prevent the creation of fractured blocks in your backup. When not in backup mode, the database records only changed bytes in the redo stream. When a tablespace is in backup mode, each time a block is changed the database writes the before-image of the entire block to the redo stream before modifying the block. Then, the database also records the changes to the block in the redo log. During user-managed recovery using SQL*Plus, the database applies both the captured block images and the recorded block changes from the redo logs. Applying the block images repairs any possible fractured blocks in the backup being restored and recovered.

RMAN does not require that you put datafiles into backup mode. During an RMAN backup, a database server session reads each block of the datafile and checks whether each block is fractured by comparing the block header and footer. If a block is fractured, the session re-reads the block. If the same fracture is found, then the block is considered permanently corrupt. If MAXCORRUPT is exceeded, the backup stops.

 

 

4,rman

run{

allocate channel  c1 device type disk;

allocate channel  c2 device type disk;

backup as compressed backupset database

}

 

list backup;

crosscheck backupset;

delete expired backupset;

list backup of database;

 

restore preview database;預覽oracle使用哪個來恢復

from tag= 或者空格

還可以備份tablespace  datafile
backup current controlfile;備份當前控制檔案;
在oracle高階技術裡面v$database裡面的controlfile_type也可能是standby
backup spfile;
臨時檔案和redo不能備份;必須要求open以及archivelog模式;
 
用rman非歸檔模式必須在mount的時候備份,也就是冷備份;
還可以備份archivelog
 
backup archivelog all
backup archivelog all not backed up備份新的歸檔日誌。備份archivelog的時候需要切換日誌;
backup archivelog all delete input;備份完刪除磁碟上的歸檔日誌;
 
手動維護rman備份
delete  noprompt  backup;
刪除所有backup;
 
delete backupset  19;
刪除一個備份級別;
 
list backupset 17可以列出單獨的備份片;
 
 
crosscheck archivelog all ;
delete expired archivelog all;
 
 
rman的有個設定show all可以看到。
retention policy redundance 1;預設保留一份完整的有效備份,其他均廢棄;
可修改為7天
configure retention policy to recovery window 7 days;
report obsolete 檢視廢棄的備份
delete obsolete 刪除廢棄備份;
 
 
report schema;在rman裡看資料庫的物理結構;
 
backup database;
delete noprompt obsolete;
backup archivelog all;
 
configure backup optimiztion on;則備份過的archivelog就不備份了。
configure controlfile autobackup off;如果開啟,不管你備份什麼,控制檔案都自動備份;
 
list backup of archivelog sequece 71;檢視日誌檔案71號;
 
配置預設就最後加上clear;
只要我們備份system表空間包含的資料檔案。則自動備份controlfile以及spfile;
 
 
完全離線備份缺點
1shutdown
2copy
部分離線備份(tablespace offline)
copy
online
事物之後 offline 損壞
online
 
rman讀取的保留策略的時間是從哪裡得到的?
configure controlfile autobackup format for device type disk to '%F'
backup database format 'c:\temp\%d_%T_%U.bak';
rman target catalog
connect ,resouce,recovery_catalog_owner;角色;授予catalog裡面的rman使用者;
create catalog:建立一堆的物件到catalog資料庫;
現在還沒關聯上
register database;讀取target的控制檔案內容放到catalog表裡。
resync catalog;
catalog 命令。如果控制檔案損壞,重建控制檔案丟失備份資訊,可以把以前的備份檔案重新註冊到catalog裡面。
coverting column overflows integer datatype;
waiting for snapshot cotorlfile enquence;

在rman裡面可以建立指令碼。必須在catalog模式;
create script. scr1
{backup as compressed backupset database;
 delete noprompt obsolete;
 backup archivelog all;
}
list script. names;
輸出指令碼內容print script. scr1;
指令碼必須在run裡面執行
run{
execute script. scr1; }
修改指令碼方法;
print script. scr1 to file 'c:\1.txt';
replace script. scr1 from file 'c:\1.txt';
也可以建立global script. 所有的target資料庫都能看到;

增量備份
backup incremental level=0 database;
bakkup incremental level=1 database;增量1;
backup incremental level=1 cumulative database;累計增量備份;
list backup of database summary;檢視彙總

dbv檢查壞塊
backup validate database;rman 檢查;
也可以對單獨的資料檔案檢查;
rman可以單獨恢復壞塊。
blockrecover datafile 4 block 730;
set maxcorrupt for datafile 4 to 1;有1個折斷塊也可以備份了;
記錄檢視到 v$database_block_corruption;
 
不完全恢復:
drop表了。要恢復到drop之前
recover database until change 87989798;在rman裡面叫scn;
recover database until timestamp to_timestamp('')
resetlogs;
開啟資料庫
必要條件v$datafile 和v$datafile_header;
線上聯機日誌損壞就不行了。做不完全恢復。
recover database;=完全恢復;
until sequence 就是恢復到比這個小的;
 
 
 
 
 
 
 
 
alter database backup controlfile to trace as 'c:\a.txt' restlogs;
只要resetlog那一段;
並且儲存在c盤下a.txt;
 
noresetlog就表示當前日誌沒損壞的時候使用;
 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22374393/viewspace-710514/,如需轉載,請註明出處,否則將追究法律責任。

相關文章