使用RMAN備份與恢復數據庫(2)——參數文件的備份與恢復

使用RMAN備份與恢復數據庫(2)——參數文件的備份與恢復

Oracle有兩類參數文件:
(1)pfile:文本格式的參數文件,文件名通常爲init.ora;
(2)spfile:二進制格式的參數文件,不能直接修改,可以使用alter system修改,文件名通常爲spfile.ora,支持RMAN備份。

一、使用RMAN備份參數文件

1、備份參數文件

命令如下:

RMAN> backup spfile format '/home/oracle/rmanbak/spfileorcl.old';

Starting backup at 2020-04-09 14:52:14
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=9 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 2020-04-09 14:52:14
channel ORA_DISK_1: finished piece 1 at 2020-04-09 14:52:15
piece handle=/home/oracle/rmanbak/spfileorcl.old tag=TAG20200409T145214 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 2020-04-09 14:52:15

2、查看備份集

RMAN> list backup of spfile;

List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time    
------- ---- -- ---------- ----------- ------------ -------------------
37      Full    80.00K     DISK        00:00:00     2020-04-09 14:52:14
        BP Key: 66   Status: AVAILABLE  Compressed: NO  Tag: TAG20200409T145214
        Piece Name: /home/oracle/rmanbak/spfileorcl.old
  SPFILE Included: Modification time: 2020-04-09 13:56:52
  SPFILE db_unique_name: ORCL

二、恢復參數文件

1、連接scott用戶

創建t1表,並插入記錄:

SQL> show user;
USER is "SCOTT"

SQL> create table t1(id number(4),name varchar2(20));
Table created.
Elapsed: 00:00:00.33

SQL> insert into t1 values(1,'Jack');
1 row created.
Elapsed: 00:00:00.09

SQL> commit;
Commit complete.
Elapsed: 00:00:00.00

SQL> select * from t1;
	ID NAME
---------- --------------------
	 1 Jack
Elapsed: 00:00:00.01

2、刪除參數文件

(1)查看參數文件

SQL> show parameter spfile;

NAME	     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
spfile	     string	 /usr/local/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora

(2)刪除參數文件

SQL> ! rm /usr/local/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora

SQL> 

3、重啓數據庫

重新啓動數據庫提示無法打開參數文件:

SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/usr/local/oracle/product/11.2.0/db_1/dbs/initorcl.ora'

由於缺少參數文件,無法啓動實例,可以在RMAN中啓動一個僞實例到nomount,代碼如下:

RMAN> startup nomount;

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/usr/local/oracle/product/11.2.0/db_1/dbs/initorcl.ora'

starting Oracle instance without parameter file for retrieval of spfile
Oracle instance started

Total System Global Area     158662656 bytes

Fixed Size                     2211448 bytes
Variable Size                 92275080 bytes
Database Buffers              58720256 bytes
Redo Buffers                   5455872 bytes

查看實例信息如下:

SQL> connect / as sysdba
Connected.
SQL> show parameter name;

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert	     string
db_name 			         string	     DUMMY
db_unique_name			     string	     DUMMY
global_names			     boolean	 FALSE
instance_name			     string	     orcl
lock_name_space 		     string
log_file_name_convert		 string
service_names			     string	     DUMMY

4、使用RMAN還原參數文件

RMAN> restore spfile from '/home/oracle/rmanbak/spfileorcl.old';

Starting restore at 2020-04-09 15:47:47
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=10 device type=DISK

channel ORA_DISK_1: restoring spfile from AUTOBACKUP /home/oracle/rmanbak/spfileorcl.old
channel ORA_DISK_1: SPFILE restore from AUTOBACKUP complete
Finished restore at 2020-04-09 15:47:49

5、關閉RMAN中的實例

RMAN> shutdown immediate

Oracle instance shut down

6、啓動數據庫

SQL> connect / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area 1068937216 bytes
Fixed Size		    2220200 bytes
Variable Size		  482348888 bytes
Database Buffers	  578813952 bytes
Redo Buffers		    5554176 bytes
Database mounted.
Database opened.

7、查看數據是否丟失

刪除參數文件前的最後一個操作是往scott用戶的t1表中插入一條記錄,查看t1表中的數據如下:

SQL> select * from scott.t1;

	ID NAME
---------- --------------------
	 1 Jack

Elapsed: 00:00:00.05
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章