DBA_Oracle冷備份案例腳本本法(案例)

2014-08-10 Created By BaoXinjiansql

1、摘要數據庫


1. 冷備份安全

    數據庫在關閉狀態下完成全部物理系統文件拷貝的過程,也稱脫機備份oracle

    適合於非歸檔模式下,數據庫處於一致性狀態性能

2. 步驟   spa

    首先在運行的庫中獲得數據庫運行的全部的物理文件位置,而後在計劃內關閉數據庫(shutdown)日誌

    再執行拷貝物理文家到備份路徑或備份設備code

    備份完成後當即啓動數據庫讓其提供正常的服務blog

3. 總結 - 優勢ip

    冷備模式下概念易於理解,即將須要備份的文件複製到安全的位置

    操做比較簡單,不須要太多的干預

    容易恢復到某個時間點上(只需將文件再拷貝回去)

    能與歸檔方法相結合,做數據庫「最新狀態」的恢復。

4. 總結 - 缺點

   備份時,數據庫必須處於一致性關閉狀態

   只能提供到某一時間點的恢復

   備份時速度比較慢,尤爲是數據量大性能影響比較大

   不能實現基於表和用戶級別的數據恢復

 

2、冷備份


案例:首先應該在相關視圖裏查出數據庫的數據文件,日誌文件,控制文件,臨時文件所在的位置

   注意:不要直接把oradata下的cp就好了,由於生產庫裏各個文件一般分佈在不一樣的磁盤,不一樣的地方,因此在去視圖裏得到真實路徑 

 

1. 查看實例和數據庫的相關信息

SQL> select instance_name,version,status,archiver,database_status from v$instance;

 

SQL> select dbid,name,log_mode from v$database;

 

2. 查看數據文件及狀態信息

SQL> select file_name,tablespace_name,status,online_status from dba_data_files;

 

3. 查看數據文件

SQL> select name from v$datafile;



4. 查看臨時文件

SQL> select name from v$tempfile;

 

5. 查看日誌文件

SQL> select member from v$logfile;

 

6. 查看控制文件

SQL> select name from v$controlfile;

 

7. 建立備份目錄

SQL> ho mkdir /opt/oracle/coolbak

  

8. 使用鏈接符生成複製文件命令

select 'ho cp ' || name || ' &dir' from v$controlfile union all select 'ho cp ' || name || ' &dir' from v$datafile union all select 'ho cp ' || member || ' &dir' from v$logfile union all select 'ho cp ' || name || ' &dir' from v$tempfile
/

 

 9. 使用鏈接符生成複製文件命令

     [gavinsit.com]> vi /tmp/tmpbak.sql   --編輯tmpbak.sql,將下面的內容輸入到tmpbak.sql

set feedback off set heading off set verify off set trimspool off set pagesize 0 set linesize 200 define dir = '/opt/oracle/coolbak' define script = '/tmp/coolbak.sql' spool &script select 'ho cp ' || name || ' &dir' from v$controlfile union all select 'ho cp ' || name || ' &dir' from v$datafile union all select 'ho cp ' || member || ' &dir' from v$logfile union all select 'ho cp ' || name || ' &dir' from v$tempfile
/ create pfile = '&dir/spfilegavinsit.ora' from spfile; ho cp /opt/oracle/product/11.2.0/gavinsit/dbs/orapwgavinsit &dir spool off shutdown immediate start &script ho rm &script startup

 

8. 執行過程及數據庫啓動略

     SQL> @/tmp/tmpbak.sql;

SQL> @/tmp/tmpbak.sql ho cp /opt/oracle/oradata/gavinsit/control01.ctl /opt/oracle/coolbak ho cp /opt/oracle/flash_recovery_area/gavinsit/control02.ctl /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/system01.dbf /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/sysaux01.dbf /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/undotbs01.dbf /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/users01.dbf /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/example01.dbf /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/bxj_emp_data01.dbf /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/bxj_emp_data02.dbf /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/redo03.log /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/redo02.log /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/redo01.log /opt/oracle/coolbak ho cp /opt/oracle/oradata/gavinsit/temp01.dbf /opt/oracle/coolbak Database closed. Database dismounted. ORACLE instance shut down.

 

9. 啓動後查看備份的文件

ls /opt/oracle/coolbak

      control01.ctl  orapworcl   redo2b.rdo    system01.dbf   users01.dbf

      control02.ctl  redo1a.rdo  redo3a.rdo    tbs1_1.dbf

      example01.dbf  redo1b.rdo  redo3b.rdo    tbs1_2.dbf

      initorcl.ora   redo2a.rdo  sysaux01.dbf  undotbs01.dbf

 

Thanks and Regards

相關文章
相關標籤/搜索