【Rman全备迁移恢复11G r1数据库详情】

 【Rman全备迁移恢复11G r1数据库详情】

 

1.环境

生产环境:Redhat Linux 5.4 64位+Oracle 11G R1

恢复环境:Redhat Linux 5.4 64位+Oracle 11G R1【因为试验过恢复到11G R2 ,尽是问                           题,从低版本恢复到高版本,之后要升级数据库版本才能解决的,如果是高                     版本,或许还要降恢复后的数据文件头版本号,麻烦!!】

                    所以还是建议做Rman的,都在相同版本迁移恢复,比较容易解决问题;

 

 

适合场合:恢复的目录一致,同时备份的过程中有归档日志

恢复的数据库目录和备份机的数据库一致,还有一个就是RMAN备份的时候已经备份了归档日志。【目录最好一致,如果条件限制,可以做个文件夹软连接,使目录一致】

备份脚本:

run{

allocate channel c1 type disk;

allocate channel c2 type disk;

sql ‘alter system archive log current’;

backup as compressed backupset database format ‘/mnt/backup/full_%T_%U’;

sql ‘alter system archive log current’;

backup as compressed backupset archivelog all format ‘/mnt/backup/arc_%T_%U’;

backup current controlfile format ‘/mnt/backup/cf_%T_%U’;

backup spfile format ‘/mnt/backup/sp_%T_%U’;

release channel c1;

release channel c2;

}

 

2,备份库安装数据库,不要建库,设置好相应环境变量

 

su – oracle

vim ~/.bash_profile

export ORACLE_BASE=/opt/app/oracle

export ORACLE_HOME=/opt/app/oracle/11g/db_1

export ORACLE_SID=orcl    --这个一定要对应

export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin

unset USERNAME

生效:source ~/.bash_profile

 

3,拷贝备份和归档到恢复机器对应的路径下,最好对应备份目录,不然可以软连接解决目录问题

 

4,迁移恢复过程

1) rman target / 

2)set dbid=12665668;【dbid 可以由源库查询到】

3)startup nomount; 之后会报错,因为木有spfile;

RMAN> restore spfile from '/mnt/backup/sp_20110810_05lo1lg0_1_1';

Starting restore at 10-AUG-11

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=36 devtype=DISK

channel ORA_DISK_1: autobackup found: /mnt/backup/sp_20110810_05lo1lg0_1_1

channel ORA_DISK_1: SPFILE restore from autobackup complete

Finished restore at 10-AUG-10


4)恢复控制文件

RMAN> shutdown immediate;

Oracle instance shut down

RMAN> startup nomount;

connected to target database (not started)

Oracle instance started

Total System Global Area     167772160 bytes

Fixed Size                     1266392 bytes

Variable Size                 62917928 bytes

Database Buffers             100663296 bytes

Redo Buffers                   2924544 bytes

RMAN> restore controlfile from '/mnt/backup/cf_201108106_07lo1lg8_1_1';

Starting restore at 10-AUG-11

allocated channel: ORA_DISK_1

channel ORA_DISK_1: sid=101 devtype=DISK

channel ORA_DISK_1: restoring control file

channel ORA_DISK_1: restore complete, elapsed time: 00:00:02

output filename=/opt/oracle/oradata/orcl/control01.ctl

output filename=/opt/oracle/oradata/orcl/control02.ctl

output filename=/opt/oracle/oradata/orcl/control03.ctl

Finished restore at 10-AUG-11

5)将数据启动到mount状态

RMAN> alter database mount;

database mounted

released channel: ORA_DISK_1

6)恢复数据库

后面出现的错误是指个别日志不同步,所以最好就是把归档一起拷贝全

RMAN> restore database;

在一次恢复时,报错了如下:

 

channel c1: restore complete, elapsed time: 06:01:33

channel c2: ORA-19870: ?????? /mybak/full_db_ndmkqhpj_1_1_20110824 ???

ORA-19502: ?? "/opt/oradata/orcl/orcl/undotbs02.dbf", ??? 1522561 (???=8192) ???????

ORA-27072: ?? I/O ??

Linux-x86_64 Error: 2: No such file or directory

Additional information: 4

Additional information: 1522561

Additional information: 73728

failover to previous backup

 

事实是系统磁盘不足了,可以利用set newname 命令,直接恢复未恢复的数据文件哦!。

后来重新恢复,就全部数据文件都用了set newname 命令转移恢复的数据文件位置

命令如下:

run{

allocate channel c1 type disk;

allocate channel c2 type disk;

set newname for datafile '/opt/oradata/orcl/orcl/system01.dbf' to '/mnt/oradata/orcl/system01.dbf';

set newname for datafile '/opt/oradata/orcl/orcl/sysaux01.dbf' to '/mnt/oradata/orcl/sysaux01.dbf';

………………【其他文件这里省略了,要对应好各个数据文件的原始路径哦】

restore database;

switch datafile all;【因为set newname了,要转换下数据文件位置】

release channel c1;

release channel c2;

}

 

RMAN>recover database;【报错了,正常的,数据库不知道恢复到哪个scn啥的】

可以如下操作:

RMAN>list backup;【查看备份集里面最大的SCN号,然后恢复】

RMAN>recover database until scn 12006846;

还可以不完整恢复:【当报如下的错误时】

 

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of recover command at 08/28/2011 09:18:18

RMAN-06556: datafile 1 must be restored from backup older than SCN 7355241936

可以直接 alter database open resetlogs命令打开数据库。

 

RMAN> alter database open resetlogs;

database opened

 

 

恢复完成,可以打开了

 

7)以resetlogs打开数据库

RMAN>alter database open resetlogs;

 

8)之后可以根据情况重建temp表空间;【11G数据库,temp空间会在 如上命令执行时,在默认数据库目录生产个新的tmp数据文件的】

 

RMAN备份迁移数据库 异地恢复总结:

1.做好全备脚本,最好备份过程日志也要加上,方便恢复时查看相关参数等;

2.一定要备份归档,备份前,可以做个日志切换,如果当时没备份,可以复制归档到备份机;

3.rman迁移恢复,还是同版本比较好顺利迁移解决;

 

【如有错误,请指正,谢谢】

 =======================================================================

有次恢复后,打开数据库时,出现如下错误,还为解决,后来是重新找个磁盘够的机器,重新恢复的,如下错误问题还未解决…………【有高手请指教下小弟】

 

SQL> alter database open resetlogs;

alter database open resetlogs

*

ERROR at line 1:

ORA-01092: ORACLE instance terminated. Disconnection forced

?? ID: 2237

?? ID: 555 ???: 5

 

 

你可能感兴趣的:(职场,oracle11g,休闲,异地恢复,rman备份迁移)