Oracle資料庫物理檔案備份/恢複

來源:互聯網
上載者:User

Oracle資料庫物理檔案備份/恢複

之前也寫過一篇類似的,雖然恢複Oracle資料庫物理檔案不成問題,但總感覺有不對的地方,後面才瞭解到,以前自己有存在誤區的地方,重新用此文方法簡便得多。

環境:CentOS release 5.6 (Final)
   Oracle Database Release 11.2.0.1.0

1、解壓壓縮好的資料庫檔案到相應目錄
[root@OATest oabak]# tar -jxvf testoa_20140702.tar.bz2

2、還原檔案
[root@OATest temp]# su - oracle
[oracle@OATest /]$ export ORACLE_SID=testoa
[oracle@OATest /]$ sqlplus "/as sysdba";

OPEN_MODE
--------------------
READ WRITE
3、關閉資料庫
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit

4、在sql模式下直接質資料庫物理檔案至相應的目錄(先顯示各類檔案的路徑所在,後拷貝到相應路徑)
--顯示控制檔案

select name from v$controlfile;
--顯示資料檔案
select name from v$datafile;
--顯示延續性的初始化參數檔案(延續性:對初始化參數的線上修改可以直接作用到參數檔案中)
show parameter spfile;
--顯示記錄檔
select member from v$logfile;
--orapw$ORACLE_SID密碼檔案:password file路徑 在$ORACLE_HOME/dbs/orapw$ORACLE_SID    //跟備份關係不大,可以隨時產生。

[oracle@OATest temp]$ sqlplus "/as sysdba";

host cp /usr/oabak/temp/control01.ctl /app/oracle/oradata/testoa/control01.ctl

host cp /usr/oabak/temp/control02.ctl /app/oracle/flash_recovery_area/testoa/control02.ctl
host cp /usr/oabak/temp/system01.dbf /app/oracle/oradata/testoa/system01.dbf
host cp /usr/oabak/temp/sysaux01.dbf /app/oracle/oradata/testoa/sysaux01.dbf
host cp /usr/oabak/temp/undotbs01.dbf /app/oracle/oradata/testoa/undotbs01.dbf
host cp /usr/oabak/temp/users01.dbf /app/oracle/oradata/testoa/users01.dbf
host cp /usr/oabak/temp/redo03.log /app/oracle/oradata/testoa/redo03.log
host cp /usr/oabak/temp/redo02.log /app/oracle/oradata/testoa/redo02.log
host cp /usr/oabak/temp/redo01.log /app/oracle/oradata/testoa/redo01.log
host cp /usr/oabak/temp/spfile${ORACLE_SID}.ora $ORACLE_HOME/dbs/
host cp /usr/oabak/temp/orapw${ORACLE_SID} $ORACLE_HOME/dbs/
--要刪除臨時檔案, 重啟的時候會自動建立temp01.dbf

若不刪除臨時檔案,會出現下面的報錯:
ORA-01187: cannot read from file  because it failed verification tests
ORA-01110: data file 201: '/app/oracle/oradata/testoa/temp01.dbf'
恢複檔案時候沒有刪除,舊的暫存資料表空間資料檔案(300MB),無法建立新的暫存資料表空間檔案(500MB) ..所以一直報錯

5、啟動資料庫
SQL> startup
ORACLE instance started.

Total System Global Area 4275781632 bytes
Fixed Size                  2220200 bytes
Variable Size            2113933144 bytes
Database Buffers        2147483648 bytes
Redo Buffers              12144640 bytes
Database mounted.
Database opened.
SQL> exit

6、修改使用者密碼
SQL> alter user oaadmin identified by oaadmin;
User altered.

7、解鎖帳戶
SQL> alter user oaadmin account unlock;
User altered.

上面第4步也可以利用一條命令直接處理:
select 'host cp /u03/backup/'||substr(name,(instr(name,'/',-1)+1))||
  ' '||name from v$controlfile
 union all
 select 'host cp /u03/backup/'||substr(name,(instr(name,'/',-1)+1))||
  ' '||name from v$controlfile
 union all
 select 'host cp /u03/backup/'||substr(member,(instr(member,'/',-1)+1))
  ||' '||member from v$logfile
 union all
 select 'host cp /u03/backup/spfile${ORACLE_SID}.ora $ORACLE_HOME/dbs/'
  from dual
 union all
 select 'host cp /u03/backup/orapw${ORACLE_SID} $ORACLE_HOME/dbs/'
  from dual;

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.