700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 使用RMAN备份与恢复数据库(2)——参数文件的备份与恢复

使用RMAN备份与恢复数据库(2)——参数文件的备份与恢复

时间:2022-12-22 21:04:49

相关推荐

使用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 -04-09 14:52:14allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=9 device type=DISKchannel ORA_DISK_1: starting full datafile backup setchannel ORA_DISK_1: specifying datafile(s) in backup setincluding current SPFILE in backup setchannel ORA_DISK_1: starting piece 1 at -04-09 14:52:14channel ORA_DISK_1: finished piece 1 at -04-09 14:52:15piece handle=/home/oracle/rmanbak/spfileorcl.old tag=TAGT145214 comment=NONEchannel ORA_DISK_1: backup set complete, elapsed time: 00:00:01Finished backup at -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 ------- ---- -- ---------- ----------- ------------ -------------------37Full 80.00KDISK 00:00:00-04-09 14:52:14BP Key: 66 Status: AVAILABLE Compressed: NO Tag: TAGT145214Piece Name: /home/oracle/rmanbak/spfileorcl.oldSPFILE Included: Modification time: -04-09 13:56:52SPFILE 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.33SQL> insert into t1 values(1,'Jack');1 row created.Elapsed: 00:00:00.09SQL> commit;Commit complete.Elapsed: 00:00:00.00SQL> select * from t1;ID NAME---------- --------------------1 JackElapsed: 00:00:00.01

2、删除参数文件

(1)查看参数文件

SQL> show parameter spfile;NAMETYPE VALUE------------------------------------ ----------- ------------------------------spfilestring /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.oraSQL>

3、重启数据库

重新启动数据库提示无法打开参数文件:

SQL> startupORA-01078: failure in processing system parametersLRM-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 parametersLRM-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 spfileOracle instance startedTotal System Global Area158662656 bytesFixed Size 2211448 bytesVariable Size 92275080 bytesDatabase Buffers 58720256 bytesRedo Buffers 5455872 bytes

查看实例信息如下:

SQL> connect / as sysdbaConnected.SQL> show parameter name;NAMETYPE VALUE------------------------------------ ----------- ------------------------------db_file_name_convertstringdb_namestringDUMMYdb_unique_namestringDUMMYglobal_namesboolean FALSEinstance_namestringorcllock_name_spacestringlog_file_name_convert stringservice_namesstringDUMMY

4、使用RMAN还原参数文件

RMAN> restore spfile from '/home/oracle/rmanbak/spfileorcl.old';Starting restore at -04-09 15:47:47using target database control file instead of recovery catalogallocated channel: ORA_DISK_1channel ORA_DISK_1: SID=10 device type=DISKchannel ORA_DISK_1: restoring spfile from AUTOBACKUP /home/oracle/rmanbak/spfileorcl.oldchannel ORA_DISK_1: SPFILE restore from AUTOBACKUP completeFinished restore at -04-09 15:47:49

5、关闭RMAN中的实例

RMAN> shutdown immediateOracle instance shut down

6、启动数据库

SQL> connect / as sysdbaConnected to an idle instance.SQL> startupORACLE instance started.Total System Global Area 1068937216 bytesFixed Size 220 bytesVariable Size 482348888 bytesDatabase Buffers 578813952 bytesRedo Buffers 5554176 bytesDatabase mounted.Database opened.

7、查看数据是否丢失

删除参数文件前的最后一个操作是往scott用户的t1表中插入一条记录,查看t1表中的数据如下:

SQL> select * from scott.t1;ID NAME---------- --------------------1 JackElapsed: 00:00:00.05

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。