备份恢复-Recovery Catalog(04)实战篇OCM知识点补充
1、修改hosts文件
#source ip: 192.168.94.102
#vi工具修改/etc/hosts文件,添加destination ip地址
[root@enmoedu ~]# vi /etc/hosts #回车
192.168.94.102 enmotech1 prod.enmotech1.com
192.168.94.103 enmotech2 prod.enmotech2.com
按键盘Esc,:wq (保存退出)
[root@enmoedu ~]# vi /etc/hostname #回车
enmotech1
reboot (重启)
#destination ip: 192.168.94.103
#vi工具修改/etc/hosts文件,添加source ip地址
[root@node1 ~]# vi /etc/hosts
192.168.94.103 enmotech2 prod.enmotech2.com
192.168.94.102 enmotech1 prod.enmotech1.com
192.168.94.101 master master.com
按键盘Esc,:wq (保存退出)
[root@node1 ~]# vi /etc/hostname #回车
enmotech2
reboot (重启)
2、实现免登录
source host: 192.168.94.102
#1)在linux系统的终端的任何目录下,输入切换命令:
[root@enmotech1 ~]# cd ~/.ssh
[root@enmotech1 .ssh]# pwd
/root/.ssh
#2)查看.ssh目录下内容,执行命令:
[root@enmotech1 .ssh]# ls -la
total 12
drwx------. 2 root root 38 May 15 2023 .
dr-xr-x---. 7 root root 4096 Nov 25 11:30 ..
#3)生成ssh免登录密钥,
#在linux系统命令框的.ssh目录下执行如下命令:ssh-keygen -t rsa # 连续四个回车
[root@enmotech1 .ssh]# ssh-keygen -t rsa #第1次回车
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): #第2次回车
Enter passphrase (empty for no passphrase): #第3次回车
Enter same passphrase again: #第4次回车
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pTwvZVGOOvfiVl9ORK/afQRe106QnTDNHO8xLFSaFZo root@enmotech1
The key's randomart image is:
+---[RSA 2048]----+
| . |
| o |
|.. o o |
|oo+ . + |
|.=oo S . o |
|*o%.. . o |
|B&+B+. . . . |
|=BBEo. . o . |
|oo++. . .. |
+----[SHA256]-----+
[root@enmotech1 .ssh]# ls -l
total 8
-rw------- 1 root root 1675 Nov 25 22:58 id_rsa
-rw-r--r-- 1 root root 394 Nov 25 22:58 id_rsa.pub
#4)查看公钥和私钥内容:分别执行如下命令
# cat id_rsa #私钥
# cat id_rsa.pub #公钥
#5)生成公钥,将公钥拷贝到要免登录的机器上
[root@enmotech1 .ssh]# ssh-copy-id enmotech1
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'enmotech1 (192.168.94.102)' can't be established.
ECDSA key fingerprint is SHA256:sd/Kns8+EkcxyPIUA2zGFLhRu09CnzWnLKWNDst3P6E.
ECDSA key fingerprint is MD5:7c:1c:9e:20:6b:de:a5:a8:6a:26:14:ee:cf:9f:1d:28.
Are you sure you want to continue connecting (yes/no)? 【yes】
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@enmotech1's password:【*******】
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'enmoedu'"
and check to make sure that only the key(s) you wanted were added.
[root@enmotech1 .ssh]# ll
total 16
-rw------- 1 root root 394 Nov 25 23:00 authorized_keys
-rw------- 1 root root 1675 Nov 25 22:58 id_rsa
-rw-r--r-- 1 root root 394 Nov 25 22:58 id_rsa.pub
-rw-r--r-- 1 root root 184 Nov 25 23:00 known_hosts
[root@enmotech1 .ssh]# pwd
/root/.ssh
destination hosts: 192.168.94.103
#查看目标端文件夹ssh路径
[root@enmotech2 ~]# cd ~/.ssh
[root@enmotech2 .ssh]# pwd
/root/.ssh
source hosts: 192.168.94.102端,scp命令传输公钥文件
[root@enmotech1 .ssh]# scp ./authorized_keys enmotech2:/root/.ssh/
The authenticity of host 'enmotech2 (192.168.94.103)' can't be established.
ECDSA key fingerprint is SHA256:OaW0MtRTqL2DVNoWlDLzlKD520xBHEnjgWVii5eiVEE.
ECDSA key fingerprint is MD5:1f:97:04:2d:f7:30:34:3d:07:51:e8:1a:d6:37:f4:6e.
Are you sure you want to continue connecting (yes/no)?【yes】
Warning: Permanently added 'enmotech2,192.168.94.103' (ECDSA) to the list of known hosts.
root@enmotech2's password:【*******】
authorized_keys 100% 394 111.5KB/s 00:00
[root@enmotech1 .ssh]# scp ./id_rsa.pub enmotech2:/root/.ssh/
id_rsa.pub 100% 394 198.0KB/s 00:00
[root@enmotech1 .ssh]# scp ./id_rsa enmotech2:/root/.ssh/
id_rsa 100% 1675 725.6KB/s 00:00
3、验证登陆
校验从源端登陆目标端
[root@enmotech1 .ssh]# ssh enmotech2
Last login: Tue Nov 26 07:24:51 2024 from enmotech1
[root@enmotech2 ~]# ssh enmotech1
Last login: Mon Nov 25 23:11:54 2024 from enmotech2
[root@enmotech1 ~]#
校验从目标端登陆源端
[root@enmotech2 ~]# ssh enmotech1
Last login: Mon Nov 25 23:13:02 2024 from enmotech2
[root@enmotech1 ~]# ssh enmotech2
Last login: Tue Nov 26 07:26:01 2024 from enmotech1
[root@enmotech2 ~]#
4、仅只安装软件(目标端)
4.1 安装操作系统依懒包
- 手动安装
# yum install libst* -y
# yum install gcc* -y
# yum install libaio* -y
# yum install glibc* -y
# yum install compat*
# yum install libx* -y
# yum install libX* y
# yum install make* -y
# yum install sysstat*
依赖包的安装是很有必要的!
4.2 内核参数配置
# vi /etc/sysctl.conf
net.ipv4.ip_local_port_range = 9000 65500
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
4.3 检查是否开启大页
通过root用户登陆来检查是否开启大页:
Red Hat Enterprise Linux kernels:
# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
Other kernels:
# cat /sys/kernel/mm/transparent_hugepage/enabled
如下显示表示:开启状态
[always] never
注意:
如果提示如下文件不存在,则表示hugepage已从内核中移除:neither /sys/kernel/mm/transparent_hugepage nor /sys/kernel/mm/redhat_transparent_hugepage files exist.
4.4 禁用Transparent HugePages
对于Oracle Linux 7 and Red Hat Enterprise Linux 7,修改/etc/default/grub添加
transparent_hugepage=never
示例:
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet numa=off transparent_hugepage=never"
GRUB_DISABLE_RECOVERY="true"
运行grub2–mkconfig 重新生成grub.cfg文件:
# grub2-mkconfig -o /boot/grub2/grub.cfg
4.5 配置用户、组及目录
- 1)创建组
# groupadd -g 54321 oinstall
# groupadd -g 54322 dba
# groupadd -g 54323 oper
# groupadd -g 54324 backupdba
# groupadd -g 54325 dgdba
# groupadd -g 54326 kmdba
# groupadd -g 54330 racdba
# groupadd -g 54331 asmdba
- 2)创建用户
# useradd -u 54321 -g oinstall -G dba,asmdba,backupdba,dgdba,kmdba,racdba,oper oracle
设置oracle用户密码:
echo "oracle123"|passwd --stdin oracle
如果oracle用户已存在,可以使用passwd oracle方式更改密码。
- 3)创建目录并授权
# mkdir -p /u01/app
# chown -R oracle:oinstall /u01/app
# chmod -R 775 /u01/app
# mkdir -p /u01/app/oraInventory
# chown -R oracle:oinstall /u01/app/oraInventory
# chmod -R 775 /u01/app/oraInventory
# mkdir -p /u01/app/oracle/cfgtoollogs
# mkdir -p /u01/app/oracle/product/19.3.0/dbhome_1
# chown -R oracle:oinstall /u01/app/oracle
# chmod -R 775 /u01/app/oracle
4.6 关闭防火墙及selinux
- 1)selinux关闭需重启生效
# vi /etc/selinux/config #将selinux的值改为disabled
SELINUX=disabled
- 2)防火墙关闭及禁用开机自启动
# systemctl list-unit-files|grep firewalld
# systemctl stop firewalld.service
# systemctl status firewalld.service
# systemctl disable firewalld.service
- 3)reboot重启生效
[root@enmotech2 ~]# reboot
[root@enmotech2 ~]# systemctl status firewalld.service
â— firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@enmotech2 ~]# getenforce
Disabled
4.7 安装软件
4.7.1 以oracle用户登陆设置环境变量
[root@enmotech2 ~]# su - oracle
[oracle@enmotech2 ~]$ vi .bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19.3.0/dbhome_1
export ORACLE_SID=prod
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
#按Esc,:wq (保存退出)
[oracle@enmotech2 ~]$ . .bash_profile
[oracle@enmotech2 ~]$ echo $ORACLE_HOME
/u01/app/oracle/product/19.3.0/dbhome_1
[oracle@enmotech2 ~]$ echo $ORACLE_BASE
/u01/app/oracle
[oracle@enmotech2 ~]$ echo $ORACLE_SID
prod
4.7.2 上传安装包
利用xftp上传到/soft目录,上传Oracle 11g(linux.x64_11gR2_database_[1of2/2of2])
# su - root
# mkdir /soft
4.7.3 解压安装包
安装11g软件
[root@enmotech2 soft]# ll
总用量 2097024
-rw-r--r--. 1 root root 796917760 12月 3 17:54 linux.x64_11gR2_database_1of2.zip
-rw-r--r--. 1 root root 800587776 12月 3 17:54 linux.x64_11gR2_database_2of2.zip
[root@enmotech2 soft]# chown oracle:oinstall /soft -R
[root@enmotech2 soft]# chmod 755 /soft -R
[oracle@enmotech2 ~]$ ll
总用量 0
[oracle@enmotech2 ~]$ cd /soft
[oracle@enmotech2 soft]$ ll
总用量 2295592
-rwxr-xr-x. 1 oracle oinstall 1239269270 12月 3 17:56 linux.x64_11gR2_database_1of2.zip
-rwxr-xr-x. 1 oracle oinstall 1111416131 12月 3 17:55 linux.x64_11gR2_database_2of2.zip
[oracle@enmotech2 soft]$ unzip /soft/linux.x64_11gR2_database_1of2.zip -d $ORACLE_HOME/
[oracle@enmotech2 soft]$ unzip /soft/linux.x64_11gR2_database_2of2.zip -d $ORACLE_HOME/
4.7.4 执行安装
修改xshell设置
打开xmanager中的Xmanager - Passive
设置DISPLAY变量的值:
[oracle@enmotech2 soft]$ cd $ORACLE_HOME
[oracle@enmotech2 dbhome_1]$ pwd
/u01/app/oracle/product/19.3.0/dbhome_1
[oracle@enmotech2 dbhome_1]$ ls
database
[oracle@enmotech2 dbhome_1]$ cd database/
[oracle@enmotech2 database]$ ls
doc install response rpm runInstaller sshsetup stage welcome.html
[oracle@enmotech2 database]$ export LANG=en_US.UTF-8
[oracle@enmotech2 database]$ export DISPLAY=192.168.94.1:0.0
[oracle@enmotech2 database]$ ./runInstaller
正在启动 Oracle Universal Installer...
检查临时空间: 必须大于 120 MB。 实际为 27254 MB 通过
检查交换空间: 必须大于 150 MB。 实际为 2047 MB 通过
检查监视器: 监视器配置至少必须显示 256 种颜色
>>> 无法使用命令 /usr/bin/xdpyinfo 自动检查显示器颜色。请检查是否设置了 DISPLAY 变量。 未通过 <<<<
未通过某些要求检查。必须先满足这些 要求,
然后才能继续安装,
是否继续? (y/n) [n] y
>>> 忽略未通过的必需先决条件。继续...
准备从以下地址启动 Oracle Universal Installer /tmp/OraInstall2024-12-03_06-55-11PM. 请稍候...[oracle@enmotech2 database]$
1.只安装软件
点击“是”,
点击“next",
点击“yes",
点击“next”,
点击“next”,
点击“next”,
点击“next”,
点击“next”,
点击“yes”,
点击“next”,
点击“next”,
如果有条件能够找到下面的安装包,能安装就安装,安装不了就“next”:
yum install -y libaio-0.3.105*
yum install -y glibc-2.3.4-2.41*
yum install -y compat-libstdc++-33-3.2.3*
yum install -y elfutils-libelf-devel-0.97*
yum install -y libaio-devel-0.3.105*
yum install -y libgcc-3.4.6*
yum install -y libstdc++-3.4.6*
yum install -y unixODBC-2.2.11*
yum install -y unixODBC-devel-2.2.11*
yum install -y pdksh-5.2.14*
点击“next”,
点击“finish”,
点击“continue”不行,无法继续下去,
点击“retry”也不行,
点击“abort”就直接退出了。必须点击“continue”。一直点“continue”。
到此为止,Oracle 11g软件已安装完毕!
4.7.5 后续问题
[oracle@enmotech2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Tue Dec 3 22:43:17 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL>
Oracle 11g 软件安装成功!
5、数据库克隆
5.1 源端 ip: 192.168.94.102
#源端实例名、版本号等
SYS@prod> col host_name for a20
select instance_name,
host_name,
version,
status,
active_state,
blocked
from v$instance;
INSTANCE_NAME HOST_NAME VERSION STATUS ACTIVE_ST BLOCKED
---------------- -------------------- ----------------- ------------ --------- --------
prod enmotech1 11.2.0.1.0 OPEN NORMAL NO
#源端审计目录
SYS@prod> show parameter audit_file_dest
NAME TYPE VALUE
------------------------ ----------- ---------------------------------
audit_file_dest string /u01/app/oracle/admin/prod/adump
#源端查询快速恢复区目录
SYS@prod> show parameter db_recovery_file_dest
NAME TYPE VALUE
------------------------------- ----------- ------------------------------
db_recovery_file_dest string /home/oracle/fra/backup
db_recovery_file_dest_size big integer 4G
#源端listener.ora
[oracle@enmotech1 admin]$ cat listener.ora
#
LISTENER =
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.94.102)(PORT=1521))
(ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=prod.enmotech1.com)
(SID_NAME=prod)
(ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1)))
#源端tnsname.ora
[oracle@enmotech1 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
PROD = (DESCRIPTION=
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.94.102)(PORT = 1521))
(CONNECT_DATA=
(SERVICE_NAME=prod.enmotech1.com)
(SID=prod)))
aux = (DESCRIPTION=
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.94.103)(PORT = 1521))
(CONNECT_DATA=
(SERVICE_NAME=prod.enmotech2.com)
(SID=prod)))
5.2 目标端 ip: 192.168.94.103
#关闭其它实例,修改环境变量
[oracle@enmotech2 ~]$ cat .bash_profile
export PATH
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19.3.0/dbhome_1
export ORACLE_SID=prod
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
[oracle@enmotech2 ~]$ source .bash_profile
[oracle@enmotech2 ~]$ echo $ORACLE_SID
prod
#建立pfile哑参文件
[oracle@enmotech2 ~]$ cd $ORACLE_HOME/dbs
[oracle@enmotech2 dbs]$ pwd
/u01/app/oracle/product/19.3.0/dbhome_1/dbs
[oracle@enmotech2 dbs]$ vi dummy.ora
db_name='aaa'
[oracle@enmotech2 dbs]$
#从源端复制口令文件到目标库
[oracle@enmotech2 ~]$ cd /u01/app/oracle/product/19.3.0/dbhome_1/dbs/
[oracle@enmotech2 dbs]$ ll
总用量 8
-rw-r--r-- 1 oracle oinstall 14 12月 3 23:54 dummy.ora
-rw-r--r-- 1 oracle oinstall 2851 5月 15 2009 init.ora
[oracle@enmotech2 dbs]$ pwd
/u01/app/oracle/product/19.3.0/dbhome_1/dbs
[oracle@enmotech2 dbs]$ scp enmotech1:/u01/app/oracle/product/19.3.0/dbhome_1/dbs/orapwprod ./
The authenticity of host 'enmoedu (192.168.94.102)' can't be established.
ECDSA key fingerprint is SHA256:sd/Kns8+EkcxyPIUA2zGFLhRu09CnzWnLKWNDst3P6E.
ECDSA key fingerprint is MD5:7c:1c:9e:20:6b:de:a5:a8:6a:26:14:ee:cf:9f:1d:28.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'enmoedu,192.168.94.102' (ECDSA) to the list of known hosts.
oracle@enmoedu's password:【oracle】
orapwprod 100% 1536 380.4KB/s 00:00
[oracle@enmotech2 dbs]$ ll
总用量 12
-rw-r--r-- 1 oracle oinstall 14 12月 3 23:54 dummy.ora
-rw-r--r-- 1 oracle oinstall 2851 5月 15 2009 init.ora
-rw-r----- 1 oracle oinstall 1536 12月 4 01:25 orapwprod
#目标端创建数据库需要的目录
#1)创建目标端审计目录(先在源端查询审计目录的路径)
[oracle@enmotech2 ~]$ mkdir -p /u01/app/oracle/admin/prod/adump
#2)创建目标端快速恢复区路径(先在源端查询快速恢复区的路径)
[oracle@enmotech2 ~]$ mkdir -p /home/oracle/fra/backup
[oracle@enmotech2 ~]$ ls -ld /home/oracle/fra/backup
drwxr-xr-x 2 oracle oinstall 6 12月 4 01:34 /home/oracle/fra/backup
#补充创建路径
[oracle@enmotech2 ~]$ mkdir -p /home/oracle/BCT
[oracle@enmotech2 ~]$ ls -ld /home/oracle/BCT
drwxr-xr-x 2 oracle oinstall 6 12月 5 02:43 /home/oracle/BCT
#3)创建归档目录
[oracle@enmotech2 ~]$ cd /u01/app
[oracle@enmotech2 app]$ mkdir arch
[oracle@enmotech2 app]$ ls -ld /u01/app/arch
drwxr-xr-x 2 oracle oinstall 6 12月 4 01:36 /u01/app/arch
#参数文件、密码文件
[oracle@enmotech2 ~]$ cd $ORACLE_HOME/dbs
[oracle@enmotech2 dbs]$ ls -lht
总用量 12K
-rw-r----- 1 oracle oinstall 1.5K 12月 4 01:25 orapwprod
-rw-r--r-- 1 oracle oinstall 14 12月 3 23:54 dummy.ora
-rw-r--r-- 1 oracle oinstall 2.8K 5月 15 2009 init.ora
静态参数文件(哑参) ———— dummy.ora
source database的远程口令文件副本 ———— orapwprod
#数据库目录
[oracle@enmotech2 ~]$ mkdir -p /u01/app/oracle/oradata/prod
[oracle@enmotech2 ~]$ ls -ld /u01/app/oracle/oradata/prod
drwxr-xr-x 2 oracle oinstall 6 12月 4 01:41 /u01/app/oracle/oradata/prod
#source端和duplicate端之间的oracle net
#网络复制时通过source端和duplicate端之间的oracle net,必须保证两端的监听都能启动,duplicate端用的是静态监听,source端使用静态/动态即可。
#1)配置duplicate端的静态/动态监听配置文件
#
LISTENER =
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.94.103)(PORT=1521))
(ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(GLOBAL_DBNAME=prod.enmotech2.com)
(SID_NAME=prod)
(ORACLE_HOME=/u01/app/oracle/product/19.3.0/dbhome_1)))
[oracle@enmotech2 admin]$ lsnrctl start
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 04-DEC-2024 23:18:54
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Starting /u01/app/oracle/product/19.3.0/dbhome_1/bin/tnslsnr: please wait...
TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/enmotech2/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.94.103)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.94.103)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 04-DEC-2024 23:18:56
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/enmotech2/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.94.103)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))
Services Summary...
Service "prod.enmotech2.com" has 1 instance(s).
Instance "prod", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
(从上面的监听状态可以得出,没有服务“aaa”。)
#两端tnsname.ora
#source和duplicate两端的tnsname.ora,两端都必须配置,两段内容相同即可。
#将源端的tnsnames.ora复制到目标端即可
[oracle@enmotech2 admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
PROD = (DESCRIPTION=
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.94.102)(PORT = 1521))
(CONNECT_DATA=
(SERVICE_NAME=prod.enmotech1.com)
(SID=prod)))
aux = (DESCRIPTION=
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.94.103)(PORT = 1521))
(CONNECT_DATA=
(SERVICE_NAME=prod.enmotech2.com)
(SID=prod)))
#目标端测试网络
[oracle@enmotech2 ~]$ tnsping prod
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 04-DEC-2024 23:20:19
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.94.102)(PORT = 1521)) (CONNECT_DATA= (SERVICE_NAME=prod.enmotech1.com) (SID=prod)))
OK (10 msec)
#目标端测试网络
[oracle@enmotech2 ~]$ tnsping enmotech1
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 04-DEC-2024 23:20:44
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
Used HOSTNAME adapter to resolve the alias
Attempting to contact (DESCRIPTION=(CONNECT_DATA=(SERVICE_NAME=))(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.94.102)(PORT=1521)))
OK (10 msec)
#源端网络测试
[oracle@enmotech1 ~]$ tnsping aux
TNS Ping Utility for Linux: Version 11.2.0.1.0 - Production on 04-DEC-2024 15:22:47
Copyright (c) 1997, 2009, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/19.3.0/dbhome_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.94.103)(PORT = 1521)) (CONNECT_DATA= (SERVICE_NAME=prod.enmotech2.com) (SID=prod)))
OK (10 msec)
#目标端登陆源端数据库
[oracle@enmotech2 ~]$ sqlplus sys/oracle@prod as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 4 02:00:38 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
SQL> show parameter name
NAME TYPE VALUE
-------------------------------- ----------- ------------------------------
db_file_name_convert string /u01/app/oracle/oradata/proddg
, /u01/app/oracle/oradata/prod
db_name string prod
db_unique_name string prod
global_names boolean FALSE
instance_name string prod
lock_name_space string
log_file_name_convert string /u01/app/oracle/oradata/proddg
, /u01/app/oracle/oradata/prod
service_names string prod.enmotech.com
[oracle@enmotech2 ~]$ sqlplus sys/oracle@192.168.94.102:1521/prod.enmotech1.com as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 4 23:24:00 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
#测试库使用哑参文件到nomount状态
#duplicate端使用dummy参数文件启动实例到nomount状态
[oracle@enmotech2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 4 02:02:13 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup nomount pfile=$ORACLE_HOME/dbs/dummy.ora
ORACLE instance started.
Total System Global Area 217157632 bytes
Fixed Size 2211928 bytes
Variable Size 159387560 bytes
Database Buffers 50331648 bytes
Redo Buffers 5226496 bytes
SQL>
SQL> alter system register;
System altered.
-- 监控
[oracle@enmotech2 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 04-DEC-2024 23:25:47
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.94.103)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 04-DEC-2024 23:22:19
Uptime 0 days 0 hr. 3 min. 27 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/enmotech2/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.94.103)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))
Services Summary...
Service "aaa" has 1 instance(s). #服务“aaa”已注册。BLOCKED,堵塞状态,无法访问。
Instance "prod", status BLOCKED, has 1 handler(s) for this service...
Service "prod.enmotech2.com" has 1 instance(s).
Instance "prod", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
SQL> select status from v$instance;
STATUS
------------
STARTED
SQL> show parameter name
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert string
db_name string aaa
db_unique_name string aaa
global_names boolean FALSE
instance_name string prod
lock_name_space string
log_file_name_convert string
service_names string aaa
5.3 验证
-- 目标端数据库自校验
[oracle@enmotech2 ~]$ sqlplus sys/oracle@aux as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 4 23:27:59 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
-- 源端数据库登陆至目标端数据库
[oracle@enmotech1 ~]$ sqlplus sys/oracle@aux as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 4 15:27:50 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@aux>
[oracle@enmotech1 ~]$ sqlplus sys/oracle@192.168.94.103:1521/aaa as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 4 10:15:38 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
ERROR:
ORA-12528: TNS:listener: all appropriate instances are blocking new connections #阻塞
(哑参)
-- 目标端数据库登陆至源端数据库
-- 第1种登陆方式
[oracle@enmotech2 ~]$ sqlplus sys/oracle@prod as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 4 18:02:44 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> show parameter name
NAME TYPE VALUE
-------------------------------- ----------- ------------------------------
db_file_name_convert string /u01/app/oracle/oradata/proddg
, /u01/app/oracle/oradata/prod
db_name string prod
db_unique_name string prod
global_names boolean FALSE
instance_name string prod
lock_name_space string
log_file_name_convert string /u01/app/oracle/oradata/proddg
, /u01/app/oracle/oradata/prod
service_names string prod.enmotech.com
-- 第2种登陆方式
[oracle@enmotech2 ~]$ sqlplus sys/oracle@192.168.94.102:1521/prod.enmotech1.com as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 4 18:05:18 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
5.4 rman复制
测试库开启log session记录会话日志方便以后查看。
在duplicate端使用rman同时连接source和duplicate(两端都是用远程连接方式)
#源端
[oracle@enmotech1 ~]$ rman target sys/oracle@prod auxiliary sys/oracle@aux
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Dec 4 15:30:48 2024
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=548929043)
connected to auxiliary database: AAA (not mounted)
RMAN>
#目标端(重点在目标端执行)
[oracle@enmotech2 ~]$ rman target sys/oracle@prod auxiliary sys/oracle@aux
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Dec 4 23:31:08 2024
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=548929043)
connected to auxiliary database: AAA (not mounted)
RMAN>
5.5 使用rman工具复制数据库
- 目标端数据库克隆
[oracle@enmotech2 ~]$ rman target sys/oracle@prod auxiliary sys/oracle@aux
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 5 02:45:22 2024
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=548929043)
connected to auxiliary database: AAA (not mounted)
RMAN> duplicate target database to prod from active database spfile nofilenamecheck;
Starting Duplicate Db at 05-DEC-24
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=5 device type=DISK
contents of Memory Script:
{
backup as copy reuse
targetfile '/u01/app/oracle/product/19.3.0/dbhome_1/dbs/spfileprod.ora' auxiliary format
'/u01/app/oracle/product/19.3.0/dbhome_1/dbs/spfileprod.ora' ;
sql clone "alter system set spfile= ''/u01/app/oracle/product/19.3.0/dbhome_1/dbs/spfileprod.ora''";
}
executing Memory Script
Starting backup at 05-DEC-24
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=69 device type=DISK
Finished backup at 05-DEC-24
sql statement: alter system set spfile= ''/u01/app/oracle/product/19.3.0/dbhome_1/dbs/spfileprod.ora''
contents of Memory Script:
{
sql clone "alter system set db_name =
''PROD'' comment=
''duplicate'' scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
sql statement: alter system set db_name = ''PROD'' comment= ''duplicate'' scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1586708480 bytes
Fixed Size 2213736 bytes
Variable Size 1140852888 bytes
Database Buffers 436207616 bytes
Redo Buffers 7434240 bytes
contents of Memory Script:
{
sql clone "alter system set db_name =
''PROD'' comment=
''Modified by RMAN duplicate'' scope=spfile";
sql clone "alter system set db_unique_name =
''PROD'' comment=
''Modified by RMAN duplicate'' scope=spfile";
shutdown clone immediate;
startup clone force nomount
backup as copy current controlfile auxiliary format '/u01/app/oracle/oradata/prod/control01.ctl';
restore clone controlfile to '/u01/app/oracle/oradata/prod/control02.ctl' from
'/u01/app/oracle/oradata/prod/control01.ctl';
alter clone database mount;
}
executing Memory Script
sql statement: alter system set db_name = ''PROD'' comment= ''Modified by RMAN duplicate'' scope=spfile
sql statement: alter system set db_unique_name = ''PROD'' comment= ''Modified by RMAN duplicate'' scope=spfile
Oracle instance shut down
Oracle instance started
Total System Global Area 1586708480 bytes
Fixed Size 2213736 bytes
Variable Size 1140852888 bytes
Database Buffers 436207616 bytes
Redo Buffers 7434240 bytes
Starting backup at 05-DEC-24
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
copying current control file
output file name=/u01/app/oracle/product/19.3.0/dbhome_1/dbs/snapcf_prod.f tag=TAG20241204T185423 RECID=8 STAMP=1186858485
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:45
Finished backup at 05-DEC-24
Starting restore at 05-DEC-24
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=63 device type=DISK
channel ORA_AUX_DISK_1: copied control file copy
Finished restore at 05-DEC-24
database mounted
RMAN-05538: WARNING: implicitly using DB_FILE_NAME_CONVERT
contents of Memory Script:
{
set newname for datafile 1 to
"/u01/app/oracle/oradata/prod/system01.dbf";
set newname for datafile 2 to
"/u01/app/oracle/oradata/prod/sysaux01.dbf";
set newname for datafile 3 to
"/u01/app/oracle/oradata/prod/undotbs01.dbf";
set newname for datafile 4 to
"/u01/app/oracle/oradata/prod/users01.dbf";
set newname for datafile 5 to
"/u01/app/oracle/oradata/prod/dbcompare_isc4052.dbf";
set newname for datafile 6 to
"/u01/app/oracle/oradata/prod/rmantbs.dbf";
set newname for datafile 7 to
"/u01/app/oracle/oradata/prod/tbs_fla.dbf";
backup as copy reuse
datafile 1 auxiliary format
"/u01/app/oracle/oradata/prod/system01.dbf" datafile
2 auxiliary format
"/u01/app/oracle/oradata/prod/sysaux01.dbf" datafile
3 auxiliary format
"/u01/app/oracle/oradata/prod/undotbs01.dbf" datafile
4 auxiliary format
"/u01/app/oracle/oradata/prod/users01.dbf" datafile
5 auxiliary format
"/u01/app/oracle/oradata/prod/dbcompare_isc4052.dbf" datafile
6 auxiliary format
"/u01/app/oracle/oradata/prod/rmantbs.dbf" datafile
7 auxiliary format
"/u01/app/oracle/oradata/prod/tbs_fla.dbf" ;
sql 'alter system archive log current';
}
executing Memory Script
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting backup at 05-DEC-24
using channel ORA_DISK_1
channel ORA_DISK_1: starting datafile copy
input datafile file number=00005 name=/u01/app/oracle/oradata/prod/dbcompare_isc4052.dbf
output file name=/u01/app/oracle/oradata/prod/dbcompare_isc4052.dbf tag=TAG20241204T185544
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:25:42
channel ORA_DISK_1: starting datafile copy
input datafile file number=00004 name=/u01/app/oracle/oradata/prod/users01.dbf
output file name=/u01/app/oracle/oradata/prod/users01.dbf tag=TAG20241204T185544
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:04:46
channel ORA_DISK_1: starting datafile copy
input datafile file number=00001 name=/u01/app/oracle/oradata/prod/system01.dbf
output file name=/u01/app/oracle/oradata/prod/system01.dbf tag=TAG20241204T185544
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:27
channel ORA_DISK_1: starting datafile copy
input datafile file number=00002 name=/u01/app/oracle/oradata/prod/sysaux01.dbf
output file name=/u01/app/oracle/oradata/prod/sysaux01.dbf tag=TAG20241204T185544
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:02:48
channel ORA_DISK_1: starting datafile copy
input datafile file number=00003 name=/u01/app/oracle/oradata/prod/undotbs01.dbf
output file name=/u01/app/oracle/oradata/prod/undotbs01.dbf tag=TAG20241204T185544
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:01:17
channel ORA_DISK_1: starting datafile copy
input datafile file number=00007 name=/u01/app/oracle/oradata/prod/tbs_fla.dbf
output file name=/u01/app/oracle/oradata/prod/tbs_fla.dbf tag=TAG20241204T185544
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:37
channel ORA_DISK_1: starting datafile copy
input datafile file number=00006 name=/u01/app/oracle/oradata/prod/rmantbs.dbf
output file name=/u01/app/oracle/oradata/prod/rmantbs.dbf tag=TAG20241204T185544
channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:25
Finished backup at 05-DEC-24
sql statement: alter system archive log current
contents of Memory Script:
{
backup as copy reuse
archivelog like "/home/oracle/fra/backup/PROD/archivelog/2024_12_04/o1_mf_1_23_mo0hh8jx_.arc" auxiliary format
"/home/oracle/fra/backup/PROD/archivelog/2024_12_05/o1_mf_1_23_%u_.arc" ;
catalog clone recovery area;
switch clone datafile all;
}
executing Memory Script
Starting backup at 05-DEC-24
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log copy
input archived log thread=1 sequence=23 RECID=482 STAMP=1186860780
output file name=/home/oracle/fra/backup/PROD/archivelog/2024_12_05/o1_mf_1_23_1l3bs3ni_.arc RECID=0 STAMP=0
channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:36
Finished backup at 05-DEC-24
searching for all files in the recovery area
List of Files Unknown to the Database
=====================================
File Name: /home/oracle/fra/backup/PROD/archivelog/2024_12_05/o1_mf_1_23_1l3bs3ni_.arc
cataloging files...
cataloging done
List of Cataloged Files
=======================
File Name: /home/oracle/fra/backup/PROD/archivelog/2024_12_05/o1_mf_1_23_1l3bs3ni_.arc
datafile 1 switched to datafile copy
input datafile copy RECID=8 STAMP=1186889627 file name=/u01/app/oracle/oradata/prod/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=9 STAMP=1186889627 file name=/u01/app/oracle/oradata/prod/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=10 STAMP=1186889627 file name=/u01/app/oracle/oradata/prod/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=11 STAMP=1186889627 file name=/u01/app/oracle/oradata/prod/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=12 STAMP=1186889627 file name=/u01/app/oracle/oradata/prod/dbcompare_isc4052.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=13 STAMP=1186889627 file name=/u01/app/oracle/oradata/prod/rmantbs.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=14 STAMP=1186889627 file name=/u01/app/oracle/oradata/prod/tbs_fla.dbf
contents of Memory Script:
{
set until scn 3808645;
recover
clone database
delete archivelog
;
}
executing Memory Script
executing command: SET until clause
Starting recover at 05-DEC-24
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 23 is already on disk as file /home/oracle/fra/backup/PROD/archivelog/2024_12_05/o1_mf_1_23_1l3bs3ni_.arc
archived log file name=/home/oracle/fra/backup/PROD/archivelog/2024_12_05/o1_mf_1_23_1l3bs3ni_.arc thread=1 sequence=23
media recovery complete, elapsed time: 00:00:02
Finished recover at 05-DEC-24
contents of Memory Script:
{
shutdown clone immediate;
startup clone nomount;
sql clone "alter system set db_name =
''PROD'' comment=
''Reset to original value by RMAN'' scope=spfile";
sql clone "alter system reset db_unique_name scope=spfile";
shutdown clone immediate;
startup clone nomount;
}
executing Memory Script
database dismounted
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1586708480 bytes
Fixed Size 2213736 bytes
Variable Size 1140852888 bytes
Database Buffers 436207616 bytes
Redo Buffers 7434240 bytes
sql statement: alter system set db_name = ''PROD'' comment= ''Reset to original value by RMAN'' scope=spfile
sql statement: alter system reset db_unique_name scope=spfile
Oracle instance shut down
connected to auxiliary database (not started)
Oracle instance started
Total System Global Area 1586708480 bytes
Fixed Size 2213736 bytes
Variable Size 1140852888 bytes
Database Buffers 436207616 bytes
Redo Buffers 7434240 bytes
sql statement: CREATE CONTROLFILE REUSE SET DATABASE "PROD" RESETLOGS ARCHIVELOG
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 100
MAXINSTANCES 8
MAXLOGHISTORY 292
LOGFILE
GROUP 1 ( '/u01/app/oracle/oradata/prod/redo01.log' ) SIZE 10 M REUSE,
GROUP 2 ( '/u01/app/oracle/oradata/prod/redo02.log' ) SIZE 10 M REUSE,
GROUP 3 ( '/u01/app/oracle/oradata/prod/redo03.log' ) SIZE 10 M REUSE
DATAFILE
'/u01/app/oracle/oradata/prod/system01.dbf'
CHARACTER SET AL32UTF8
contents of Memory Script:
{
set newname for tempfile 1 to
"/u01/app/oracle/oradata/prod/temp01.dbf";
switch clone tempfile all;
catalog clone datafilecopy "/u01/app/oracle/oradata/prod/sysaux01.dbf",
"/u01/app/oracle/oradata/prod/undotbs01.dbf",
"/u01/app/oracle/oradata/prod/users01.dbf",
"/u01/app/oracle/oradata/prod/dbcompare_isc4052.dbf",
"/u01/app/oracle/oradata/prod/rmantbs.dbf",
"/u01/app/oracle/oradata/prod/tbs_fla.dbf";
switch clone datafile all;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /u01/app/oracle/oradata/prod/temp01.dbf in control file
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/prod/sysaux01.dbf RECID=1 STAMP=1186889981
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/prod/undotbs01.dbf RECID=2 STAMP=1186889981
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/prod/users01.dbf RECID=3 STAMP=1186889981
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/prod/dbcompare_isc4052.dbf RECID=4 STAMP=1186889981
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/prod/rmantbs.dbf RECID=5 STAMP=1186889981
cataloged datafile copy
datafile copy file name=/u01/app/oracle/oradata/prod/tbs_fla.dbf RECID=6 STAMP=1186889981
datafile 2 switched to datafile copy
input datafile copy RECID=1 STAMP=1186889981 file name=/u01/app/oracle/oradata/prod/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=2 STAMP=1186889981 file name=/u01/app/oracle/oradata/prod/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=3 STAMP=1186889981 file name=/u01/app/oracle/oradata/prod/users01.dbf
datafile 5 switched to datafile copy
input datafile copy RECID=4 STAMP=1186889981 file name=/u01/app/oracle/oradata/prod/dbcompare_isc4052.dbf
datafile 6 switched to datafile copy
input datafile copy RECID=5 STAMP=1186889981 file name=/u01/app/oracle/oradata/prod/rmantbs.dbf
datafile 7 switched to datafile copy
input datafile copy RECID=6 STAMP=1186889981 file name=/u01/app/oracle/oradata/prod/tbs_fla.dbf
contents of Memory Script:
{
Alter clone database open resetlogs;
}
executing Memory Script
database opened
Finished Duplicate Db at 05-DEC-24
RMAN>
5.6 目标端数据库校验
SQL> select dbid from v$database;
DBID
----------
548929043
SQL> show parameter name;
NAME TYPE VALUE
------------------------------- ----------- ------------------------------
db_file_name_convert string /u01/app/oracle/oradata/proddg
, /u01/app/oracle/oradata/prod
db_name string PROD
db_unique_name string PROD
global_names boolean FALSE
instance_name string prod
lock_name_space string
log_file_name_convert string /u01/app/oracle/oradata/proddg
, /u01/app/oracle/oradata/prod
service_names string PROD.enmotech.com
6、场景模拟
6.1 创建catalog目录库
前提条件:catalog目录库建在一台独立的 Oracle server 上。
- target database(source host: 192.168.94.102)
SYS@prod> col host_name for a20
SYS@prod> select instance_name, host_name, version, status, active_state, blocked from v$instance;
INSTANCE_NAME HOST_NAME VERSION STATUS ACTIVE_ST BLOCKED
---------------- -------------------- ----------------- ------------ --------- --------
prod enmotech1 11.2.0.1.0 OPEN NORMAL NO
- catalog database(target host: 192.168.94.103)
SQL> col host_name for a15
SQL> select instance_name, host_name, version, status, active_state, blocked from v$instance;
INSTANCE_NAME HOST_NAME VERSION STATUS ACTIVE_ST BLOCKED
---------------- --------------- ----------------- ------------ --------- --------
prod enmotech2 11.2.0.1.0 OPEN NORMAL NO
6.2 catalog database启动listener
目标端target host: 192.168.94.103,并且启动监听服务。
[oracle@enmotech2 ~]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-DEC-2024 06:20:12
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.94.103)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 04-DEC-2024 23:22:19
Uptime 0 days 6 hr. 57 min. 53 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/enmotech2/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.94.103)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=PNPKEY)))
Services Summary...
Service "PROD.enmotech.com" has 1 instance(s).
Instance "prod", status READY, has 1 handler(s) for this service...
Service "prod.enmotech2.com" has 1 instance(s).
Instance "prod", status UNKNOWN, has 1 handler(s) for this service...
Service "prodXDB.enmotech.com" has 1 instance(s).
Instance "prod", status READY, has 1 handler(s) for this service...
The command completed successfully
6.3 target database配置tnsnames.ora
源端source host: 192.168.94.102,配置tnsnames.ora,并且能够连接目标端数据库。
[oracle@enmotech1 ~]$ cat $ORACLE_HOME/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /u01/app/oracle/product/19.3.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
PROD = (DESCRIPTION=
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.94.102)(PORT = 1521))
(CONNECT_DATA=
(SERVICE_NAME=prod.enmotech1.com)
(SID=prod)))
aux = (DESCRIPTION=
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.94.103)(PORT = 1521))
(CONNECT_DATA=
(SERVICE_NAME=prod.enmotech2.com)
(SID=prod)))
测试源端数据库远程连接目标端数据库,且正常连接。
[oracle@enmotech1 ~]$ sqlplus sys/oracle@aux as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 5 10:56:26 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@aux> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@enmotech1 ~]$ sqlplus sys/oracle@192.168.94.103:1521/prod.enmotech2.com as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 5 10:57:14 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@192.168.94.103:1521/prod.enmotech2.com>
6.4 目标端数据库创建catalog所用表空间
[oracle@enmotech2 ~]$ sqlplus / as sysdba
SQL> create tablespace rmantbs02 datafile '/u01/app/oracle/oradata/prod/rmantbs02.dbf' size 50m autoextend on;
Tablespace created.
6.5 目标端数据库创建rman用户并授权
-- 创建用户
create user rman_two identified by rman_two default tablespace rmantbs02;
-- 授权
grant connect, resource, recovery_catalog_owner to rman_two;
6.6 在源端使用rman客户端连接到目标端catalog database
连接到恢复目录数据库
[oracle@enmotech1 ~]$ rman catalog rman_two/rman_two@aux
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 5 11:09:12 2024
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to recovery catalog database
RMAN>
6.7 创建catalog目录
在源端使用rman客户端工具,创建catalog目录
RMAN> create catalog;
recovery catalog created
目标端数据库
[oracle@enmotech2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 5 06:27:48 2024
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> conn rman_two/rman_two
Connected.
SQL> select table_name, tablespace_name from user_tables;
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
DB RMANTBS02
NODE RMANTBS02
CONF RMANTBS02
DBINC RMANTBS02
CKP RMANTBS02
TS RMANTBS02
TSATT RMANTBS02
DF RMANTBS02
SITE_DFATT RMANTBS02
TF RMANTBS02
SITE_TFATT RMANTBS02
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
OFFR RMANTBS02
RR RMANTBS02
RT RMANTBS02
ORL RMANTBS02
RLH RMANTBS02
AL RMANTBS02
BS RMANTBS02
BP RMANTBS02
BCF RMANTBS02
CCF RMANTBS02
XCF RMANTBS02
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
BSF RMANTBS02
BDF RMANTBS02
CDF RMANTBS02
XDF RMANTBS02
BRL RMANTBS02
BCB RMANTBS02
CCB RMANTBS02
SCR RMANTBS02
SCRL RMANTBS02
CONFIG RMANTBS02
XAL RMANTBS02
TABLE_NAME TABLESPACE_NAME
------------------------------ ------------------------------
RSR RMANTBS02
FB RMANTBS02
GRSP RMANTBS02
NRSP RMANTBS02
VPC_USERS RMANTBS02
VPC_DATABASES RMANTBS02
CFS RMANTBS02
BCR RMANTBS02
ROUT RMANTBS02
RCVER RMANTBS02
TEMPRES RMANTBS02
44 rows selected.
6.8 同时连接源端库和目标库
-- 源端
[oracle@enmotech1 ~]$ rman target / catalog rman_two/rman_two@aux
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 5 11:16:47 2024
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=548929043)
connected to recovery catalog database
RMAN>
-- 注册目标库
-- 在源端数据库注册目标库,把目标库控制文件中的rman信息同步到catalog里
RMAN> register database;
database registered in recovery catalog
starting full resync of recovery catalog
full resync complete
6.9 在目标端数据库,查看catalog库中注册的目标库信息
-- 目标端
SQL> conn rman_two/rman_two
Connected.
SQL> select * from rc_database;
DB_KEY DBINC_KEY DBID NAME RESETLOGS_CHANGE# RESETLOGS
---------- ---------- ---------- -------- ----------------- ---------
2 4 548929043 PROD 3691845 25-NOV-24
6.10 catalog目录库存储rman备份脚本
脚本分为global和local两种:
- 1)global script:所有target都可以共享
- 2)local script:只有连接的target使用
相关脚本的命令:
create [global] script
replace [global] script
print [global] script
list [global] script names
exectue [global] script names
delete [global] script names
同时登陆目标库、catalog库
-- 源端
[oracle@enmotech1 ~]$ rman target / catalog rman_two/rman_two@aux
Recovery Manager: Release 11.2.0.1.0 - Production on Thu Dec 5 11:16:47 2024
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
connected to target database: PROD (DBID=548929043)
connected to recovery catalog database
RMAN>
创建脚本
-- 源端
RMAN> create global script rmanbak{
backup database format '/u01/backup/rman/db_%U.bak'
include current controlfile plus archivelog format '/u01/backup/rman/ar_%U.bak';
}
created global script rmanbak
查看脚本名称
-- 源端
RMAN> list script names;
List of Stored Scripts in Recovery Catalog
Global Scripts
Script Name
Description
-----------------------------------------------------------------------
rmanbak
查看脚本内容
-- 源端
RMAN> print script rmanbak;
printing stored global script: rmanbak
{
backup database format '/u01/backup/rman/db_%U.bak'
include current controlfile plus archivelog format '/u01/backup/rman/ar_%U.bak';
}
执行脚本
-- 源端
RMAN> run{execute script rmanbak;}
7、友好配置
从主库(源端服务器)找到rlwrap的安装目录及bin目录,然后scp远程传输:
# cd /usr/bin
# pwd
/usr/bin
# scp ./rlwrap 192.168.94.103:/usr/bin
# cd /usr/share
# pwd
/usr/share
# scp -r rlwrap/ 192.168.94.103:/usr/share/
目标库.bash_profile 文件:
$ vi .bash_profile
#.bash_profile文件添加如下内容
alias sqlplus='rlwrap sqlplus'
alias rman='rlwrap rman'
(:wq)
#使.bash_profile文件生效
$ . .bash_profile
编辑修改glogin.sql文件:
$ vi $ORACLE_HOME/sqlplus/admin/glogin.sql
#添加如下内容
set linesize 120
set pagesize 999
define _editer=vi
set sqlprompt "_user'@'_connect_identifier> "
参考资料:
1)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?