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

index 1b5010f4c963382ed99ee1fd863e4f315632bb9a..1bfe2c742ab132e830256ca16ec053f5b6abd86c 100755 (executable)
@@ -115,16 +115,23 @@ get_zone() {
     info "Get zone '${GREEN}${zone}${NORMAL}' ..."
 
     local tmpfile=$( mktemp "${zone}.XXXXXXXXXX.zone" )
+    local i=0
+    local zone_file="${zone}.$( cur_ts ).${i}.zone"
+    while [[ -e "${zone_file}" ]] ; do
+        i=$(( $i + 1 ))
+        zone_file="${zone}.$( cur_ts ).${i}.zone"
+    done
 
     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}"
+            named-compilezone -o "${zone_file}" -s relative "${zone}" "${tmpfile}"
         else
-            cat "${tmpfile}" | grep -P -v '^\s*(;|$)'
+            cat "${tmpfile}" | grep -P -v '^\s*(;|$)' >"${zone_file}"
         fi
+        info "Created zone file '${GREEN}${zone_file}${NORMAL}'."
     fi
 
     RM "${tmpfile}"