本文介绍如何使用ontape命令将老环境中的gbase8s数据库迁移到新环境中,该迁移方法仅适用于同版本GBase8s数据库
1.新环境中安装数据库软件
1.1.创建gbasedbt用户、组。
[root@gbase153 ~]# groupadd gbasedbt
[root@gbase153 ~]# useradd -g gbasedbt -d /home/gbasedbt -s /bin/bash -m gbasedbt
[root@gbase153 ~]# passwd gbasedbt
1.2.操作系统参数设置
系统中需要有jdk、unzip
--设置nsswitch
sed -i "s#^hosts.*#hosts: files#g" /etc/nsswitch.conf
--设置限制参数
cat <<! >>/etc/security/limits.conf
* soft nproc 65536
* hard nproc 65536
* soft nofile 1048576
* hard nofile 1048576
!
--防火墙开数据库端口
firewall-cmd --permanent --zone=public --add-port=9088/tcp
firewall-cmd --reload
--或者禁用防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
--关闭 selinux
sed -i "s#^SELINUX=.*#SELINUX=disabled#g" /etc/selinux/config
--临时关闭 selinux
setenforce 0
vim /etc/systemd/logind.conf
RemoveIPC=no
# 重启服务或重启操作系统
systemctl daemon-reload
systemctl restart systemd-logind.service
--安装数据库报错,提示.so 文件缺少,一般在麒麟操作系统上会遇到这个问题
cd /usr/lib64
ln -s libnsl.so.2 libnsl.so.1
cd /lib64
ln -s libncurses.so.6.1 libncurses.so.5
ln -s libtinfo.so.6.1 libtinfo.so.5
1.3.静默安装数据库软件
./ids_install -i silent -DLICENSE_ACCEPTED=TRUE -DUSER_INSTALL_DIR=/opt/gbase
2.原环境备份
2.1.源库使用ontape命令备份数据库
请确认gbase_backup目录权限为775,且属主为gbasedbt
ontape -s -L 0 -t /data/gbase_backup/
[gbasedbt@gbase152 gbase_backup]$ ontape -s -L 0 -t /data/gbase_backup/
Your evaluation license will expire on 2025-01-01 00:00:00
10 percent done.
20 percent done.
30 percent done.
40 percent done.
100 percent done.
File created: /data/gbase_backup/gbase152_13_L0
Please label this tape as number 1 in the arc tape sequence.
This tape contains the following logical logs:
885 - 890
Program over.
2.2.原环境拷贝参数信息到新环境
2.2.1.将原环境中用户环境变量参数拷贝到新环境中
一般在~/.bash_profile中查看
su – gbasedbt
vi ~/.bash_profile
将如下参数拷贝到新环境的gbasedbt用户环境变量中,如果该文件中只有source /home/gbasedbt/profile.gbase02,则参数信息写在profile.gbase02文件中。
export GBASEDBTSERVER=gbase02
export GBASEDBTDIR=/opt/gbase
export GBASEDBTSQLHOSTS=/opt/gbase/etc/sqlhosts.gbase02
export ONCONFIG=onconfig.gbase02
export PATH=/opt/gbase/bin:$PATH
export GL_DATETIME='%Y-%m-%d %H:%M:%S'
export GL_DATE='%Y-%m-%d'
export USE_DTENV=1
export DBACCESS_SHOW_TIME=1
export DB_LOCALE=zh_CN.utf8
export CLIENT_LOCALE=zh_CN.utf8
export DBACCESS_SHOW_TIME=1
export GL_USEGLU=1
2.2.2.创建数据文件目录并授权
首先查看源数据库实例的数据文件存放位置,需要保持一致
onstat -d
Chunks
address chunk/dbs offset size free bpages flags pathname
4d200258 1 1 0 102400 68941 PO-B-- /opt/gbase/gbase02_dbs/rootdbschk001
4d201028 1 1 0 102400 0 MO-B-- /opt/gbase/gbase02_dbs/rootdbsmirrorchk001
51bfb028 2 2 0 2232320 52267 PO-B-- /opt/gbase/gbase02_dbs/llogdbschk001
51bfc028 3 3 0 2232320 65347 PO-B-- /opt/gbase/gbase02_dbs/plogdbschk001
51bfd028 4 4 0 461824 422066 430665 POSB-- /opt/gbase/gbase02_dbs/sbspace01chk001
Metadata 31106 23147 31106
51bfe028 5 5 0 57728 57675 PO-B-- /opt/gbase/gbase02_dbs/tmpdbs01chk001
51c04028 6 6 0 701849 183837 PO-BE- /opt/gbase/gbase02_dbs/datadbs01chk001
51c05028 7 7 0 1280 1203 PO-B-- /opt/gbase/gbase02_dbs/datadbs02chk001
51c06028 8 8 0 1280 1187 PO-B-- /opt/gbase/gbase02_dbs/datadbs03chk001
51c07028 9 9 0 1280 1191 PO-B-- /opt/gbase/gbase02_dbs/datadbs04chk001
51c08028 10 10 0 1280 1227 PO-B-- /opt/gbase/gbase02_dbs/datadbs05chk001
51c09028 11 11 0 1024000 973947 PO-B-- /opt/gbase/gbase02_dbs/llogdbschk002
51c0a028 12 6 0 12500 12497 PO-B-- /opt/gbase/gbase02_dbs/datadbs01chk002
51c0b028 13 12 0 64000 62418 PO-B-- /opt/gbase/gbase02_dbs/datadir/erdbspace
51c0c028 14 13 0 512000 477464 477465 POSB-- /opt/gbase/gbase02_dbs/datadir/ersbspace
Metadata 34482 25659 34482
51c0d028 15 14 0 12500 12447 PO-B-- /data/gbase/datadbschk06001
51c0e028 16 15 0 10240 9475 9475 POSB-- /opt/gbase/gbase02_dbs/sbtempspace01chk001
在新环境中创建数据文件存放目录
上面的结果集中存在三个数据目录
/opt/gbase/gbase02_dbs
/opt/gbase/gbase02_dbs/datadir
/data/gbase
--root用户执行
mkdir -p /data/gbase
mkidr -p /opt/gbase/gbase02_dbs/datadir
chown -R gbasedbt:gbasedbt /data/gbase
chown -R gbasedbt:gbasedbt /opt/gbase/gbase02_dbs
chown -R gbasedbt:gbasedbt /opt/gbase/gbase02_dbs/datadir
chmod -R 775 /data/gbase
chmod -R 775 /opt/gbase/gbase02_dbs
chmod -R 775 /opt/gbase/gbase02_dbs/datadir
2.2.3.创建数据文件并授660权限(gbasedbt用户操作)
cd /data/gbase/
touch touch datadbschk06001
chmod 660 datadbschk06001
cd /opt/gbase/gbase02_dbs/
touch datadbs01chk001 datadbs03chk001 datadbs06chk001 llogdbschk001 plogdbschk001 sbspace01chk001
touch datadbs01chk002 datadbs04chk001 llogdbschk002 rootdbschk001 sbtempspace01chk001 tmpdbs01chk001
chmod 660 *chk*
mkdir datadir
cd datadir/
touch erdbspace ersbspace
chmod 660 erdbspace ersbspace
2.2.4.拷贝参数文件
根据环境变量信息中的配置参数,将数据库配置文件和监听配置文件拷贝到新环境对应目录下
--数据库配置文件所在目录(在GBASEDBTDIR下的etc目录中,文件名是ONCONFIG)
/opt/gbase/etc/onconfig.gbase02
--监听配置文件所在目录
/opt/gbase/etc/sqlhosts.gbase02
直接拷贝或者scp到新环境的对应目录下
cd /opt/gbase/etc
scp -r onconfig.gbase02 sqlhosts.gbase02 192.168.31.153:$PWD
修改sqlhosts.gbase02中的ip为新环境的ip
vi /opt/gbase/etc/sqlhosts.gbase02
gbase02 onsoctcp 192.168.31.153 9099
如果环境中存在udr外部函数,需要将udr外部函数的jar一并拷贝到新的环境中对应的目录下
scp -r udr/ 192.168.31.153:$PWD
将ontape备份文件拷贝至新环境
scp -r gbase152_13_L0 192.168.31.153:/home/gbasedbt/
3.新环境还原数据库
3.1.还原数据库备份
su – gbasedbt
执行还原命令
ontape -r -t /home/gbasedbt/gbase152_13_L0
ontape -r -t /home/gbasedbt/gbase152_13_L0
Please mount tape 1 on gbase152_13_L0 and press Return to continue ... --回车
Continue restore? (y/n) y
Do you want to back up the logs? (y/n) n
Restore a level 1 archive (y/n) n
Do you want to restore log tapes? (y/n)n
Program over.
3.2.数据库转成在线模式
onmode -m
[gbasedbt@gbase153 ~]$ onstat -
Your evaluation license will expire on 2025-09-07 00:00:00
Quiescent -- Up 00:06:53 -- 4275148 Kbytes
[gbasedbt@gbase153 ~]$ onmode -m
Your evaluation license will expire on 2025-09-07 00:00:00
[gbasedbt@gbase153 ~]$ onstat -
Your evaluation license will expire on 2025-09-07 00:00:00
On-Line -- Up 00:07:01 -- 4275148 Kbytes
完成数据库的备份还原操作。
3.3.检查数据库
检查外部函数是否正常显示。
检查数据库是否正常重启。
原创文章,作者:kirin,如若转载,请注明出处:https://blog.ytso.com/tech/bigdata/318094.html