From e1fbfb3cc5ab5065f5f55ffc16056693a88bc75f Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 21 Apr 2020 13:22:22 +0200 Subject: [PATCH] Extending bin/get-dns-zonefiles --- bin/get-dns-zonefiles | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/bin/get-dns-zonefiles b/bin/get-dns-zonefiles index c2f2bcd..1b5010f 100755 --- a/bin/get-dns-zonefiles +++ b/bin/get-dns-zonefiles @@ -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 } -- 2.39.5