欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

oracle的clone及冷迁移(直接拷贝数据文件)

程序员文章站 2022-05-15 17:51:06
...

最近做了个oracle 10g数据冷迁移,很简单,但还是写一下基本的操作过程: 首先是准备迁移目标服务器,初始化环境,安装数据软件。 基本的环境初始化、依赖包先安装好、相关目录、用户都需要安装好(目标机器环境要与原一样),安装数据库软件我是采用的clone

最近做了个oracle 10g数据冷迁移,很简单,但还是写一下基本的操作过程:

首先是准备迁移目标服务器,初始化环境,安装数据软件。

基本的环境初始化、依赖包先安装好、相关目录、用户都需要安装好(目标机器环境要与原一样),安装数据库软件我是采用的clone,将线上的product目录打包传到目标服务器。

内存检查

grep MemTotal /proc/meminfo
MemTotal:     32949816 kB

磁盘空间检查

df -k /dev/shm/
Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                 16474908         0  16474908   0% /dev/shm
df -h /tmp
Filesystem            Size  Used Avail Use% Mounted on
/dev/shm               16G     0   16G   0% /tmp

内核检查

uname -r
2.6.18-194.el5

依赖包检查

rpm -q \
binutils \
compat-libstdc++-33 \
elfutils-libelf \
elfutils-libelf-devel \
gcc \
gcc-c++ \
glibc \
glibc-common \
glibc-devel \
glibc-headers \
ksh \
libaio \
libaio-devel \
libgcc \
libgomp \
libstdc++ \
libstdc++-devel \
make \
numactl-devel \
sysstat \
unixODBC \
unixODBC-devel | grep "not installed"

创建用户

groupadd oinstall
groupadd dba
chattr -i /etc/passwd /etc/shadow
useradd -g oinstall -G dba oracle
passwd oracle
chattr +i /etc/passwd /etc/shadow

目录创建、环境参数修改等

vi /etc/sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 8388608
kernel.shmmax = 34359738368
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
sysctl -p
vi /etc/security/limits.conf
oracle              soft    nproc   2047
oracle              hard    nproc   16384
oracle              soft    nofile  1024
oracle              hard    nofile  65536
oracle              soft    stack   10240
mkdir -p /U01/app/oracle/
chown -R oracle:oinstall /U01/
chmod -R 775 /U01/
vi /etc/pam.d/login
session    required     pam_limits.so
vi /etc/profile
if [ $USER = "oracle" ]; then
        if [ $SHELL = "/bin/ksh" ]; then
              ulimit -p 16384
              ulimit -n 65536
        else
              ulimit -u 16384 -n 65536
        fi
fi
vi .bash_profile
export ORACLE_BASE=/U01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1 
export ORACLE_SID=test
export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH 
export LANG="en_US.UTF-8" 
export NLS_LANG=american_AMERICA.UTF8 
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"

开始打包原服务器oracle软件

[@crm.cyou.com product]# pwd
/U01/app/oracle/product
[@crm.cyou.com product]# tar -zcf 10.2.0.tgz 10.2.0

拷贝到目标服务器,解压,开始clone

cd $ORACLE_HOME/clone/bin/
perl clone.pl ORACLE_BASE=/U01/app/oracle ORACLE_HOME=/U01/app/oracle/product/10.2.0  ORACLE_HOME_NAME=db_1
./runInstaller -clone -waitForCompletion  "ORACLE_BASE=/U01/app/oracle" "ORACLE_HOME=/U01/app/oracle/product/10.2.0/db_1" "ORACLE_HOME_NAME=db_1" -silent -noConfig -nowait
Starting Oracle Universal Installer...
Checking swap space: must be greater than 500 MB.   Actual 16386 MB    Passed
Preparing to launch Oracle Universal Installer from /tmp/OraInstall2012-03-21_05-09-02PM. Please wait ...Oracle Universal Installer, Version 10.2.0.0 Production
Copyright (C) 1999, 2011, Oracle. All rights reserved.
You can find the log of this install session at:
/U01/app/oracle/oraInventory/logs/cloneActions.....2PM.log
.................................................................................................... 100% Done.
Installation in progress (Wednesday, March 21, ... 5:09:10 PM CST)
...............................................................................                                                 79% Done.
Install successful
Linking in progress (Wednesday, March 21,... 5:09:16 PM CST)
Link successful
Setup in progress (Wednesday, March 21, ... 5:09:46 PM CST)
Setup successful
End of install phases.(Wednesday, March 21, ....:08 PM CST)
WARNING:A new inventory has been created in this session. However, it has not yet been registered as the central inventory of this system.
To register the new inventory please run the script '/U01/app/oracle/oraInventory/orainstRoot.sh' with root privileges.
If you do not register the inventory, you may not be able to update or patch the products you installed.
The following configuration scripts need to be executed as the "root" user.
/U01/app/oracle/oraInventory/orainstRoot.sh
/U01/app/oracle/product/10.2.0/db_1/root.sh
To execute the configuration scripts:
    1. Open a terminal window
    2. Log in as "root"
    3. Run the scripts
The cloning of db_1 was successful.
Please check '/U01/app/oracle/oraInventory/logs/cloneActions......PM.log' for more details.
9.run sh scripts
[root@bf_test_qd_119 ~]# /U01/app/oracle/oraInventory/orainstRoot.sh
Changing permissions of /U01/app/oracle/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions for world.
Changing groupname of /U01/app/oracle/oraInventory to oinstall.
The execution of the script is complete.
[root@bf_test_qd_119 ~]# /U01/app/oracle/product/10.2.0/db_1/root.sh
Check /U01/app/oracle/product/10.2.0/db_1/install/......

这个clone很快,ok后,可以停原oracle实例及监听

select distinct username from v$session;  查看应用是否停完
下面停掉所有监听
lsnrctl stop LISTENER
lsnrctl stop LISTENER1532
lsnrctl stop LISTENER1528
lsnrctl stop LISTENER1525

停数据库

shutdown immediate   //确定应用停完后,开始停数据库

开始拷贝数据文件

scp -r /U01/app/oracle/product/10.2.0/dbs/*  1.1.1.1:/U01/app/oracle/product/10.2.0/dbs/
scp -r oradata/ 1.1.1.1:/U01/app/oracle/
cd /U01/app/oracle/admin/ldjbmdb && mkdir -p adump  bdump  cdump  dpdump  pfile  udump  utl_file
cd /U01/app/oracle && mkdir -p arch  flash_recovery_area    oraInventory

需要拷贝的包括如下:

1、控制文件

2、数据文件

3、参数文件spfile ? (环境一致)

4、密码文件

5、redo

没有首先检查这些文件的路径,然后再进行拷贝,这里我的目录基本都没有变,控制文件、数据文件、redo都 在oradata里,密码文件、参数文件都在dbs目录里。所以我只要拷贝两个目录就行。

然后就创建相应的目录,启动数据库

startup mount;
alter database archivelog;
alter database open;
archive log list;
ALTER DATABASE FORCE LOGGING;
select log_mode,force_logging from v$database;
启监听
lsnrctl start LISTENER
lsnrctl start LISTENER1532
lsnrctl start LISTENER1528
lsnrctl start LISTENER1525

把数据库开启了archivelog(选择冷迁移的原因就在这里)

后面还有些步骤就是:

a.检查计划任务

b.防火墙

c.数据库自启动