已关闭
[Bug]: jdbcgsbackup导出导入序列不存在 #8462
liuzhen001创建于  18 天前关闭于  5 天前
liuzhen001
liuzhen001成员
18 天前 创建

测试类型

工具功能

测试版本

7.0.0LTS

问题描述

操作系统和硬件信息

image.png

测试环境

企业版主备

被测功能

预置条件

操作步骤

Opengauss_Function_JdbcGsBackup_Case0045
"""
Case Type : openGauss-tools-backup
Case Name : 使用jdbcpgbackup -m dump导出指定数据库下的序列
Description :
1.创建工具目录
2.获取工具安装包并解压
3.创建数据库
4.指定数据库下创建测试用户,创建序列
5.修改信任方式为sha256
6.导出指定数据库
7.删除序列后执行导入
8.查看序列
9.清理环境
Expect :
1.创建成功
2.解压成功
3.创建成功
4.创建成功
5.修改成功
6.导出成功
7.导入成功
8.序列导入成功
9.清理环境完成
"""
import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node
from yat.test import macro

class ToolsBackup(unittest.TestCase):
def setUp(self):
self.log = Logger()
self.pri_sh = CommonSH('PrimaryDbUser')
self.log.info(
'---Opengauss_Function_JdbcGsBackup_Case0045start---')
self.constant = Constant()
self.DB_ENV_PATH = macro.DB_ENV_PATH
self.Primary_Node = Node('PrimaryDbUser')
self.Root_Node = Node('PrimaryRoot')
self.package = os.path.join(
os.path.dirname(macro.DB_INSTANCE_PATH), 'package_tool')
self.db_name = "db_jdbcgsbackup_0045"
self.se_name = "se_jdbcgsbackup_0045"
self.user = "u_jdbcgsbackup_0045"
text = '备份pg_hba.conf文件'
self.log.info(text)
cmd = f"cp {os.path.join(macro.DB_INSTANCE_PATH, 'pg_hba.conf')} "
f"{os.path.join(macro.DB_INSTANCE_PATH, 'pg_hba.conf_t_bak')}"
self.log.info(cmd)
msg = self.Primary_Node.sh(cmd).result()
self.log.info(msg)

def test_tools_backup(self):
    text = '---step1:创建工具所在目录;expect:创建成功---'
    self.log.info(text)
    mkdir_cmd = f'''if [ ! -d "{self.package}" ]
                    then
                        mkdir -p {self.package}
                    fi'''
    self.log.info(mkdir_cmd)
    result = self.Primary_Node.sh(mkdir_cmd).result()
    self.log.info(result)
    result = self.Primary_Node.sh(mkdir_cmd).result()
    self.log.info(result)
    self.assertEqual(result, '', '执行失败:' + text)

    text = '---step2:获取openGauss-tools-backup工具包并解压;' \
           'expect:解压成功---'
    self.log.info(text)
    sql_cmd = f'''wget -P {self.package} {macro.PACKAGE_URL};
        cd {self.package};
        tar -zxvf openGauss-tools-backup.tar.gz;'''
    self.log.info(sql_cmd)
    result = self.Primary_Node.sh(sql_cmd).result()
    self.log.info(result)
    self.assertIn(f"‘{self.package}/openGauss-tools-backup.tar.gz’ saved"
                  , result, '执行失败:' + text)

    text = '---step3:创建数据库;expect:创建成功---'
    self.log.info(text)
    sql_cmd = self.pri_sh.execut_db_sql(f'''drop database if exists \
        {self.db_name};
        create database {self.db_name};''')
    self.log.info(sql_cmd)
    self.assertIn(self.constant.CREATE_DATABASE_SUCCESS, sql_cmd,
                  '执行失败:' + text)

    text = '---step4:创建测试用户,创建序列;expect:创建成功---'
    self.log.info(text)
    sql_cmd = f'''drop user if exists {self.user};
        create user {self.user} with sysadmin \
        password '{macro.COMMON_PASSWD}';
       drop sequence if exists {self.se_name};
       create sequence {self.se_name} start 101 cache 20;'''
    self.log.info(sql_cmd)
    sql_result = self.pri_sh.execut_db_sql(sql=sql_cmd,
                                           dbname=f'{self.db_name}')
    self.log.info(sql_result)
    self.assertIn(self.constant.CREATE_SEQUENCE_SUCCESS_MSG, sql_result,
                  '执行失败:' + text)
    self.assertIn(self.constant.CREATE_ROLE_SUCCESS_MSG, sql_result,
                  '执行失败:' + text)

    text = '---step5:修改信任方式为sha256;expect:修改成功---'
    self.log.info(text)
    cmd = f"grep -nr '127.0.0.1/32' " \
          f"{os.path.join(macro.DB_INSTANCE_PATH, 'pg_hba.conf')}"
    self.log.info(cmd)
    line = self.Primary_Node.sh(
        cmd).result().splitlines()[0].split(':')[0]
    self.log.info(line)
    cmd = f'sed -i "{str(int(line)+1)} ihost   all     all ' \
          f'{self.Primary_Node.db_host}/32   sha256" ' \
          f'{os.path.join(macro.DB_INSTANCE_PATH, "pg_hba.conf")}; ' \
          f'cat {os.path.join(macro.DB_INSTANCE_PATH, "pg_hba.conf")};'
    self.log.info(cmd)
    result = self.Primary_Node.sh(cmd).result()
    self.log.info(result)
    restart_msg = self.pri_sh.restart_db_cluster()
    self.log.info(restart_msg)
    status = self.pri_sh.get_db_cluster_status()
    self.assertTrue("Degraded" in status or "Normal" in status)
    self.assertIn(f'{self.Primary_Node.db_host}/32   sha256', result,
                  '执行失败:' + text)

    text = '---step6:导出;expect:导出成功---'
    self.log.info(text)
    sql_cmd = f'''cd {self.package}/openGauss-tools-backup;\
        java -jar openGauss-tools-backup.jar \
        -m dump \
        -d {self.db_name} \
        -h {self.Primary_Node.db_host} \
        -p {self.Primary_Node.db_port} \
        -U {self.user} \
        -P {macro.COMMON_PASSWD} \
        -s public '''
    self.log.info(sql_cmd)
    msg = self.Primary_Node.sh(sql_cmd).result()
    self.log.info(msg)
    self.assertIn(self.constant.jdbcgsbackup_success, msg,
                  '执行失败:' + text)
    self.assertNotIn(self.constant.jdbcgsbackup_failed[0] and
                     self.constant.jdbcgsbackup_failed[1] and
                     self.constant.jdbcgsbackup_failed[2], msg,
                     '执行失败:' + text)

    text = '---step7:删除序列执行导入;expect:导入成功---'
    self.log.info(text)
    sql_cmd = f'''drop sequence if exists {self.se_name};'''
    sql_result = self.pri_sh.execut_db_sql(sql=sql_cmd,
                                           dbname=f'{self.db_name}')
    self.log.info(sql_result)
    sql_cmd = f'''cd {self.package}/openGauss-tools-backup;\
        java -jar openGauss-tools-backup.jar \
        -m restore \
        -d {self.db_name} \
        -h {self.Primary_Node.db_host} \
        -p {self.Primary_Node.db_port} \
        -U {self.user} \
        -P {macro.COMMON_PASSWD} \
        -s public \
        -n public '''
    self.log.info(sql_cmd)
    msg = self.Primary_Node.sh(sql_cmd).result()
    self.log.info(msg)
    self.assertIn(self.constant.jdbcgsbackup_success, msg,
                  '执行失败:' + text)
    self.assertNotIn(self.constant.jdbcgsbackup_failed[0] and
                     self.constant.jdbcgsbackup_failed[1] and
                     self.constant.jdbcgsbackup_failed[2], msg,
                     '执行失败:' + text)

    text = '---step8:查询序列;expect:序列导入成功---'
    self.log.info(text)
    sql_cmd = f'''\d+ {self.se_name};'''
    sql_result = self.pri_sh.execut_db_sql(sql=sql_cmd,
                                           dbname=f'{self.db_name}')
    self.log.info(sql_result)
    self.assertIn(f'Sequence "public.{self.se_name}"', sql_result,
                  '执行失败:' + text)

def tearDown(self):
    text = '---step9:清理环境;expect:清理环境完成---'
    self.log.info(text)
    sql_cmd = f'''rm -rf {self.package};'''
    self.log.info(sql_cmd)
    result = self.Root_Node.sh(sql_cmd).result()
    self.log.info(result)
    cmd = f"rm -rf " \
          f"{os.path.join(macro.DB_INSTANCE_PATH, 'pg_hba.conf')};" \
          f"mv " \
          f"{os.path.join(macro.DB_INSTANCE_PATH, 'pg_hba.conf_t_bak')} " \
          f"{os.path.join(macro.DB_INSTANCE_PATH, 'pg_hba.conf')}"
    self.log.info(cmd)
    self.Primary_Node.sh(cmd)
    sql_cmd = self.pri_sh.execut_db_sql(f'''drop database if exists \
            {self.db_name};
            drop user if exists {self.user} cascade;''')
    self.log.info(sql_cmd)
    self.log.info(
        '---Opengauss_Function_JdbcGsBackup_Case0045finish---')

预期输出

实际输出

image.png

日志信息

image.png

提单组织

测试团队

测试代码

likedislike
liuzhen001liuzhen001成员
18 天前 添加了label:bug
liuzhen001liuzhen001成员
18 天前 关联了看板:openGauss 7.0.0-LTS
opengauss_bot
opengauss_bot成员
18 天前 评论:

Welcome To openGauss Community

Hey @liuzhen001 , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: StorageEngine, AI, CM, CloudNative, SecurityTechnology, SQLEngine ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @libiao2024, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @Igali, @bihua111, @cailei19, @h_ray, @levy53071, @libiao2024, @lihaixiao, @mrzack, @wangfeihuo, @wuyuechuan, @xiong_xjun, @zhangfengzhi123, @zhangxubo, @zhangzq131, @zjh_hw .

likedislike
opengauss_botopengauss_bot成员
18 天前 添加了label:sig/Tools
zhangxubozhangxubo成员
16 天前 关联了pull request:导入适配多个sequence类型
zhangxubo
zhangxubo成员
10 天前 评论:

20260909 B022自测:

create sequence aaaa start 101 cache 20;
create large sequence bbbb start 101 cache 20;

导出:
java -jar JdbcGsBackup.jar -m dump -d postgres -h 20.20.20.58 -p 27000 -U test -P Test@123 -s public -f test.zip

导入:
java -jar JdbcGsBackup.jar -m restore -d db2 -h 20.20.20.58 -p 27000 -U test -P Test@123 -s public -f test.zip

image.png

image.png

likedislike
zhangxubozhangxubo成员
10 天前 issue状态由 待办的 改变为 待回归
liuzhen001
liuzhen001成员
5 天前 评论:

回归版本:B023
回归结果:回归通过
回归过程:
image.png
image.png

likedislike
liuzhen001liuzhen001成员
5 天前 issue状态由 待回归 改变为 已验收
liuzhen001liuzhen001成员
5 天前 关闭了 issue