]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding retrieving zones
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 16 Nov 2017 15:04:26 +0000 (16:04 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 16 Nov 2017 15:04:26 +0000 (16:04 +0100)
bin/backup-pdns-global.sh

index ed711a6401925f56d690d6c9d74b2cda923c124e..860d3fb7ec7329b59b2ea6a8fc9044250504564d 100755 (executable)
@@ -3,14 +3,14 @@
 set -e
 set -u
 
-export LC_ALL=C
-export LANG=C
+export LC_ALL="en_US.utf8"
+export LANG="en_US.utf8"
 
 VERBOSE="n"
 DEBUG="n"
 QUIET='n'
 
-VERSION="1.0"
+VERSION="1.1"
 
 # console colors:
 RED=""
@@ -20,11 +20,12 @@ BLUE=""
 NORMAL=""
 
 HAS_TTY='y'
+HAS_COLORS="n"
 
 BASENAME="$(basename ${0})"
 BASE_DIR="$(dirname ${0})"
 
-declare -a DATABASES=()
+declare -a ZONES=()
 
 #########################################################
 # Modify below variables to fit your need ----
@@ -65,6 +66,7 @@ detect_color() {
         GREEN="\033[38;5;46m"
         BLUE="\033[38;5;27m"
         NORMAL="\033[39m"
+        HAS_COLORS="y"
     else
         RED=""
         YELLOW=""
@@ -160,6 +162,7 @@ get_options() {
                 GREEN=""
                 BLUE=""
                 NORMAL=""
+                HAS_COLORS="n"
                 shift
                 ;;
             --nocolor)
@@ -168,6 +171,7 @@ get_options() {
                 GREEN=""
                 BLUE=""
                 NORMAL=""
+                HAS_COLORS="n"
                 shift
                 ;;
             -h|--help)
@@ -389,6 +393,37 @@ cleanup_old_backups() {
 
 }
 
+#------------------------------------------------------------------------------
+get_zones() {
+
+    local no_color_option=""
+    if [[ "${HAS_COLORS}" == "n" ]] ; then
+        no_color_option="--color no"
+    fi
+
+    if [[ ! -x ./pdns-list-zones ]] ; then
+        error "Script '${RED}${BASE_DIR}/pdns-list-zones${NORMAL}' not found."
+        exit 5
+    fi
+
+    local zone=
+    for zone in $( ./pdns-list-zones ${no_color_option} --global --quiet | \
+                       tail -n +3  | awk '{print $1}' ) ; do
+        ZONES+=( "${zone}" )
+    done
+
+    if [[ "${VERBOSE}" == "y" ]] ; then
+        echo
+        echo "Zones to backup:"
+        for zone in "${ZONES[@]}" ; do
+            echo " * '${zone}'"
+        done
+        echo
+    fi
+
+
+}
+
 #------------------------------------------------------------------------------
 backup_databases() {
 
@@ -476,7 +511,7 @@ main() {
     prepare_dirs
     info "Starting backup ..."
     cleanup_old_backups
-    #get_databases
+    get_zones
     #backup_databases
 
     empty_line