]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Extending bin/get-dns-zonefiles
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 21 Apr 2020 11:22:22 +0000 (13:22 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 21 Apr 2020 11:22:22 +0000 (13:22 +0200)
bin/get-dns-zonefiles

index c2f2bcd91ba83803cfc9b770addb29506266c9d5..1b5010f4c963382ed99ee1fd863e4f315632bb9a 100755 (executable)
@@ -101,15 +101,46 @@ get_options() {
 
 }
 
+#------------------------------------------------------------------------------
+cur_ts() {
+    date +'%Y-%m-%d_%H-%M-%S'
+}
+
+#------------------------------------------------------------------------------
+get_zone() {
+
+    local zone="$1"
+
+    echo >&2
+    info "Get zone '${GREEN}${zone}${NORMAL}' ..."
+
+    local tmpfile=$( mktemp "${zone}.XXXXXXXXXX.zone" )
+
+    dig axfr "${zone}" >"${tmpfile}"
+    if grep -i 'Transfer failed' "${tmpfile}" >/dev/null ; then
+        error "Could not transfer zone '${RED}${zone}${NORMAL}'."
+    else
+        if type -p named-compilezone >/dev/null ; then
+            named-compilezone -o - -s relative "${zone}" "${tmpfile}"
+        else
+            cat "${tmpfile}" | grep -P -v '^\s*(;|$)'
+        fi
+    fi
+
+    RM "${tmpfile}"
+}
+
 #------------------------------------------------------------------------------
 main() {
 
     get_options "$@"
+    umask 0022
+    local the_zone=
 
-    for zone in "${ZONES[@]}" ; do
-        echo >&2
-        info "Get zone '${GREEN}${zone}${NORMAL}' ..."
+    set_locale "en_US.utf8"
 
+    for the_zone in "${ZONES[@]}" ; do
+        get_zone "${the_zone}"
     done
 
 }