From: Frank Brehm Date: Thu, 16 Nov 2017 15:55:39 +0000 (+0100) Subject: Finished bin/backup-pdns-global.sh X-Git-Tag: 0.1.2~71 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=a7685995db22d0b85749d74babd89fbbf0202f87;p=pixelpark%2Fadmin-tools.git Finished bin/backup-pdns-global.sh --- diff --git a/bin/backup-pdns-global.sh b/bin/backup-pdns-global.sh index 860d3fb..02ef672 100755 --- a/bin/backup-pdns-global.sh +++ b/bin/backup-pdns-global.sh @@ -10,7 +10,7 @@ VERBOSE="n" DEBUG="n" QUIET='n' -VERSION="1.1" +VERSION="1.2" # console colors: RED="" @@ -46,6 +46,8 @@ TIMESTAMP="${YEAR}-${MONTH}-${DAY}-${TIME}" # Define, check, create directories. BACKUP_DIR="${BACKUP_ROOTDIR}/${YEAR}/${MONTH}/${DAY}" +BYTES_TOTAL=0 + #------------------------------------------------------------------- detect_color() { @@ -300,7 +302,6 @@ RMDIR() { #------------------------------------------------------------------------------ empty_line() { if [[ "${QUIET}" == "y" ]] ; then - echo >> "${LOGFILE}" return 0 fi echo @@ -425,14 +426,15 @@ get_zones() { } #------------------------------------------------------------------------------ -backup_databases() { +backup_zones() { local db= - for db in "${DATABASES[@]}" ; do - backup_database "${db}" + for zone in "${ZONES[@]}" ; do + backup_zone "${zone}" done empty_line + info "Backed up ${#ZONES[*]} zones." local k_bytes=$(( ${BYTES_TOTAL} / 1024 )) local m_bytes=$(( ${k_bytes} / 1024 )) local msg=$( printf "Total compressed size: %10d Bytes => %7d KiB => %4d MiB" \ @@ -441,58 +443,66 @@ backup_databases() { } #------------------------------------------------------------------------------ -backup_database() { +backup_zone() { - local db="$1" + local zone="$1" empty_line - info "Backing up database '${GREEN}${db}${NORMAL}' ..." + info "Backing up zone '${GREEN}${zone}${NORMAL}' ..." - local output_sql="${db}-${TIMESTAMP}.sql" - local output_sql_compressed="${output_sql}.bz2" - local out_sql_tmp="${TMP_DIR}/${output_sql}" - local out_sql_tmp_compressed="${TMP_DIR}/${output_sql_compressed}" - local out_sql_tgt="${BACKUP_DIR}/${output_sql}" - local out_sql_tgt_compressed="${BACKUP_DIR}/${output_sql_compressed}" + local no_color_option="" + if [[ "${HAS_COLORS}" == "n" ]] ; then + no_color_option="--color no" + fi local verbose_option="" if [[ "${VERBOSE}" == "y" ]] ; then verbose_option="--verbose" fi - pg_dump ${verbose_option} --blobs --clean \ - --create --if-exists --serializable-deferrable \ - "${db}" 2>&1 >"${out_sql_tmp}" | tee -a "${LOGFILE}" + local quiet_option="" + if [[ "${QUIET}" == "y" ]] ; then + quiet_option="--quiet" + fi - local blocks=$(stat -c "%b" "${out_sql_tmp}") - local bs=$(stat -c "%B" "${out_sql_tmp}") - local bytes=$(stat -c "%s" "${out_sql_tmp}") + if [[ ! -x ./pdns-show-zone ]] ; then + error "Script '${RED}${BASE_DIR}/pdns-show-zone${NORMAL}' not found." + exit 5 + fi + + local output_txt="${zone}${TIMESTAMP}.txt" + local output_txt_compressed="${output_txt}.bz2" + local out_txt_tgt="${BACKUP_DIR}/${output_txt}" + local out_txt_tgt_compressed="${BACKUP_DIR}/${output_txt_compressed}" + + ./pdns-show-zone ${verbose_option} ${quiet_option} ${no_color_option} "${zone}" > "${out_txt_tgt}" + + local blocks=$(stat -c "%b" "${out_txt_tgt}") + local bs=$(stat -c "%B" "${out_txt_tgt}") + local bytes=$(stat -c "%s" "${out_txt_tgt}") local b_bytes=$(( ${blocks} * ${bs} )) local k_bytes=$(( ${b_bytes} / 1024 )) local m_bytes=$(( ${k_bytes} / 1024 )) - local msg=$( printf "Original size of %-50s %10d Bytes => %7d KiB => %4d MiB" \ - "'${output_sql}':" "${bytes}" "${k_bytes}" "${m_bytes}" ) + local msg=$( printf "Original size of %-60s %10d Bytes => %7d KiB => %4d MiB" \ + "'${output_txt}':" "${bytes}" "${k_bytes}" "${m_bytes}" ) info "${msg}" - debug "Compressing '${out_sql_tmp}' ..." - bzip2 ${verbose_option} --best "${out_sql_tmp}" 2>&1 | tee -a "${LOGFILE}" + debug "Compressing '${out_txt_tgt}' ..." + bzip2 ${verbose_option} --best "${out_txt_tgt}" - blocks=$(stat -c "%b" "${out_sql_tmp_compressed}") - bs=$(stat -c "%B" "${out_sql_tmp_compressed}") - bytes=$(stat -c "%s" "${out_sql_tmp_compressed}") + blocks=$(stat -c "%b" "${out_txt_tgt_compressed}") + bs=$(stat -c "%B" "${out_txt_tgt_compressed}") + bytes=$(stat -c "%s" "${out_txt_tgt_compressed}") b_bytes=$(( ${blocks} * ${bs} )) k_bytes=$(( ${b_bytes} / 1024 )) m_bytes=$(( ${k_bytes} / 1024 )) BYTES_TOTAL=$(( ${BYTES_TOTAL} + ${b_bytes} )) - local msg=$( printf "Compressed size of %-50s %10d Bytes => %7d KiB => %4d MiB" \ - "'${output_sql}':" "${bytes}" "${k_bytes}" "${m_bytes}" ) + local msg=$( printf "Compressed size of %-60s %10d Bytes => %7d KiB => %4d MiB" \ + "'${output_txt}':" "${bytes}" "${k_bytes}" "${m_bytes}" ) info "${msg}" - debug "Moving '${out_sql_tmp_compressed}' => '${BACKUP_DIR}' ..." - MV -i "${out_sql_tmp_compressed}" "${BACKUP_DIR}" - } @@ -512,7 +522,7 @@ main() { info "Starting backup ..." cleanup_old_backups get_zones - #backup_databases + backup_zones empty_line info "Finished."