MogDB工具—gs_backup
背景信息
MogDB部署成功后,在数据库运行的过程中,会遇到各种问题及异常状态。MogDB提供了gs_backup工具帮助MogDB备份、恢复重要数据、显示帮助信息和版本号信息。
gs_backup是一个用于备份或恢复二进制文件和参数文件的实用程序。
前提条件
-
可以正常连接MogDB数据库。
-
在进行还原时,需要保证各节点备份目录中存在备份文件。
-
需以操作系统用户omm执行gs_backup命令。
参数说明
[omm@lxs1 ~]$ gs_backup --help gs_backup is a utility to back up or restore binary files and parameter files. Usage: gs_backup -? | --help gs_backup -V | --version gs_backup -t backup --backup-dir=BACKUPDIR [-h HOSTNAME] [--parameter] [--binary] [--all] [-l LOGFILE] gs_backup -t restore --backup-dir=BACKUPDIR [-h HOSTNAME] [--parameter] [--binary] [--all] [-l LOGFILE] [--force] General options: -t Operation type. It can be backup or restore. --backup-dir=BACKUPDIR Backup or restore directory. -h The node which stored the backup file, need to specify the node when recovering. If the node name is not specified, the backup sets are stored in each node. --parameter Back up or restore parameter files only. (This option is used by default.) --binary Back up or restore binary files only. --all Back up or restore both parameter files and binary files. --force Force to restore binary files even if the cluster_static_config is lost -l Path of log file. -?, --help Show help information for this utility, and exit the command line mode. -V, --version Show version information. [omm@lxs1 ~]$
gs_backup参数可以分为如下几类:
-
备份数据库主机参数:
-
-h
指定存储备份文件的主机名称。
取值范围: 主机名称。如果不指定主机名称,则备份当前集群。
-
–backup-dir=BACKUPDIR
备份文件保存路径。
-
–parameter
备份参数文件,不指定–parameter、–binary、–all参数时默认只备份参数文件。
-
–binary
备份app目录下的二进制文件。
-
–all
备份app目录下的二进制文件、pg_hba.conf和postgsql.conf文件。
-
-l
指定日志文件及存放路径。
默认值:$GAUSSLOG/om/gs_backup-YYYY-MM-DD_hhmmss.log
-
-
恢复数据库主机参数:
-
-h
指定需要恢复主机的名称。
取值范围: 主机名称。如果不指定主机,则恢复对应的备份节点。
-
–backup-dir=BACKUPDIR
恢复文件提取路径。
-
–parameter
恢复参数文件,不指定–parameter、–binary、–all参数时默认只恢复参数文件。
-
–binary
恢复二进制文件。
-
–all
恢复二进制和参数文件。
-
-l
指定日志文件及存放路径。
默认值:$GAUSSLOG/om/gs_backup-YYYY-MM-DD_hhmmss.log
-
–force
节点的静态文件丢失之后强行restore,仅限–all或者–binary参数使用时才生效。
-
-
其他参数:
-
-?, --help
显示帮助信息。
-
-V, --version
显示版本号信息。
-
-t
指定操作类型。
取值范围: backup或者restore。
-
语法
-
备份数据库主机
gs_backup -t backup --backup-dir=BACKUPDIR [-h HOSTNAME] [--parameter] [--binary] [--all] [-l LOGFILE]恢复数据库主机
gs_backup -t restore --backup-dir=BACKUPDIR [-h HOSTNAME] [--parameter] [--binary] [--all] [-l LOGFILE] [--force]显示帮助信息
gs_backup -? | --help显示版本号信息
gs_backup -V | --version
演示
备份
集群环境
[omm@lxs1 ~]$ gs_om -t status --detail [ Cluster State ] cluster_state : Normal redistributing : No current_az : AZ_ALL [ Datanode State ] nodenode_ip port instance state ------------------------------------------------------------------------------- 1 lxs1 192.168.60.101 26000 6001 /opt/mogdb/data P Primary Normal 2 lxs2 192.168.60.102 26000 6002 /opt/mogdb/data S Standby Normal 3 lxs3 192.168.60.103 26000 6003 /opt/mogdb/data C Cascade Normal [omm@lxs1 ~]$
创建备份目录
[omm@lxs1 ~]$ mkdir backup [omm@lxs1 ~]$ ls -l backup/ total 0 [omm@lxs1 ~]$
默认参数备份
1)可以看到默认参数备份,则备份整个集群所有节点的参数文件。
2)没有指定主机的情况下,所有节点均有生成备份数据。
[omm@lxs1 ~]$ gs_backup -t backup --backup-dir /home/omm/backup Hint:Parameters '--parameter','--binary',and '--all' were not specified. Only parameter files will be backed up. Parsing configuration files. Successfully parsed the configuration file. Performing remote backup. Remote backup succeeded. Successfully backed up cluster files. [omm@lxs1 ~]$ cd backup/ [omm@lxs1 backup]$ ll total 160 -rw-------. 1 omm omm 163840 Dec 5 21:41 parameter.tar [omm@lxs1 backup]$ tar -xvf parameter.tar parameter_lxs1.tar parameter_lxs2.tar parameter_lxs3.tar [omm@lxs1 backup]$ tar -xvf parameter_lxs1.tar parameter_lxs1/ parameter_lxs1/HOSTNAME parameter_lxs1/6001_postgresql.conf parameter_lxs1/6001_pg_hba.conf [omm@lxs1 backup]$ ll total 316 drwx------. 2 omm omm 74 Dec 5 21:41 parameter_lxs1 -rw-------. 1 omm omm 51200 Dec 5 21:41 parameter_lxs1.tar -rw-------. 1 omm omm 51200 Dec 5 21:41 parameter_lxs2.tar -rw-------. 1 omm omm 51200 Dec 5 21:41 parameter_lxs3.tar -rw-------. 1 omm omm 163840 Dec 5 21:41 parameter.tar [omm@lxs1 backup]$ ll parameter_lxs1/ total 48 -rw-------. 1 omm omm 4783 Dec 3 00:04 6001_pg_hba.conf -rw-------. 1 omm omm 35003 Dec 3 00:04 6001_postgresql.conf -rw-------. 1 omm omm 4 Dec 5 21:41 HOSTNAME [omm@lxs1 backup]$ --lxs2: [omm@lxs2 backup]$ ll total 160 -rw-------. 1 omm omm 163840 Dec 5 22:02 parameter.tar [omm@lxs2 backup]$ tar -xvf parameter.tar parameter_lxs1.tar parameter_lxs2.tar parameter_lxs3.tar [omm@lxs2 backup]$ --lxs3: [omm@lxs3 backup]$ ll total 160 -rw-------. 1 omm omm 163840 Dec 5 22:02 parameter.tar [omm@lxs3 backup]$ tar -xvf parameter.tar parameter_lxs1.tar parameter_lxs2.tar parameter_lxs3.tar [omm@lxs3 backup]$
指定主机备份数据
1)可以发现指定主机后,备份数据则生成在指定主机的目录上,而非是执行备份的主机上。
2)指定备份binary二进制数据后,备份了指定主机节点的二进制数据。
[omm@lxs1 ~]$ gs_backup -t backup --backup-dir /home/omm/backup -h lxs2 --binary Parsing configuration files. Successfully parsed the configuration file. Performing remote backup. Remote backup succeeded. Successfully backed up cluster files. [omm@lxs1 ~]$ --lxs2: [omm@lxs2 backup]$ ll total 330592 -rw-------. 1 omm omm 338524160 Dec 5 22:05 binary.tar [omm@lxs2 backup]$ tar -xvf binary.tar binary_lxs2.tar [omm@lxs2 backup]$ tar -xvf binary_lxs2.tar app/ app/bin/ app/bin/gsql app/bin/gs_tar app/bin/gs_dump app/bin/cluster_guc.conf .......... app/logs/ app/logs/eSDK-OBS-API-Linux-C.interface.log app/logs/eSDK-OBS-API-Linux-C.operation.log app/logs/eSDK-OBS-API-Linux-C.run.log [omm@lxs2 backup]$ ll total 661172 drwx------. 10 omm omm 130 Dec 3 00:04 app -rw-------. 1 omm omm 338513920 Dec 5 22:05 binary_lxs2.tar -rw-------. 1 omm omm 338524160 Dec 5 22:05 binary.tar [omm@lxs2 backup]$
指定主机备份全部并生成日志
1)指定主机后,在指定主机上生成备份数据。
2)指定备份参数为all时,只备份了指定主机的二进制文件、pg_hba.conf和postgsql.conf文件。
3)指定日志目录后,在执行备份主机上生成备份日志,在指定主机上同样生成备份日志,但是日志名称不是-l指定的名称。
[omm@lxs1 ~]$ gs_backup -t backup --backup-dir /home/omm/backup -h lxs3 --all -l /home/omm/backup/backup.log Parsing configuration files. Successfully parsed the configuration file. Performing remote backup. Remote backup succeeded. Successfully backed up cluster files. [omm@lxs1 ~]$ cd backup/ [omm@lxs1 backup]$ ll total 4 -rw-------. 1 omm omm 2201 Dec 5 22:07 backup-2022-12-05_220727.log [omm@lxs1 backup]$ --lxs3: [omm@lxs3 ~]$ cd backup/ [omm@lxs3 backup]$ ll total 330656 -rw-------. 1 omm omm 338524160 Dec 5 21:54 binary.tar -rw-------. 1 omm omm 3022 Dec 5 21:54 gs_local-2022-12-05_215432.log -rw-------. 1 omm omm 61440 Dec 5 21:54 parameter.tar [omm@lxs3 backup]$ tar -xvf binary.tar binary_lxs3.tar [omm@lxs3 backup]$ [omm@lxs3 backup]$ tar -xvf parameter.tar parameter_lxs3.tar [omm@lxs3 backup]$
恢复
恢复参数文件
[omm@lxs3 ~]$ ll backup/ total 330652 -rw-------. 1 omm omm 338524160 Dec 5 22:07 binary.tar -rw-------. 1 omm omm 61440 Dec 5 22:07 parameter.tar [omm@lxs3 ~]$ ll /opt/mogdb/data/postgresql.conf /opt/mogdb/data/pg_hba.conf -rw-------. 1 omm omm 4783 Dec 3 01:25 /opt/mogdb/data/pg_hba.conf -rw-------. 1 omm omm 34988 Dec 3 00:04 /opt/mogdb/data/postgresql.conf [omm@lxs3 ~]$ rm -rf /opt/mogdb/data/postgresql.conf /opt/mogdb/data/pg_hba.conf [omm@lxs3 ~]$ ll /opt/mogdb/data/postgresql.conf /opt/mogdb/data/pg_hba.conf ls: cannot access /opt/mogdb/data/postgresql.conf: No such file or directory ls: cannot access /opt/mogdb/data/pg_hba.conf: No such file or directory [omm@lxs3 ~]$ [omm@lxs3 ~]$ gs_backup -t restore --backup-dir /home/omm/backup -h lxs3 --parameter -l /home/omm/backup/backup.log Parsing configuration files. Successfully parsed the configuration file. Performing remote restoration. Successfully restored cluster files. [omm@lxs3 ~]$ ll /opt/mogdb/data/postgresql.conf /opt/mogdb/data/pg_hba.conf -rw-------. 1 omm omm 4783 Dec 3 01:25 /opt/mogdb/data/pg_hba.conf -rw-------. 1 omm omm 34988 Dec 3 00:04 /opt/mogdb/data/postgresql.conf [omm@lxs3 ~]$
恢复数据
在恢复过程中,直接恢复会报错[GAUSS-50201] : The static configuration file [/opt/mogdb/app/bin/cluster_static_config] of designated user [omm] does not exist.
1)使用force参数强制恢复
2)直接将备份的二进制文件cp到软件目录下,再次执行restore即可。
[omm@lxs3 ~]$ cd backup/ [omm@lxs3 backup]$ ll total 330660 drwx------. 10 omm omm 130 Dec 3 00:04 app -rw-------. 1 omm omm 2053 Dec 5 22:23 backup-2022-12-05_222333.log -rw-------. 1 omm omm 338524160 Dec 5 22:07 binary.tar -rw-------. 1 omm omm 2139 Dec 5 22:23 gs_local-2022-12-05_222334.log -rw-------. 1 omm omm 61440 Dec 5 22:07 parameter.tar [omm@lxs3 backup]$ [omm@lxs3 backup]$ rm -rf /opt/mogdb/app/ [omm@lxs3 backup]$ [omm@lxs3 backup]$ gs_backup -t restore --backup-dir /home/omm/backup -h lxs3 --binary Parsing configuration files. [GAUSS-50201] : The static configuration file [/opt/mogdb/app/bin/cluster_static_config] of designated user [omm] does not exist. [omm@lxs3 backup]$ gs_backup -t restore --backup-dir /home/omm/backup -h lxs3 --binary --force Parsing configuration files. Successfully init restore nodename: lxs3. Performing remote restoration. Successfully restored cluster files. [omm@lxs3 backup]$ [omm@lxs3 backup]$ cd /opt/mogdb/ [omm@lxs3 mogdb]$ ll total 8 drwx------. 10 omm omm 130 Dec 5 22:49 app drwx------. 20 omm omm 4096 Dec 5 22:39 data drwx------. 10 omm omm 125 Dec 3 00:45 log drwxr-xr-x. 2 omm omm 263 Nov 16 17:34 mogha drwx------. 2 omm omm 104 Dec 5 22:49 tmp drwx------. 6 omm omm 4096 Dec 3 00:03 tool [omm@lxs3 mogdb]$ [omm@lxs3 mogdb]$ rm -rf /opt/mogdb/app/ [omm@lxs3 mogdb]$ cp -r app/ /opt/mogdb/ [omm@lxs3 mogdb]$ gs_backup -t restore --backup-dir /home/omm/backup -h lxs3 --binary Parsing configuration files. Successfully parsed the configuration file. Performing remote restoration. Successfully restored cluster files [omm@lxs3 mogdb]$ ll total 8 drwx------. 10 omm omm 130 Dec 5 22:49 app drwx------. 20 omm omm 4096 Dec 5 22:39 data drwx------. 10 omm omm 125 Dec 3 00:45 log drwxr-xr-x. 2 omm omm 263 Nov 16 17:34 mogha drwx------. 2 omm omm 104 Dec 5 22:49 tmp drwx------. 6 omm omm 4096 Dec 3 00:03 tool [omm@lxs3 mogdb]$




