因为时不时要搭个oracle 的dataguard,想偷个懒,根据自己的一些理解做了一个自动配置环境,
自动rman duplicate 复制来实现搭建oracle dg 的小工具,工具目前还不是特别完善,希望圈内各位前辈多多指点,多踩踩,有兴趣的小伙伴可以一起完善完善;
autodg oracle dataguard 自动搭建小工具,目前只支持linux 平台,oracle11g 及以上版本
github代码连接:
功能参数使用说明
##check 参数 主库环境预检查
主要检查数据库版本是否大于11201
主库归档模式 & force_logging 是否开启
主库密码文件orapwd$sid是否存在
主库是否使用spfile
##prepare 参数 主库环境检查,主备环境初始化,自动搭建oracle dataguard
主库更新tnsnames.ora
下载主库tnsnames.ora,orapwd 密码文件
本地备库tnsnames.ora orapwd 文件同步
本地备库adump 等目录配置
本地备库listener.ora 初始化
本地备库pfile 初始化
本地备库启动到 nomount 状态
本地备库执行rman duplicate 命令
使用事项
4、配置 autodg 参数文件,config.toml 相关参数配置说明见 conf/config.toml
5、主库环境检查
$ ./autodg --config config.toml --mode check
6、自动配置dataguard 环境编辑,数据库同步备份等
$ ./autodg --config config.toml --mode prepare
prepare 模式
/* 数据库开启归档以及补充日志 */
-- 开启归档【必须选项】
alter database archivelog;
-- 强制日志【必须选项】
alter database force log ;
若直接在命令行中用 `nohup` 启动程序,可能会因为 sighup 信号而退出,建议把 `nohup` 放到脚本里面且不建议用 kill -9,如:
```shell
#!/bin/bash
nohup ./autodg -config config.toml --mode check > nohup.out &
check 参数执行日志如下:
[2022/06/01 14:17:02.877 08:00] [info] [server.go:197] ["check oracle dbversion"] [dbversion=11.2.0.4.0]
[2022/06/01 14:17:02.979 08:00] [info] [server.go:208] ["get oracle sid"] [sid=crm]
[2022/06/01 14:17:03.278 08:00] [info] [server.go:221] ["get oracle archived_mode"] [archived_mode=archivelog]
[2022/06/01 14:17:03.368 08:00] [info] [server.go:231] ["get oracle force_logging"] [force_logging=yes]
[2022/06/01 14:17:03.455 08:00] [info] [server.go:243] ["check oracle spfile status"] [spfile="there is a spfile"]
prepare 参数执行日志如下:
[2022/06/02 10:48:33.776 08:00] [info] [server.go:26] ["autodg--oracle dataguard autoconfig . 米乐app官网下载 copyright © 2022-2099 huanglinjie"]
[2022/06/02 10:48:36.854 08:00] [info] [server.go:35] ["prepare dg"] ["check primary db version "=]
[2022/06/02 10:48:36.854 08:00] [info] [oracle.go:96] ["get oracle rdbms_version start"]
[2022/06/02 10:48:36.920 08:00] [info] [oracle.go:103] ["get oracle rdbms_version finished"] [rdbms_version=11.2.0.4.0] [cmds="select value from nls_database_parameters where parameter='nls_rdbms_version'"] [cost=66.1735ms]
[2022/06/02 10:48:36.921 08:00] [info] [server.go:53] ["prepare dg"] ["get primary db oracle_sid"=]
[2022/06/02 10:48:36.921 08:00] [info] [oracle.go:14] ["get oracle oracle_sid start"]
[2022/06/02 10:48:36.998 08:00] [info] [oracle.go:23] ["get oracle oracle_sid finished"] [cmds="select value from v$parameter where name='instance_name'"] [cost=77.009ms]
[2022/06/02 10:48:36.998 08:00] [info] [server.go:60] ["prepare dg"] ["get primary db db_name"=]
[2022/06/02 10:48:36.998 08:00] [info] [oracle.go:33] ["get oracle db_name start"]
[2022/06/02 10:48:37.072 08:00] [info] [oracle.go:40] ["get oracle db_name finished"] [cmds="select value from v$parameter where name='db_name'"] [cost=73.7813ms]
[2022/06/02 10:48:37.072 08:00] [info] [server.go:64] ["prepare dg"] ["get primary db db_name"=crm]
[2022/06/02 10:48:37.072 08:00] [info] [server.go:68] ["prepare dg"] ["get primary db db_unique_name"=]
[2022/06/02 10:48:37.072 08:00] [info] [oracle.go:50] ["get oracle db_unique_name start"]
[2022/06/02 10:48:37.148 08:00] [info] [oracle.go:57] ["get oracle db_unique_name finished"] [cmds="select value from v$parameter where name='db_unique_name'"] [cost=76.2214ms]
[2022/06/02 10:48:37.148 08:00] [info] [server.go:75] ["prepare dg"] ["get primary db (sinage & rac)"=]
[2022/06/02 10:48:37.148 08:00] [info] [oracle.go:113] ["get oracle cluster_database start"]
[2022/06/02 10:48:37.223 08:00] [info] [oracle.go:120] ["get oracle cluster_database finished"] [cmds="select value from v$parameter where name='cluster_database'"] [cost=73.9347ms]
[2022/06/02 10:48:37.223 08:00] [info] [server.go:79] ["prepare dg"] ["get primary db (sinage & rac)"="##this is a single node database"]
[2022/06/02 10:48:37.223 08:00] [info] [server.go:90] ["prepare dg"] ["check primary db arch log mode"=]
[2022/06/02 10:48:37.223 08:00] [info] [oracle.go:65] ["get oracle log_mode start"]
[2022/06/02 10:48:37.291 08:00] [info] [oracle.go:72] ["get oracle log_mode finished"] [cmds="select log_mode from v$database"] [cost=68.2916ms]
[2022/06/02 10:48:37.292 08:00] [warn] [server.go:100] ["prepare dg"] ["oracle db is running in archivelog mode"=archivelog]
[2022/06/02 10:48:37.292 08:00] [info] [server.go:105] ["prepare dg"] ["check primary db force_logging mode "=]
[2022/06/02 10:48:37.292 08:00] [info] [oracle.go:80] ["get oracle force_logging start"]
[2022/06/02 10:48:37.361 08:00] [info] [oracle.go:87] ["get oracle force_logging finished"] [cmds="select force_logging from v$database"] [cost=69.522ms]
[2022/06/02 10:48:37.362 08:00] [info] [server.go:117] ["prepare dg"] ["oracle db is running in force_logging mode"=yes]
[2022/06/02 10:48:37.362 08:00] [info] [server.go:123] ["prepare dg"] ["check primary db orapw file"=]
[2022/06/02 10:48:37.762 08:00] [info] [server.go:137] ["prepare dg"] ["there is orapw$sid"="1\n"]
[2022/06/02 10:48:37.762 08:00] [info] [server.go:142] ["prepare dg"] ["download primary db orapw file "=/oracle/app/oracle/product/11.2.0/db/dbs/orapwcrm]
[2022/06/02 10:48:38.508 08:00] [info] [server.go:147] ["prepare dg"] ["update primary db tnsnames.ora file "=/oracle/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora]
[2022/06/02 10:48:38.934 08:00] [info] [server.go:152] ["prepare dg"] ["download primary db tnsnames.ora file "=/oracle/app/oracle/product/11.2.0/db/network/admin/tnsnames.ora]
[2022/06/02 10:48:39.747 08:00] [info] [server.go:157] ["prepare dg"] ["init standby db tnsnames.ora file "=./network/admin/tnsnames.ora]
。。。。。。