rman异机恢复,全部恢复和增量恢复

 

1.首先准备工作:
hostname
192.168.222.11 ol7.localdomain ol7
建立相关目录:
mkdir -p /u01/app/oracle/oradata/DB11G/
mkdir -p /oracle/redo1/
mkdir -p /u01/app/oracle/product/11.2.0.4/db_1/dbs/
mkdir -p /oracletemp/DB11G/archive_log/
mkdir -p /oraclearch/archive_log/
mkdir -p /oraclearch/flash_recovery_area/DB11G/
mkdir -p /u01/app/oracle/oradata/DB11G/
mkdir -p /oracledata/nc/ncindex/
mkdir -p /u01/app/oracle/oradata/DB11G/
mkdir -p /oracledata/nc/nctables/
mkdir -p /oracledata/DB11G/
mkdir -p /u01/app/oracle/oradata/DB11G/
mkdir -p /u01/app/oracle/admin/DB11G/{adump,dpdump,pfile}
chown -R oracle:oinstall /u01
chmod -R 775 /u01
chown -R oracle:oinstall /oracle/redo1/
chmod -R 775 /oracle/redo1/
chown -R oracle:oinstall /oracletemp/DB11G/archive_log/
chmod -R 775 /oracletemp/DB11G/archive_log/
chown -R oracle:oinstall /oraclearch/archive_log/
chmod -R 775 /oraclearch/archive_log/
chown -R oracle:oinstall /oracledata/nc/ncindex/
chmod -R 775 /oracledata/nc/ncindex/
mkdir /oracledata/nc_ma/nc_ma_tables/ -p
chown oracle:oinstall -R /oracledata/nc_ma/nc_ma_tables/
更新yum update
执行脚本:
[root@ol7 ~]# cat dbinstall.sh
#!/bin/bash
IP=`ip addr |grep 'inet'|grep 'brd'|awk '{print $2}'|awk -F / '{print $1}'`
echo $IP ol7.localdomain ol7 >> /etc/hosts
hostnamectl set-hostname ol7.localdomain
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
setenforce 0
yum -y install oracle-rdbms-*
yum -y install rlwrap
mkdir -p /u01/app/oracle/product/11.2.0.4/db_1
chown -R oracle:oinstall /u01
chmod -R 775 /u01
systemctl stop firewalld
systemctl disable firewalld
cat >>/home/oracle/.bash_profile<<EOF
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
ORACLE_HOSTNAME=ol7.localdomain; export ORACLE_HOSTNAME
ORACLE_UNQNAME=DB11G; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=\$ORACLE_BASE/product/11.2.0.4/db_1; export ORACLE_HOME
ORACLE_SID=DB11G; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:\$PATH; export PATH
PATH=\$ORACLE_HOME/bin:\$PATH; export PATH

LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib; export CLASSPATH

alias sql='rlwrap sqlplus'
alias sqlplus='rlwrap sqlplus'
alias lsnrctl='rlwrap lsnrctl'
alias rman='rlwrap rman'

alias envo='env | grep ORACLE'
alias cdob='cd \$ORACLE_BASE'
alias cdoh='cd \$ORACLE_HOME'
alias tns='cd \$ORACLE_HOME/network/admin'

EOF
再次执行脚本:
[root@ol7 ~]# cat iso.sh
#!/bin/bash
yum install createrepo -y
yum install unzip -y
yum install gcc* -y
yum install xhost -y
yum -y install elfutils*
[root@ol7 ~]#
解压:
/u01/app/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0.4/db_1/root.sh
二:在目的服务器上复制备份数据,并准备好相关的目录
[oracle@orcl ~]$ mkdir /u01/backup
[oracle@orcl ~]$ scp -rp 192.168.227.20:/u01/backup/* /u01/backup/
oracle@192.168.227.20's password:
control20110906.bak 100% 6944KB 1.7MB/s 00:04
db_full_0fmlsmdt_1_1.bkp 100% 97MB 4.4MB/s 00:22
db_full_0gmlsme5_1_1.bkp 100% 593MB 9.1MB/s 01:05
db_full_0hmlsmg7_1_1.bkp 100% 6656 6.5KB/s 00:00
spfile20110906.bak 100% 96KB 96.0KB/s 00:00

[oracle@orcl ~]$ mkdir -p /u01/app/oracle/admin/orcl/{adump,bdump,cdump,dpdump,udump,pfile}
[oracle@orcl ~]$ mkdir -p /u01/app/oracle/oradata/orcl
[oracle@orcl ~]$ mkdir -p /u01/app/oracle/flash_recover_area/ORCL
三:在目的服务器上进行恢复
[oracle@orcl ~]$ echo 'db_name=orcl' > $ORACLE_HOME/dbs/initorcl.ora
[oracle@orcl ~]$ export ORACLE_SID=orcl
[oracle@orcl ~]$ rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Tue Sep 6 16:18:19 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
connected to target database (not started)

RMAN> set dbid 1287906064; //指定DBID,需要和源服务器的DBID一致
RMAN> startup nomount; //启动数据库到nomount状态,这里需要前面创建initorcl.ora文件,否则将报错
RMAN> restore spfile from '/u01/backup/spfile20110906.bak'; //恢复参数文件
RMAN> startup nomount force; //重启实例到nomout状态
RMAN> restore controlfile from '/u01/backup/control20110906.bak'; //恢复控制文件
RMAN> restore database; //还原数据库文件 (记得注册目录)
RMAN> recover database; //恢复数据库文件,这里将报错
RMAN-03002: failure of recover command at 09/06/2011 17:03:51
RMAN-06054: media recovery requesting unknown log: thread 1 seq 15 lowscn 547974
RMAN> exit

[oracle@orcl ~]$ sqlplus /nolog //在sqlplus中对数据库进行until cancel操作后以resetlogs方式打开
SQL*Plus: Release 10.2.0.1.0 - Production on Tue Sep 6 17:04:22 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.

SQL> conn /as sysdba
Connected.
SQL> recover database using backup controlfile until cancel;
ORA-00279: change 547974 generated at 09/06/2011 16:49:11 needed for thread 1
ORA-00289: suggestion :
/u01/app/oracle/flash_recovery_area/ORCL/archivelog/2011_09_06/o1_mf_1_15_%u_.ar
c
ORA-00280: change 547974 for thread 1 is in sequence #15


Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.
SQL> alter database open resetlogs;
四:测试
SQL> select member from v$logfile;

MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/redo03.log
/u01/app/oracle/oradata/orcl/redo02.log
/u01/app/oracle/oradata/orcl/redo01.log

SQL> select file_name from dba_data_files;

FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/example01.dbf
/u01/app/oracle/oradata/orcl/tbs_apple01.dbf
6 rows selected.


SQL> select count(*) from dba_temp_files;
COUNT(*)
----------
1

SQL> select count(*) from hr.employees;

COUNT(*)
----------
107
五:注意事项
RMAN> list incarnation; //生成一个新的incarnation
using target database control file instead of recovery catalog

List of Database Incarnations
DB Key Inc Key DB Name DB ID STATUS Reset SCN Reset Time
------- ------- -------- ---------------- --- ---------- ----------
1 1 ORCL 1287906064 PARENT 1 2005-06-30:19:09:40
2 2 ORCL 1287906064 PARENT 446075 2011-08-25:17:55:31
3 3 ORCL 1287906064 CURRENT 547975 2011-09-06:17:07:09

[oracle@orcl ~]$ emctl start dbconsole //dbconsole需要重新配置,orapwd文件也需要创建
TZ set to PRC
首先:
/u01/app/oracle/product/11.2.0.4/db_1/dbs
orapwd file='/u01/app/oracle/product/11.2.0.4/db_1/dbs/orapwDB11G' password=oracle entries=5 force=y;
OC4J Configuration issue. /u01/app/oracle/product/10.2.0/db_1/oc4j/j2ee/OC4J_DBConsole_orcl.herostart.com_orcl not found
然后:
你按着这个顺序来试试,不行的话我也不会了

1、设置好监听器,用lsnrctl start启动,然后用lsnrctl statu观察一下是否成功
2、emca -deconfig dbcontrol db 删除dbcontrol
3、emca -repos drop删除EM资料库
4、emca -repos create创建资料库
5、emca -config dbcontrol db重新配置dbcontrol

如果能顺利做下来就应该没问题了

 

ok!!!!!

六:增量备份的异机恢复
1:源服务器
SQL> create user rman_inr identified by "123456" default tablespace users;
User created.
SQL> grant connect,resource to rman_inr;
Grant succeeded.
SQL> create table rman_inr.test as select * from dba_source;
Table created.

RMAN> backup incremental level 1
2> format '/u01/backup/inr1_db_%U' tag 'inr_1'
3> database plus archivelog;

[oracle@orcl ~]$ rman target /
RMAN> backup incremental level 1
2> format '/u01/backup/inr1_db_%U' tag 'inr_1'
3> database plus archivelog;

RMAN> backup current controlfile format '/u01/backup/control02.bak';

[oracle@orcl ~]$ ls -lh /u01/backup/inr1_db_1*
-rw-r----- 1 oracle oinstall 53M Sep 8 16:34 /u01/backup/inr1_db_1omm1ud0_1_1
-rw-r----- 1 oracle oinstall 51M Sep 8 16:35 /u01/backup/inr1_db_1pmm1udk_1_1
-rw-r----- 1 oracle oinstall 6.9M Sep 8 16:35 /u01/backup/inr1_db_1qmm1uf2_1_1
-rw-r----- 1 oracle oinstall 11K Sep 8 16:35 /u01/backup/inr1_db_1rmm1uf5_1_1

[oracle@orcl ~]$ scp /u01/backup/inr1_db_1* 192.168.227.30:/u01/backup/
[oracle@orcl ~]$ scp /u01/backup/control02.bak 192.168.227.30:/u01/backup/
2:目标服务器
[oracle@orcl ~]$ sqlplus /nolog
SQL> conn /as sysdba
Connected.
SQL> shutdown immediate;

RMAN> set dbid=1287906064;
RMAN> startup nomount;
RMAN> restore controlfile from '/u01/backup/control02.bak';
RMAN> startup mount force;

RMAN> restore database;
RMAN> recover database;
RMAN-03002: failure of recover command at 09/08/2011 16:46:44
RMAN-06054: media recovery requesting unknown log: thread 1 seq 45 lowscn 598452
RMAN> exit

[oracle@orcl ~]$ sqlplus /nolog
SQL> conn /as sysdba

SQL> recover database using backup controlfile until cancel;
ORA-00279: change 598452 generated at 09/08/2011 16:35:49 needed for thread 1
ORA-00289: suggestion : /u01/arch/orcl/1_45_760125331.arc
ORA-00280: change 598452 for thread 1 is in sequence #45

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
cancel
Media recovery cancelled.

SQL> alter database open resetlogs;
Database altered.
3:测试
SQL> conn rman_inr/123456
Connected

SQL> select count(*) from test;

COUNT(*)
----------
292428

posted on 2017-07-18 13:30  Jt00  阅读(1833)  评论(0编辑  收藏  举报

导航