1. 程式人生 > >Oracle數據庫冷備份與熱備份操作梳理

Oracle數據庫冷備份與熱備份操作梳理

冷備 sql strong 10.2.0.1 redo 相關 16px acl member

Oracle數據庫的備份方式有冷備份和熱備份兩種,針對這兩種備份的實施過程記錄如下:

一、Oracle冷備份
概念
數據庫在關閉狀態下完成所有物理系統文件拷貝的過程,也稱脫機備份
適合於非歸檔模式(noarchivelog)下,數據庫處於一致性狀態

步驟

  • 首先在運行的庫中得到數據庫運行的所有的物理文件位置,然後在計劃內關閉數據庫(shutdown)
  • 再執行拷貝物理文家到備份路徑或備份設備
  • 備份完成後立即啟動數據庫讓其提供正常的服務

冷備腳本的寫法
首先應該在相關視圖裏查出數據庫的數據文件,日誌文件,控制文件,臨時文件所在的位置
註意:不要直接在oradata下進行cp就行了,因為生產庫裏各個文件通常分布在不同的磁盤,不同的地方,所以在去視圖裏獲得真實路徑

冷備份操作

1)查看Oracle數據庫的日誌模式,如果是歸檔模式,將需要將數據庫設置為noarchivelog模式(非歸檔模式),從而進行冷備份。

SQL> archive log list  
Database log mode              No Archive Mode  
Automatic archival             Enabled                     //Enabled表示為歸檔模式
Archive destination            /u01/admin/denver/archdest  
Oldest online log sequence     1  
Current log sequence           1 

SQL> startup mount  
ORACLE instance started.  
Total System Global Area  422670336 bytes  
Fixed Size                  1336960 bytes  
Variable Size             314575232 bytes  
Database Buffers          100663296 bytes  
Redo Buffers                6094848 bytes  
Database mounted.  

SQL>  alter database noarchivelog  
Database altered.  

SQL> archive log list  
Database log mode              No Archive Mode  
Automatic archival             Disabled                   //Disabled表示為歸檔模式
Archive destination            /u01/admin/denver/archdest  
Oldest online log sequence     1  
Current log sequence           1  

SQL> alter database open;  
Database altered.  

2)查看實例和數據庫的相關信息

SQL> select instance_name,version,status,archiver,database_status from v$instance;
 
    INSTANCE_NAME    VERSION           STATUS       ARCHIVE DATABASE_STATUS
    ---------------- ----------------- ------------ ------- -----------------
    orcl             10.2.0.1.0        OPEN         STOPPED ACTIVE
 
SQL> select dbid,name,log_mode from v$database;
 
    DBID NAME      LOG_MODE
    ---------- --------- ------------
    1242732291 ORCL      NOARCHIVELOG

3)查看數據文件及狀態信息

SQL> select file_name,tablespace_name,status,online_status from dba_data_files;
 
    FILE_NAME                                               TABLESPACE STATUS    ONLINE_
    ------------------------------------------------------- ---------- --------- -------
    /u01/app/oracle/oradata/orcl/undotbs01.dbf              UNDOTBS1   AVAILABLE ONLINE
    /u01/app/oracle/oradata/orcl/system01.dbf               SYSTEM     AVAILABLE SYSTEM
    /u01/app/oracle/oradata/orcl/sysaux01.dbf               SYSAUX     AVAILABLE ONLINE
    /u01/app/oracle/oradata/orcl/users01.dbf                USERS      AVAILABLE ONLINE
    /u01/app/oracle/oradata/orcl/example01.dbf              EXAMPLE    AVAILABLE ONLINE
    /u01/app/oracle/oradata/orcl/tbs1_1.dbf                 TBS1       AVAILABLE ONLINE
    /u01/app/oracle/oradata/orcl/tbs1_2.dbf                 TBS1       AVAILABLE ONLINE

4)查看數據文件

SQL> select name from v$datafile;
 
    NAME
    --------------------------------------------------------------------------------
    /u01/app/oracle/oradata/orcl/system01.dbf
    /u01/app/oracle/oradata/orcl/undotbs01.dbf
    /u01/app/oracle/oradata/orcl/sysaux01.dbf
    /u01/app/oracle/oradata/orcl/users01.dbf
    /u01/app/oracle/oradata/orcl/example01.dbf
    /u01/app/oracle/oradata/orcl/tbs1_1.dbf
    /u01/app/oracle/oradata/orcl/tbs1_2.dbf

5)查看臨時文件

SQL> select name from v$tempfile;
 
    NAME
    --------------------------------------------------------------------------------
    /u01/app/oracle/oradata/orcl/temp01.dbf

6)查看日誌文件

SQL> select member from v$logfile;
 
    MEMBER
    ------------------------------------------------------------
    /u01/app/oracle/oradata/orcl/redo2a.rdo
    /u01/app/oracle/oradata/orcl/redo2b.rdo
    /u01/app/oracle/oradata/orcl/redo1a.rdo
    /u01/app/oracle/oradata/orcl/redo3a.rdo
    /u01/app/oracle/oradata/orcl/redo3b.rdo
    /u01/app/oracle/oradata/orcl/redo1b.rdo

7)查看控制文件

SQL> select name from v$controlfile;
 
    NAME
    ------------------------------------------------------------
    /u01/app/oracle/oradata/orcl/control01.ctl
    /u01/app/oracle/oradata/orcl/control02.ctl

8)創建備份目錄

SQL> ho mkdir /u01/app/oracle/coolbak

9)使用連接符生成復制文件命令

SQL> select ‘ho cp ‘ || name || ‘ /u01/app/oracle/coolbak‘ from v$controlfile;
 
    ‘HOCP‘||NAME||‘/U01/APP/ORACLE/COOLBAK‘
    ----------------------------------------------------------------------------------
    ho cp /u01/app/oracle/oradata/orcl/control01.ctl /u01/app/oracle/coolbak
    ho cp /u01/app/oracle/oradata/orcl/control02.ctl /u01/app/oracle/coolbak

將上面的輸入保存為tmpbak.sql

SQL> save /tmp/tmpbak.sql;   
Created file /tmp/tmpbak.sql

Oracle數據庫冷備份與熱備份操作梳理