恢復處于NOARCHIVELOG模式的資料庫
當資料庫處于NOARCHIVELOG模式時,如果出現介質故障 ,則最后一次備份之后對資料庫所做的任何操作都將丟失,通過RMAN執行恢復時,只需要執行restore命令將資料庫檔案修復到正確的位置,然后就可以打開資料庫,也就是說,對于處于NOARCHIVELOG模式下的資料庫,管理員不需要執行recover命令,
1.Sys登陸,并確認資料庫屬于NOARCHIVELOG模式
SQL> select log_mode from v$database;
LOG_MODE
------------
ARCHIVELOG
SQL>
SQL>
SQL>
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 2755870720 bytes
Fixed Size 2256432 bytes
Variable Size 671089104 bytes
Database Buffers 2063597568 bytes
Redo Buffers 18927616 bytes
Database mounted.
2.更改資料庫為noarchivelog狀態
SQL> alter database noarchivelog;
alter database noarchivelog
*
ERROR at line 1:
ORA-38774: cannot disable media recovery - flashback database is enabled
SQL> alter database flashback off;
Database altered.
SQL> alter database noarchivelog;
Database altered.
SQL> archive log list;

3.執行一下命令,備份整個資料庫
RMAN> run{
2> allocate channel ch_1 type disk;
3> backup database
4> format '/u01/app/oracle/oradata/Backup/orcl_%t_%u.bak';
5> }

4.可以查看一下備份下來的檔案,上邊有路徑,資料檔案和控制檔案

5.模擬users.dbf丟失,這里可以先查找資料檔案的位置
SQL> select file_name,tablespace_name,bytes from dba_data_files;

[oracle@orcl Backup]$ cd /u01/app/oracle/oradata/orcl

[oracle@orcl orcl]$ rm users01.dbf

6.洗掉的時候資料庫必須是關閉的,不然系統禁止洗掉正在使用的資料檔案,現在到起庫測驗一下,提示找不到資料檔案
RMAN> startup
database is already started
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of startup command at 12/04/2019 03:39:53
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
RMAN> run{
7.startup mount狀態才能訪問資料檔案,就可以執行restore
RMAN> run{
2> allocate channel ch_1 type disk;
3> restore database;
4> }

這時候看一下資料檔案是可以恢復到目錄下的

8.起庫看一下是可以起來的
RMAN> startup
database is already started
database opened
處于ARCHIVE模式
恢復處于archivelog模式的資料庫
1.查看資料庫是否處于歸檔
SQL> archive log list;

2.啟動rman對目標表空間進行備份,然后模擬洗掉
[oracle@orcl Backup]$ ramn target /
RMAN> run{
2> allocate channel ch_1 type disk;
3> allocate channel ch_2 type disk;
4> backup tablespace users
5> format '/u01/app/oracle/oradata/Backup/users_tablespace.bak';
6> }

3.關閉資料庫,然后模擬洗掉掉users.dbf,users.dbf的路徑怎么找上邊寫的有命令

RMAN> shutdown immediate
database closed
database dismounted
Oracle instance shut down
RMAN> startup mount
RMAN> alter database open;
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of alter db command at 12/04/2019 05:20:32
ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
ORA-01110: data file 4: '/u01/app/oracle/oradata/orcl/users01.dbf'
4.資料庫現在mount狀態,恢復表空間
RMAN> run{
2> allocate channel ch_1 type disk;
3> restore tablespace users;
4> recover tablespace users;
5> }

5.更改成open狀態是沒有問題的,users的資料檔案還是在的

RMAN> alter database open;
database opened
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/25081.html
標籤:Oracle
上一篇:RMAN備份資料庫與表空間
下一篇:Linux7 64安裝 oracle 11g Error in invoking target 'agent nmhs' of makefile
