数据库异机冷备恢复

具体为以下几个步骤:
一:在新的机器安装系统,创建oralce用户及目录和赋相应的权限,配置目的机器的oracle安装路径跟原机器一致
二:关闭原数据库,拷贝数据库所有目录下的文件到另外一台机器的对应目录下
三:sqlplus /nolog startup启动数据库

###################OS Installing###################################
1:在linux5u2里安装虚拟机,在虚拟机里安装red hat 5u2 64bit操作系统
  [oracle@test-vm-5u2-64 ~]$ cat /proc/cpuinfo | grep processor
  processor       : 0
  processor       : 1
  [oracle@test-vm-5u2-64 ~]$ cat /proc/meminfo | awk -F: '/MemTotal/ {print $2/1024/1024}'
  4.83774
  [oracle@test-vm-5u2-64 ~]$ getconf LONG_BIT
  64
[oracle@test-vm-5u2-64 ~]$
2:安装完毕后挂5块盘,及格式化,mount,在/etc/rc.local中写入,具体步骤
  如下:
  建立目录:
  mkdir /oracle
  mkdir /oraredo
  mkdir /oraundo
  mkdir /oradataa
  mkdir /oradatab
  格式化分区:
  mkfs.ext3 /dev/sdb
  mkfs.ext3 /dev/sdc
  mkfs.ext3 /dev/sdd
  mkfs.ext3 /dev/sde
  mkfs.ext3 /dev/sdf
  挂载设备:
  mount /dev/sdb /oracle
  mount /dev/sdc /oraredo
  mount /dev/sdd /oradataa
  mount /dev/sde /oraundo
  mount /dev/sdf /oradatab

[oracle@test-vm-5u2-64 ~]$ vi /etc/rc.local
#!/bin/sh
#
# This script. will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style. init stuff.
touch /var/lock/subsys/local
mount /dev/sdb /oraredo
mount /dev/sdc /oraundo
mount /dev/sdd /oradataa
mount /dev/sde /oradatab
mount /dev/sdf /oracle
################OS Parameter Set######################################
echo 'set kernel parameter'
 echo "#   settings for ora10g"  >>  /etc/sysctl.conf
 echo "fs.file-max=327679"  >>  /etc/sysctl.conf
 echo "kernel.msgmni=2878"  >>  /etc/sysctl.conf
 echo "kernel.msgmax=8192"  >>  /etc/sysctl.conf
 echo "kernel.msgmnb=65536"  >>  /etc/sysctl.conf
 echo "kernel.sem=250 32000 100 142"  >>  /etc/sysctl.conf
 echo "kernel.shmmni=4096"  >>  /etc/sysctl.conf
 echo "kernel.shmall=3279547"  >>  /etc/sysctl.conf
 echo "#   set to a value half the size of physical memory"  >>  /etc/sysctl.conf
 echo "kernel.shmmax=2147483648"  >>  /etc/sysctl.conf
 echo "kernel.sysrq=1"  >>  /etc/sysctl.conf
 echo "#   rmem_max can be tuned based on workload to balance performance vs lowmem usage"  >>  /etc/sysctl.conf
 echo "net.core.rmem_default=262144"  >>  /etc/sysctl.conf
 echo "net.core.rmem_max=2097152"  >>  /etc/sysctl.conf
 echo "net.core.wmem_default=262144"  >>  /etc/sysctl.conf
 echo "net.core.wmem_max=262144"  >>  /etc/sysctl.conf
 echo "fs.aio-max-nr=3145728"  >>  /etc/sysctl.conf
 echo "vm.lower_zone_protection=100"  >>  /etc/sysctl.conf
 echo "net.ipv4.ip_local_port_range=1024 65000"  >>  /etc/sysctl.conf
 sysctl -p
  echo "    # depending on size of db, these may need to be larger" >>  /etc/security/limits.conf
 echo "oracle  soft    nofile  131072" >>  /etc/security/limits.conf
 echo "oracle  hard    nofile  131072" >>  /etc/security/limits.conf
 echo "oracle  soft    nproc   131072" >>  /etc/security/limits.conf
 echo "oracle  hard    nproc   131072" >>  /etc/security/limits.conf
 echo "oracle  soft    core    unlimited" >>  /etc/security/limits.conf
 echo "oracle  hard    core    unlimited" >>  /etc/security/limits.conf
 echo "    # set to allow oracle to use hugepages" >>  /etc/security/limits.conf
 echo "oracle  soft    memlock 50000000" >>  /etc/security/limits.conf
 echo "oracle  hard    memlock 50000000" >>  /etc/security/limits.conf
 
 echo 'set kernel parameter success!'
echo 'all the env setting success!'
###################OS裁剪##########################################
chkconfig --level 3 acpid off
chkconfig --level 3 anacron off
chkconfig --level 3 apmd off
chkconfig --level 3 canna off
chkconfig --level 3 mdmonitor off
chkconfig --level 3 openibd off
chkconfig --level 3 xinetd off
chkconfig --level 3 sendmail off
chkconfig --level 3 rpcgssd off
chkconfig --level 3 cups off
chkconfig --level 3 rawdevices off
chkconfig --level 3 messagebus off
chkconfig --level 3 atd off
chkconfig --level 3 arptables_jf off
chkconfig --level 3 iiim off
chkconfig --level 3 gpm off
chkconfig --level 3 autofs off
chkconfig --level 3 cpuspeed off
chkconfig --level 3 haldaemon off
chkconfig --level 3 nfslock off
chkconfig --level 3 portmap off
chkconfig --level 3 cups-config-daemon off
chkconfig --level 3 lm_sensors off
chkconfig --level 3 rhnsd off
chkconfig --level 3 xfs off
chkconfig --level 3 netfs off
chkconfig --level 3 iptables off
chkconfig --level 3 smartd off
chkconfig --level 3 ip6tables off
chkconfig --level 3 isdn off
chkconfig --level 3 rpcidmapd off
chkconfig --level 3 microcode_ctloff
chkconfig --level 3 microcode_ctl off
chkconfig --level 3 pcmcia off
chkconfig --level 3 hpoj off
chkconfig --level 3 network on
chkconfig --level 3 syslog on
chkconfig --level 3 sshd on
chkconfig --level 3 netfs on
chkconfig --level 3 sysstat on
chkconfig --level 3 irqbalance on
chkconfig --level 3 kudzu on
chkconfig --level 3 messagebus on
chkconfig --level 3 ntpd on
chkconfig --level 3 crond on

###################CP oracle files#################################
cd /oracle
scp oracle@192.168.0.123:/oracle/* .
cd /oraredo
scp oracle@192.168.0.123:/oraredo/* .
cd /oraundo
scp oracle@192.168.0.123:/oraundo/* .
cd /oradataa
scp oracle@192.168.0.123:/oradataa/* .
cd /oradatab
scp oracle@192.168.0.123:/oradatab/* .
###################Create User ADD Privs Setting###################
echo 'create oracle user and group'
        groupadd dba
        groupadd oinstall
        useradd -g oinstall -G dba oracle
        echo 'please set oracle default password:'
        passwd oracle
       
echo 'create oracle directory '
        chown oracle.oinstall /oracle
        chown -R oracle.oinstall /oracle/ora10
        chmod 755 /oracle
echo 'setting directory owner'
 chown -R oracle.oinstall /oracle
 chown -R oracle.oinstall /oradataa
 chown -R oracle.oinstall /oraredo
 chown -R oracle.oinstall /oraundo
 chown -R oracle.oinstall /oradatab
################Set OraEnv############################################
# oracle 10g
export ORACLE_BASE=/oracle/ora10
export ORACLE_HOME=/oracle/ora10/product
export PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_OWNER=oracle
export ORACLE_SID=ora10g
unset USERNAME
umask 022
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
#
# change this NLS settings to suit your country:
# example:
# german_germany.we8iso8859p15, american_america.we8iso8859p2 etc.
#export NLS_LANG='american_america.ZHS16GBK'
export NLS_LANG='american_america.AL32UTF8'
 
# User specific environment and startup programs
PATH=$PATH:/usr/sbin:/sbin
export PATH
[root@test-vm-5u2-64 ~]# su - oracle
[oracle@test-vm-5u2-64 ~]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.4.0 - Production on Tue Sep 11 18:02:53 2012
Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 1577058304 bytes
Fixed Size                  2084264 bytes
Variable Size             486539864 bytes
Database Buffers         1073741824 bytes
Redo Buffers               14692352 bytes
Database mounted.
ORA-01113: file 5 needs media recovery
ORA-01110: data file 5: '/oradatab/datab01.dbf'

SQL> recover datafile 5;
ORA-00283: recovery session canceled due to errors
ORA-00322: log 1 of thread 1 is not current copy
ORA-00312: online log 1 thread 1: '/oraredo/redo01b.red'
ORA-00322: log 1 of thread 1 is not current copy
ORA-00312: online log 1 thread 1: '/oraredo/redo01a.red'
查看alert日志
[oracle@test-vm-5u2-64 bdump]$ tail -f 100 alert_ora10g.log
tail: cannot open `100' for reading: No such file or directory
==> alert_ora10g.log <==
 parallel recovery started with 2 processes
Tue Sep 11 18:03:26 2012
Errors in file /oracle/ora10/admin/ora10g/udump/ora10g_ora_22889.trc:
ORA-00322: log 1 of thread 1 is not current copy
ORA-00312: online log 1 thread 1: '/oraredo/redo01b.red'
ORA-00322: log 1 of thread 1 is not current copy
ORA-00312: online log 1 thread 1: '/oraredo/redo01a.red'
Tue Sep 11 18:03:27 2012
Media Recovery failed with error 322
ORA-283 signalled during: ALTER DATABASE RECOVER  datafile 5  ...
SQL> desc v$logfile;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 GROUP#                                             NUMBER
 STATUS                                             VARCHAR2(7)
 TYPE                                               VARCHAR2(7)
 MEMBER                                             VARCHAR2(513)
 IS_RECOVERY_DEST_FILE                              VARCHAR2(3)
SQL> col member format a45
SQL> select * from v$logfile;
    GROUP# STATUS  TYPE    MEMBER                                        IS_
---------- ------- ------- --------------------------------------------- ---
         1         ONLINE  /oraredo/redo01a.red                          NO
         2         ONLINE  /oraredo/redo02a.red                          NO
         3         ONLINE  /oraredo/redo03a.red                          NO
         1         ONLINE  /oraredo/redo01b.red                          NO
         2         ONLINE  /oraredo/redo02b.red                          NO
         3         ONLINE  /oraredo/redo03b.red                          NO
6 rows selected.
SQL> set linesize 400
SQL> select * from v$log;
    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------
         1          1        251  209715200          2 NO  CURRENT                3236486 29-AUG-12
         3          1        250  209715200          2 YES INACTIVE               3136454 16-JUL-12
         2          1        249  209715200          2 YES INACTIVE               3072395 29-JUN-11
SQL> recover database until time '2012-09-09 00:00:00';
ORA-00283: recovery session canceled due to errors
ORA-00322: log 1 of thread 1 is not current copy
ORA-00312: online log 1 thread 1: '/oraredo/redo01b.red'
ORA-00322: log 1 of thread 1 is not current copy
ORA-00312: online log 1 thread 1: '/oraredo/redo01a.red'

SQL> recover database until cancel;
ORA-00279: change 3272052 generated at 09/07/2011 17:21:53 needed for thread 1
ORA-00289: suggestion : /oracle/ora10/oradata/ora10g/archive/1_251_771101551.dbf
ORA-00280: change 3272052 for thread 1 is in sequence #251

Specify log: {=suggested | filename | AUTO | CANCEL}
auto
ORA-00308: cannot open archived log '/oracle/ora10/oradata/ora10g/archive/1_251_771101551.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-00308: cannot open archived log '/oracle/ora10/oradata/ora10g/archive/1_251_771101551.dbf'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3

ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/oracle/ora10/oradata/ora10g/system01.dbf'

SQL> recover database until cancel;
ORA-00279: change 3272052 generated at 09/07/2011 17:21:53 needed for thread 1
ORA-00289: suggestion : /oracle/ora10/oradata/ora10g/archive/1_251_771101551.dbf
ORA-00280: change 3272052 for thread 1 is in sequence #251
查看归档日志,看看是否有1_251_771101551.dbf文件
[oracle@test-vm-5u2-64 archive]$ ll
total 407176
-rwxr-xr-x 1 oracle oinstall 205882880 Sep 11 16:39 1_249_771101551.dbf
-rwxr-xr-x 1 oracle oinstall 209581568 Sep 11 16:39 1_250_771101551.dbf
-rwxr-xr-x 1 oracle oinstall   1056768 Sep 11 16:39 block.dbf
[oracle@test-vm-5u2-64 archive]$
我们可以看到没有这个文件,这个文件明显比已归档的文件号大,据估计肯定在
redo重做日志里,所以在下面我们用重做日志恢复
Specify log: {=suggested | filename | AUTO | CANCEL}
/oraredo/redo01a.red 
--在这里输入重做日志文件,因为在上面我们已经查了redo01a.red是当前组文件
ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
ORA-01152: file 1 was not restored from a sufficiently old backup
ORA-01110: data file 1: '/oracle/ora10/oradata/ora10g/system01.dbf'

ORA-01112: media recovery not started
在这里我们看到,已经恢复成功!
SQL>  recover database until cancel;
Media recovery complete.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01589: must use RESETLOGS or NORESETLOGS option for database open
SQL> alter database open resetlogs;
Database altered.
SQL> select * from v$log;
    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------
         1          1          1  209715200          2 NO  CURRENT                3275931 11-SEP-12
         2          1          0  209715200          2 YES UNUSED                       0
         3          1          0  209715200          2 YES UNUSED                       0
SQL> alter system switch logfile;
System altered.
SQL> select * from v$log;
    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------
         1          1          1  209715200          2 YES ACTIVE                 3275931 11-SEP-12
         2          1          2  209715200          2 NO  CURRENT                3276388 11-SEP-12
         3          1          0  209715200          2 YES UNUSED                       0
SQL> alter system switch logfile;
System altered.
SQL> select * from v$log;
    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS ARC STATUS           FIRST_CHANGE# FIRST_TIME
---------- ---------- ---------- ---------- ---------- --- ---------------- ------------- ------------------
         1          1          1  209715200          2 YES ACTIVE                 3275931 11-SEP-12
         2          1          2  209715200          2 YES ACTIVE                 3276388 11-SEP-12
         3          1          3  209715200          2 NO  CURRENT                3276394 11-SEP-12
SQL>
[oracle@test-vm-5u2-64 archive]$ ll
total 524064
-rw-r----- 1 oracle oinstall    238080 Sep 11 18:26 1_1_793736516.dbf
-rwxr-xr-x 1 oracle oinstall 205882880 Sep 11 16:39 1_249_771101551.dbf
-rwxr-xr-x 1 oracle oinstall 209581568 Sep 11 16:39 1_250_771101551.dbf
-rw-r----- 1 oracle oinstall 119318528 Sep 11 18:21 1_251_771101551.dbf
-rw-r----- 1 oracle oinstall      1024 Sep 11 18:26 1_2_793736516.dbf
-rwxr-xr-x 1 oracle oinstall   1056768 Sep 11 16:39 block.dbf
[oracle@test-vm-5u2-64 archive]$
查看重做日志已经成功归档
至此,整个数据库就已经成功启动,下来开发人员就可以正常使用了
 
 

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/16400082/viewspace-743132/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/16400082/viewspace-743132/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值