在打開模式下對數据文件進行備份的方法是將表空間置於備份模式,當表空間處於備份模式時,會發生以下事件:
1. 每個文件首部的標記都被設置,指出退將進行熱備份。
2. 表空間數据文件執行某一檢查點,內存中所有“髒”數据塊都被寫入該文件中。檢查點的SCN被寫入數据文件的首部和控制文件中
3. 告警日誌文件中添加信息
4. 數据文件中的任何塊被首次發言前,有關每個已變化塊的一個塊映像被拷貝到重做日誌中
表空間處於備份模式時,可以使用操作系統拷貝命令,將數据文件拷貝到其他地方。如果多個用戶正在更新這些表空間,則熱備份期間產生的重做日誌的數量會明顯增加,因為重做日誌中必須保留已變化數据塊的一個拷貝。因此,應在數据庫活動較少時進行打開數据庫的備份。
拷貝完成後,將表空間脫离備份模式。會發生以下事件:
1. 熱備份標誌被清除,說明備份已經結束。
2. 在重做流中記錄下終止備份SCN,作為一個重做矢量。Oracle利用這個重做記錄,可以知道在數据文件恢复過程中何時將表空間脫离熱備份。
3. 重做生成返回到正常方式。
熱備的步驟:
1. 切換日誌文件,确保在備份前所做的所有更改都被歸檔
2. 將一個表空間設置為熱備份模式
3. 拷貝該表空間的數据文件
4. 脫离備份模式
5. 對於每個表空間循環 2-4
6. 切換日誌文件,确保備份後所做的所有更改都已經歸檔
7. 備份當前控制文件
[@more@]set feedback off pagesize 0 heading off verify off linesize 100 trimspool on define dir='d:backuphot' define fil='C:WINDOWSTempora_hot_backup.sql' define spo='&diropen_backup_output.txt' prompt *** spooling to &fil set serveroutput on spool &fil prompt spool &spo prompt archive log list;; prompt alter system switch logfile;; declare -- tablespace cursor cur_tablespace is select tablespace_name from dba_tablespaces where status<>'READ ONLY' and contents<>'TEMPORARY'; -- datafile cursor cur_datafile (tn varchar) is select file_name from dba_data_files where tablespace_name=tn; begin for ct in cur_tablespace loop dbms_output.put_line('alter tablespace '||ct.tablespace_name||' begin backup;'); for cd in cur_datafile(ct.tablespace_name) loop dbms_output.put_line('host copy '||cd.file_name||' &dir'); end loop; dbms_output.put_line('alter tablespace '||ct.tablespace_name||' end backup;'); end loop; end; / prompt alter system switch logfile;; prompt alter database backup controlfile to '&dirbackup.ctl' reuse;; prompt archive log list;; spool off; @ &fil [huiyi.local@huiyi sh]$ cat hot_backup.sh #!/bin/ksh ORACLE_SID=huiyi export ORACLE_SID ORACLE_HOME=/opt/oracle/product/9.2 export ORACLE_HOME ORACLE_BASE=/opt/oracle export ORACLE_BASE #NLS_LANG="SIMPLIFIED CHINESE_CHINA.ZHS16GBK"; export NLS_LANG NLS_LANG="AMERICAN_AMERICA.ZHS16GBK" export NLS_LANG NLS_DATE_FORMAT='YYYY/MM/DD' export NLS_DATE_FORMAT echo "**************************************" echo "* hot_backup.sh " echo "**************************************" $ORACLE_HOME/bin/sqlplus -s "/ as sysdba" << ! set feedback off pagesize 0 heading off verify off linesize 100 trimspool on define dir='/backup/hot' define fil='/tmp/ora_hot_backup.sql' define spo='&dir/open_backup_output.lst' prompt *** spooling to &fil set serveroutput on spool &fil prompt spool &spo prompt archive log list;; prompt alter system switch logfile;; declare -- tablespace cursor cur_tablespace is select tablespace_name from dba_tablespaces where status<>'READ ONLY' and contents<>'TEMPORARY'; -- datafile cursor cur_datafile (tn varchar) is select file_name from dba_data_files where tablespace_name=tn; begin for ct in cur_tablespace loop dbms_output.put_line('alter tablespace '||ct.tablespace_name||' begin backup;'); for cd in cur_datafile(ct.tablespace_name) loop dbms_output.put_line('host cp '||cd.file_name||' &dir'); end loop; dbms_output.put_line('alter tablespace '||ct.tablespace_name||' end backup;'); end loop; end; / prompt alter system switch logfile;; prompt alter database backup controlfile to '&dir/backup.ctl' reuse;; prompt archive log list;; spool off; @ &fil exit !
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8799875/viewspace-914235/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8799875/viewspace-914235/