New targets for comparing Azure PG server configuration
authorUbuntu <kop@karlpinc.com>
Fri, 15 Sep 2023 23:22:51 +0000 (23:22 +0000)
committerUbuntu <kop@karlpinc.com>
Fri, 15 Sep 2023 23:22:51 +0000 (23:22 +0000)
.gitignore
db/compare-az-server.sh [new file with mode: 0755]
make_files/make_db.mk

index 5f193e0383838df82c8f22747858e537b7501448..92d79c4ddb4de6006de3aea74c9a9380ca500e84 100644 (file)
@@ -8,6 +8,7 @@ db/run_createdb.sh
 db/set_timezone.sh
 
 # A generated dump of the settings
+db/az_server_info.new
 db/pg_settings.new
 
 # Built image files
diff --git a/db/compare-az-server.sh b/db/compare-az-server.sh
new file mode 100755 (executable)
index 0000000..1e8868e
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/sh
+# Copyright (C) 2023 The Meme Factory, Inc. http://www.karlpinc.com/
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+#
+#  Compare the Azure server json config files
+#
+#  All "id" keys are removed before comparison because they are
+#  always going to be different.
+#
+#  The assumption is that an Azure server config is going to be a
+#  json list of objects.
+#
+#  See: https://jqlang.github.io/jq/manual/
+#
+#  Note: It would be nice to use jd (https://github.com/josephburnett/jd)
+#  but it isn't packaged.
+#
+#  Bugs:
+#    It's hard to tell if the output is useful when it comes to
+#    determining what configuration has changed.  But it's a start.
+#
+# Karl O. Pinc <kop@karlpinc.com>
+#
+
+tfile="$(mktemp)"
+
+cleanup () {
+    rm -rf "${tfile}"
+}
+
+trap cleanup EXIT
+
+jq --sort-keys '[sort | .[] | del(.id)]' < db/az_server_info > "${tfile}" \
+  || exit $?
+
+jq --sort-keys '[sort | .[] | del(.id)]' \
+         | diff -U 25 "${tfile}" /dev/stdin
index 03765ca734fa6c100e221de7e644a8a92a3b8532..aefd4df1e9e10f7adbfa639ce31d115b68863c3f 100644 (file)
@@ -586,6 +586,9 @@ SET_PASSWORD := ALTER ROLE $(TARGET_ROLE) PASSWORD '$(NEW_PASSWORD)'
 GET_PG_SETTINGS := SELECT name, setting, unit, pending_restart \
                      FROM pg_settings \
                      ORDER BY name;
+GET_AZ_SERVER_SETTINGS:= az postgres flexible-server parameter list \
+                           --resource-group $(RESOURCEGROUP) \
+                           --server $(TARGET_SERVER)
 
 ##
 ## The available targets for make (make TARGET) are:
@@ -719,6 +722,47 @@ compare-db-settings:
          | sort --stable \
          | diff -U 0 db/pg_settings /dev/stdin
 
+##   db/az_server_info.new
+##                       Save a file of all configuration and other
+##                       information about an MS Azure Postgres
+##                       flexible-serve named TARGET_SERVER in the
+##                       RESOURCEGROUP resource group.  See the
+##                       "compare-az-server" target.  Azure must be logged
+##                       into and defaults established in order to use this
+##                       target.  See "Usage" above.  After changing a
+##                       setting, create "db/az_server_info.new", rename it
+##                       to "db/az_server_info", and commit the change to
+##                       revision control.
+.PHONY: db/az_server_info.new
+db/az_server_info.new:
+       [ -n "$(TARGET_SERVER)" ] \
+           || { printf 'The TARGET_SERVER variable must be set\n' >&2 ; \
+                exit 1 ; }
+       [ -n "$(RESOURCEGROUP)" ] \
+           || { printf 'The RESOURCEGROUP variable must be set\n' >&2 ; \
+                exit 1 ; }
+       $(GET_AZ_SERVER_SETTINGS) \
+         | jq --sort-keys \
+         > db/az_server_info.new 
+
+##   compare-az-server   Diff the configuration settings of the MS Azure
+##                       Postgres flexible-serve named TARGET_SERVER in the
+##                       RESOURCEGROUP resource group.  Azure must be
+##                       logged into and defaults established in order to
+##                       use this target.  See "Usage" above.  This ensures
+##                       that your TARGET_SERVER is configured as expected.
+##                       Before changing server settings run this target.
+.PHONY: compare-az-server
+compare-az-server:
+       [ -n "$(TARGET_SERVER)" ] \
+           || { printf 'The TARGET_SERVER variable must be set\n' >&2 ; \
+                exit 1 ; }
+       [ -n "$(RESOURCEGROUP)" ] \
+           || { printf 'The RESOURCEGROUP variable must be set\n' >&2 ; \
+                exit 1 ; }
+       $(GET_AZ_SERVER_SETTINGS) \
+         | db/compare-az-server.sh
+
 ##
 ## Lesser used targets:
 ##