2015年11月24日 星期二

RMAN Restore

--Install Oracle10g on Enterprise Linux 5.5
(1).套裝軟體安裝
Desktop Environments -> 勾選 KDE
Development -> Development Libraries -> 按下[Optional Packages]
                 勾選 libstdc++44devel-4.4.0-6.el5.I386
                  -> Development Tools -> 按下[Optional Packages]
                 勾選 gcc44-4.4.0-6.el5.x86_64
                       gcc44-c++-4.4.0-6.el5.x86_64
                  -> 勾選Java Development
                  -> 勾選KDE Software Development
                  -> 勾選Legacy Software Development -> 按下[Optional Packages]
                 勾選 gtk+-1.2.10-56.el5.x86_64
                  -> 勾選 Ruby
                  -> X Software Development -> 按下[Optional Packages]
                 勾選 openmotif-devel-2.3.1-2.el5.x86_64
                       xorg-x11-server-sdk-1.1.1-48.52.0.1.el5.x86_64
                       xorg-x11.xbitmaps-1.0.1-4.1.x86_64
Servers -> 勾選 FTP Server
           -> 勾選 Legacy Network Server -> 按下[Optional Packages]
             勾選 telnet-server-0.17-39.el5.x86_64
           -> 勾選 Mail Server
           -> 勾選 Network Server
           -> 勾選 Printing Supports
           -> 勾選 Server Configuration Tools
           -> 勾選 Windows FIle Server
Base System -> Legacy Software Support -> 按下[Optional Packages]
                 勾選 compat-db-4.2.52-5.1.i386
                       openmotif22-2.2.3-18.I386
                       qt4-4.2.1-1.x86_64
                  -> System Tools -> 按下[Optional Packages]
                 勾選 Click gnutls-utils-1.4.1-3.el5_2.1.x86_64
                       sysstat-7.0.2-3.el5.x86_64

(2).硬體環境檢查
記憶體需求:
最少記憶體1GB
空間需求:
1.5GB~2GB swap
400MB的/tmp空間
1.5GB的oracle軟體安裝空間
2GB的flash recovery area空間

oracle install before,check Linux package。use rpm -q check:
rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel libXp

yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel libXp

========================================================================
--install oracle 10g
You should now have a single directory containing installation files. Depending on the age of the download this may either be named "db/Disk1" or "database".

Hosts File

The "/etc/hosts" file must contain a fully qualified name for the server.

   
For example.

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.        localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
10.1.1.58       test


Set Kernel Parameters

Add the following lines to the "/etc/sysctl.conf" file.

#kernel.shmall = 2097152
#kernel.shmmax = 2147483648
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
kernel.sem = 250 32000 100 128
fs.file-max = 101365
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=1048576
net.core.rmem_max=1048576
net.core.wmem_default=262144
net.core.wmem_max=262144


Run the following command to change the current kernel parameters.

/sbin/sysctl -p

Add the following lines to the "/etc/security/limits.conf" file.

*               soft    nproc   2047
*               hard    nproc   16384
*               soft    nofile  1024
*               hard    nofile  65536

Add the following line to the "/etc/pam.d/login" file, if it does not already exist.

session    required     pam_limits.so

Disable secure linux by editing the "/etc/selinux/config" file, making sure the SELINUX flag is set as follows.

SELINUX=disabled
Alternatively, this alteration can be done using the GUI tool (System > Administration > Security Level and Firewall).
Click on the SELinux tab and disable the feature.

Create the new groups and users.

groupadd -g 501 oinstall
groupadd -g 502 dba
groupadd -g 503 oper
useradd -u 500 -g oinstall -G dba oracle
passwd oracle

Create the directories in which the Oracle software will be installed.

mkdir -p /u01/app/oracle/product/10.2.0/db/
mkdir -p /Source
chown -R oracle:oinstall /u01

Edit the "/etc/redhat-release" file replacing the current release information
 (Red Hat Enterprise Linux Server release 5 (Tikanga)) with the following:

redhat-4

Login as the oracle user and add the following lines at the end of the ".bash_profile" file.

# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_HOSTNAME=`hostname` ; export ORACLE_HOSTNAME
ORACLE_UNQNAME=xxx ; export ORACLE_UNQNAME
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db; export ORACLE_HOME
ORACLE_SID=xxx; 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 sqlplus='/usr/local/rlwrap/bin/rlwrap sqlplus'
alias rman='/usr/local/rlwrap/bin/rlwrap rman'

if [ $USER = "oracle" ]; then
  if [ $SHELL = "/bin/ksh" ]; then
    ulimit -p 16384
    ulimit -n 65536
  else
    ulimit -u 16384 -n 65536
  fi
fi

========================================================================
--install rarlinux-x64-5.1.0.tar.gz
[root@test ~]# tar -zxvf rarlinux-x64-5.1.0.tar.gz
[root@test ~]# cd rar
[root@test rar]# make && make install

這個時候,執行rar或者unrar會報一系列錯誤
[root@test rar]# rar
rar: /lib64/libc.so.6: version `GLIBC_2.7' not found (required by rar)
[root@test rar]# unrar
unrar: /lib64/libc.so.6: version `GLIBC_2.7' not found (required by unrar)

這個時候不要慌張,執行下列命令
yes|cp rar_static /usr/local/bin/rar && yes|cp rar_static /usr/local/bin/unrar

[root@test rar]# yes|cp rar_static /usr/local/bin/rar && yes|cp rar_static /usr/local/bin/unrar
cp: overwrite `/usr/local/bin/rar'? cp: overwrite `/usr/local/bin/unrar'?
========================================================================
Unpack Files
gunzip the files.
[root@test ~]# cd /Source/
[root@test Source]# gunzip 10201_database_linux_x86_64.cpio.gz
[root@test Source]# cpio -idmv < 10201_database_linux_x86_64.cpio

--Installation

Start the Oracle Universal Installer (OUI) by issuing the following command in the database directory.
[oracle@test ~]$ cd /Source/database/
[oracle@test database]$ ./runInstaller
-------------------------------------------------------------------
[oracle@test ~]# /u01/app/oracle/oraInventory/orainstRoot.sh
Changing permissions of /u01/app/oracle/oraInventory to 770.
Changing groupname of /u01/app/oracle/oraInventory to oinstall.
The execution of the script is complete
[root@test ~]# /u01/app/oracle/product/10.2.0/db/root.sh
Running Oracle10 root.sh script...

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/product/10.2.0

Enter the full pathname of the local bin directory: [/usr/local/bin]:
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
-------------------------------------------------------------------
--因為還沒有安裝資料庫,故先升級到 10205 version

[root@test Source]# unzip p8202632_10205_Linux-x86-64.zip

Edit the "/etc/redhat-release" with the following:

Red Hat Enterprise Linux Server release 5 (Tikanga)

[oracle@test Source]$ cd Disk1
[oracle@test Disk1]$ ./runInstaller

--Change Kernel Parameters

Add the following lines to the "/etc/sysctl.conf" file.

net.ipv4.ip_local_port_range = 9000 65500

Run the following command to change the current kernel parameters.

/sbin/sysctl -p 讓參數生效

upgrade EM
[root@test Source]# unzip p8350262_10205_Generic.zip
[root@test Source]# su - oracle
[oracle@test ~]$ cd /Source/8350262/
[oracle@test 8350262]$ /u01/app/oracle/product/10.2.0/db/OPatch/opatch apply

結束安裝 oracle 10g 並升級 DB 與 EM (10.2.0.5.0)
========================================================================
--還原資料庫

把備份出來的檔案copy到要還原的機器上,注意還原機器的還原目錄路徑要跟備份的機器的目錄相同

測試還原
環境:
建立一個全新的db(如有舊db的也請先刪除,並且要確認datafile已被刪除,然後再建立新的db)
sid要設的跟備份機器相同
放db檔案路徑也相同
使用tree 指令讀取一下 Product 的目錄結構
tree /u01/app/oracle/ -L 5 -d

========================================================================
--Copy Product DB RMAN Backup && Archive log

--Copy password to /u01/app/oracle/product/10.2.0/db/dbs/
[oracle@test rman_bak]$ cp orapwxxx /u01/app/oracle/product/10.2.0/db/dbs/

or create password (若沒有密碼檔)

[oracle@test ~]$ orapwd file=/u01/app/oracle/product/10.2.0/dbs/orapwxxx password=oracle entries=5

--使用 rman 還原資料庫
[oracle@test rman_bak]$ rman target /

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 12 09:10:01 2015

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database (not started)

RMAN> startup nomount

startup failed: ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db/dbs/initxxx.ora'

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

Total System Global Area     159383552 bytes

Fixed Size                     2094736 bytes
Variable Size                 67111280 bytes
Database Buffers              83886080 bytes
Redo Buffers                   6291456 bytes

--restore spfile
RMAN> restore spfile from '/backup/rman_bak/o1_mf_s_874109496_bj0t9r97_.bkp';

Starting restore at 12-MAR-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=36 devtype=DISK

channel ORA_DISK_1: autobackup found: /backup/rman_bak/o1_mf_s_874109496_bj0t9r97_.bkp
channel ORA_DISK_1: SPFILE restore from autobackup complete
Finished restore at 12-MAR-15

--先shutdown db
RMAN> shutdown immediate

Oracle instance shut down

--離開
RMAN> exit


Recovery Manager complete.


--use sqlplus login
[oracle@test rman_bak]$ sqlplus "/ as sysdba"

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 12 09:14:39 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL>

--create pfile
SQL> create pfile from spfile;

File created.

SQL> exit
Disconnected

因為是還原演練 所以要先修改 pfile 內容,因為有做 DataGuard。

--use sqlplus login
[oracle@test rman_bak]$ sqlplus "/ as sysdba"

SQL*Plus: Release 10.2.0.5.0 - Production on Thu Mar 12 09:21:16 2015

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.

Connected to an idle instance.

SQL> create spfile from pfile;   重新產生 spfile

File created.

SQL> exit
Disconnected


[oracle@test rman_bak]$ rman target /

Recovery Manager: Release 10.2.0.5.0 - Production on Thu Mar 12 09:24:43 2015

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

connected to target database (not started)

RMAN> startup nomount

Oracle instance started

Total System Global Area    6442450944 bytes

Fixed Size                     2105920 bytes
Variable Size               2030046656 bytes
Database Buffers            4395630592 bytes
Redo Buffers                  14667776 bytes


RMAN> set dbid=xxxxxxxxxxxx

executing command: SET DBID

這邊就可以還原controlfile的囉,注意還原的位置喔,應該要跟原來的一樣

RMAN> restore controlfile from '/backup/rman_bak/o1_mf_s_874109496_bj0t9r97_.bkp';

Starting restore at 12-MAR-15
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1092 devtype=DISK

channel ORA_DISK_1: restoring control file
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
output filename=/u02/oradata/xxx/control01.ctl
output filename=/u02/oradata/xxx/control02.ctl
output filename=/u02/oradata/xxx/control03.ctl
Finished restore at 12-MAR-15

RMAN> alter database mount;

--還原資料庫
RMAN> restore database;

Starting restore at 12-MAR-15
Starting implicit crosscheck backup at 12-MAR-15
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1092 devtype=DISK
Crosschecked 32 objects
Finished implicit crosscheck backup at 12-MAR-15

Starting implicit crosscheck copy at 12-MAR-15
using channel ORA_DISK_1
Crosschecked 1 objects
Finished implicit crosscheck copy at 12-MAR-15

searching for all files in the recovery area
cataloging files...
cataloging done

List of Cataloged Files
=======================
File Name: /u01/app/oracle/flash_recovery_area/PRIMARY/autobackup/2015_03_11/o1_mf_s_874080942_bhzyfhmb_.bkp

using channel ORA_DISK_1

channel ORA_DISK_1: starting datafile backupset restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
restoring datafile 00004 to /u02/oradata/xxx/users01.dbf
restoring datafile 00008 to /u03/oraindx/xxx/indx01.dbf
channel ORA_DISK_1: reading from backup piece /backup/rman_bak/xxxdb_nfq1jls5_1_1
.....................
.....................

RMAN> recover database;

Starting recover at 12-MAR-15
using channel ORA_DISK_1

starting media recovery

archive log thread 1 sequence 66742 is already on disk as file
.........
archive log thread 1 sequence 66743 is already on disk as file
.........


RMAN> alter database open resetlogs;

database opened  --> 看到database opened就表示還原完成囉

RMAN> exit


Recovery Manager complete.


沒有留言: