Oracle資料庫熱備份(聯機備份)樣本
必須將日誌置為歸檔方式
SQL>archive log list; --查看日誌歸檔方式.
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 106
Current log sequence 108
SQL>alter system set log_archive_start=true scope=spfile --啟用自動歸檔
SQL>shutdown immediate
SQL>startup mount --啟動資料庫,開啟控制檔案,不開啟資料檔案
SQL>alter database archivelog --將資料庫切換到歸檔方式
SQL>alter database open; --開啟資料庫
SQL>archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 106
Next log sequence to archive 108
Current log sequence 108
SQL>alter tablespace tt begin backup; --tt資料表空間備份.
SQL>alter tablespace tt end backup;
SQL>alter system archive log current; --將當前聯機日誌歸檔,切換日誌.
SQL>alter system switch logfile; --切換第二個日誌
SQL>alter system switch logfile; --切換第三個日誌
SQL>shutdown immediate;
如果tt.dbf檔案損壞.
SQL>startup
ORA-01157:cannot identify/lock data file 6 - see DBWR trace file
ORA-01110:data file 6: 'C:\ORACLE\ORADATA\TEST\TT.DBF'
SQL>SELECT * FROM v$recover_file;
FILE# ONLINE ONLINE_ERROR CHANGE# TIME
---------- ------- ------------------------- ----------- -------------
6 ONLINE ONLINE FILE NOT FOUND 0
SQL>alter database datafile 6 offline drop;
SQL>alter database open;
--將備份檔案恢複到原路徑
SQL>recover datafile 6;
SQL>alter database datafile 6 online;
SQL>alter database backup controlfile to trace; --備份控制檔案 to \udmp\.
SQL>start c:\create_ctl.sql --重建控制檔案
--記錄檔丟失
SQL>recover database until cancel
SQL>alter database open resetlogs