首页 > 其他分享 >openGauss中使用gs_initdb时保留旧配置

openGauss中使用gs_initdb时保留旧配置

时间:2024-04-17 11:47:08浏览次数:17  
标签:gs -- initdb new openGauss data dir

openGauss 中使用 gs_initdb 时保留旧配置
一、使用场景
该需求来源于社区 issue: 重建库脚本。

在开发过程中,可能会修改系统表,或者各种 debug 情况下导致的库坏掉的情况,建议增加一种重建数据库的脚本。

当前可以通过重新安装或 gs_initdb 建一个新库解决该问题,但用户觉得重装比较麻烦,而使用 gs_initdb 的话因为需要指定一个全新的空目录作为新的数据目录,如果原始是用 OM 安装的数据库,默认启用了 SSL,这时用 gs_initdb 新建的库目录下没有 SSL 相关配置,启动就会失败,需要手动把原来的 SSL 相关证书文件再拷贝过来。

为方便有该需求的用户使用,写了一个脚本,可以指定旧的数据目录,调用 gs_initdb 后,自动把旧数据目录下的配置文件拷贝到新目录下面

二、脚本说明
使用说明如下:

上传到数据库用户的目录下,比如/home/omm;

添加执行权限 chmod +x gs_initdb_withconf.sh;

执行前导一下环境变量,确保 gs_initdb 可以正常执行,如果是环境变量分离安装的方式,也需要 source 一下,比如 source ~/.bashrc 或自定义的环境变量;

执行方式为 ./gs_initdb_withconf.sh -o old_data_dir new_data_dir --nodename=example_node;

其实在-o old_data_dir 之后的参数即 gs_initdb 的参数,会直接传给 gs_initdb;

!/bin/bash

-------------------------------------------------------------------------

gs_initdb_withconf.sh

script to initdb with ability to backup and restore the old configuration files

-------------------------------------------------------------------------

#######################################################################

#######################################################################
function print_help()
{
echo "Usage:
gs_initdb_withconf [-o OLDDDATADIR] [OPTION]... [DATADIR]

Options:
-A, --auth=METHOD default authentication method for local connections
--auth-host=METHOD default authentication method for local TCP/IP connections
--auth-local=METHOD default authentication method for local-socket connections
[-D, --pgdata=]DATADIR location for this database cluster
--nodename=NODENAME name of single node initialized
-E, --encoding=ENCODING set default encoding for new databases
--locale=LOCALE set default locale for new databases
--dbcompatibility=DBCOMPATIBILITY set default dbcompatibility for new database
--lc-collate=, --lc-ctype=, --lc-messages=LOCALE
--lc-monetary=, --lc-numeric=, --lc-time=LOCALE
set default locale in the respective category for
new databases (default taken from environment)
--no-locale equivalent to --locale=C
--pwfile=FILE read password for the new system admin from file
-T, --text-search-config=CFG
default text search configuration
-U, --username=NAME database system admin name
-W, --pwprompt prompt for a password for the new system admin
-w, --pwpasswd=PASSWD get password from command line for the new system admin
-C, --enpwdfiledir=DIR get encrypted password of AES128 from cipher and rand file
-X, --xlogdir=XLOGDIR location for the transaction log directory
-S, --security remove normal user's privilege on public schema in security mode

Less commonly used options:
-d, --debug generate lots of debugging output
-L DIRECTORY where to find the input files
-n, --noclean do not clean up after errors
-s, --show show internal settings
-o, --olddir set the old data directory for backup and restore the old configuration file and cert file

Other options:
-H, --host-ip node_host of Postgres-XC node initialized
-V, --version output version information, then exit
-h, --help show this help, then exit
"
}

if [ $# = 0 ] ; then
echo "missing option"
print_help
exit 1
fi

para_for_initdb_t=$*
new_data_dir=""

while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
print_help
exit 1
;;
-o|--olddir)
if [ "$2"X = X ]; then
echo "no given the old data directory values"
exit 1
fi
old_data_dir=$2
shift 2
;;
-D)
if [ "$2"X = X ]; then
echo "no given the new data directory values"
exit 1
fi
new_data_dir=$2
shift 2
;;
--pgdata=)
tmp=$1
if [ ${tmp/--pgdata=/}X = X ]; then
echo "no given the new data directory values"
exit 1
fi
new_data_dir=${tmp/--pgdata=/}
shift 1
;;
-X)
if [ "$2"X = X ]; then
echo "no given the new xlog directory values"
exit 1
fi
shift 2
;;
-C)
if [ "$2"X = X ]; then
echo "no given the new AES128 encrypted password directory values"
exit 1
fi
shift 2
;;
-L)
if [ "$2"X = X ]; then
echo "no given the new shared directory values"
exit 1
fi
shift 2
;;
/
)
if [ "${new_data_dir}"X = X ]; then
new_data_dir=$1
fi
shift 1
;;
*)
shift 1
esac
done

if [ "${old_data_dir}"X = X ]; then
echo "no given the old data directory values"
exit 1
fi
if [ "${new_data_dir}"X = X ]; then
echo "no given the new date directory values"
exit 1
fi
if [ ! -d "${old_data_dir}" ]; then
echo "the old data directory doesn't exist!"
exit 1
fi

para_for_initdb=${para_for_initdb_t/-o ${old_data_dir}/}

if [ "${para_for_initdb}"X = X ]; then
echo "no given the parameters of gs_initdb, exit"
exit 1
fi

declare -a file_list=("cacert.pem" "server.crt" "server.key" "server.key.cipher" "server.key.rand"
"postgresql.conf" "mot.conf" "pg_ident.conf" "pg_hba.conf")
declare -a new_file_list

function check_file()
{
for e in ${file_list[@]}
do
if [ ! -f "${old_data_dir}/$e" ]; then
echo "${old_data_dir}/$e doesn't exist! Will not copy it!"
continue
fi
new_file_list[${#new_file_list[*]}]=${old_data_dir}/$e
done
}

function copy_file()
{
for e in ${new_file_list[@]}
do
cp -p $e ${new_data_dir}
if [ $? -ne 0 ]; then
echo "copy $e to ${new_data_dir} failed."
fi
done
}

check_file
which gs_initdb >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "can't find gs_initdb command. please import the env first!"
fi
gs_initdb ${para_for_initdb}
if [ $? -ne 0 ]; then
echo "gs_initdb failed! exit!"
exit 1
fi
copy_file
echo "run gs_initdb_withconf finished!"

标签:gs,--,initdb,new,openGauss,data,dir
From: https://www.cnblogs.com/helloopenGauss/p/18140218

相关文章

  • Debezium Adapt openGauss
    DebeziumAdaptopenGaussWhatisDebeziumDebeziumisasetofdistributedservicestocapturechangesinyourdatabasessothatyourapplicationscanseethosechangesandrespondtothem.Debeziumrecordsallrow-levelchangeswithineachdatabasetable......
  • 浅谈关于openGauss的相关理论
    浅谈关于openGauss的相关理论概述openGauss是一款开源的关系型数据库管理系统,它具有多核高性能、全链路安全性、智能运维等企业级特性。openGauss内核早期源自开源数据库PostgreSQL9.2,融合了华为在数据库领域多年的内核经验,在架构、事务、存储引擎、优化器及ARM架构上进......
  • openGauss+KeepAlived
    openGauss+KeepAlived实验环境操作系统:CentOS7.6数据库版本:openGauss1.1.0Primary主机/IP:opengaussdb1/...1(openGauss主备已部署完毕)Standby主机/IP:opengaussdb2/...2(openGauss主备已部署完毕)说明:不建议在云环境(如:华为云)下搭建Keepalived进行测试,本人在......
  • openGauss主备切换之switchover与failover
    openGauss主备切换之switchover与failoverswitchover在主备机正常时,出于维护的需要,将备机切换为主机,可保证切换过程中数据不丢失。查看集群实例主备状态:1节点为主库,2节点为备库。$gs_om-tstatus--detail[ClusterState]cluster_state:Normalredistribu......
  • openGauss在kubernetes集群环境上的部署
    opengauss实践总结学习心openGauss是一款开源关系型数据库管理系统,深度融合华为在数据库领域多年的经验,结合企业级场景需求,持续构建竞争力特性;kubernetes也是一个开源的,用于管理云平台中多个主机上的容器化的应用,Kubernetes的目标是让部署容器化的应用简单并且高效,Kuber......
  • 如何使用pgloader迁移MySQL数据库至openGauss
    pgloader介绍pgloader是一个数据导入工具,使用COPY命令将数据导入到PostgreSQL。pgloader有两种工作模式,一种是从文件导入,一种是迁移数据库。pgloader在两种情况下都使用PostgreSQL的COPY协议高效的传输数据。openGauss兼容PostgreSQL的通信协议以及绝大部分语法,可......
  • Settings属性读写
    Settings系统属性存储均为xml,分三种:1.global:所有的偏好设置对系统的所有用户公开,第三方APP有读没有写的权限;对应xml路径:/data/system/users/0/settings_global.xmladb指令读写方法:先adbshell进入终端。读为settingsgetglobal系统属性key写为settingsputglobal系统属......
  • SpringBoot+SpringSecurity6+Jwt最小化代码
    SpringBoot+SpringSecurity6+Jwt最小化代码[toc]零、参考资料https://blog.csdn.net/m0_71273766/article/details/132942056一、快速开始1.1、引入依赖<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0&quo......
  • 80、SpringBoot3 SpringSecurity Mybatisplus最新版 整合 实现登入权限控制
    1、导入pom依赖<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apac......
  • [题解][2021-2022年度国际大学生程序设计竞赛第10届陕西省程序设计竞赛] Type The Str
    题目描述给定n个字符串,有以下几种操作:打出一个字符,花费1。删除一个字符,花费1。复制并打出一个之前打出过的字符串,花费k。求打出所有n个字符串的最小花费。(注意,打出顺序和字符串输入的顺序不必相同)题解显然,操作3需要算字符串的最长公共子序列来处理。这个问题可以转换为......