Change backup handling.

This commit is contained in:
Christoph 2017-08-04 13:27:11 +02:00
parent 9211cb8970
commit 568a481ddf
4 changed files with 132 additions and 23 deletions

View File

@ -448,6 +448,8 @@ while IFS='' read -r _line || [[ -n $_line ]] ; do
fi
done < "$ZONES_DECLARATION_FILE"
if [[ -d "$ZONE_FILE_MASTER_DIR" ]] ; then
echononl "\tBackup directory '${ZONE_FILE_MASTER_DIR}'.."
cp -a "${ZONE_FILE_MASTER_DIR}" "${ZONE_FILE_MASTER_DIR}.${backup_date}" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
@ -456,6 +458,7 @@ else
echo_failed
fatal "$(cat $log_file)"
fi
fi
for _val in "${zone_file_arr[@]}" ; do

View File

@ -290,6 +290,7 @@ if $LOGGING ; then
fi
[[ -n "$DEFAULT_ZONES_DECLARATION_FILE" ]] || DEFAULT_ZONES_DECLARATION_FILE="${CONF_FILE_DIR}/named.conf.local"
[[ -n "$ZONE_FILE_MASTER_DIR" ]] || ZONE_FILE_MASTER_DIR="${CONF_FILE_DIR}/master"
echo ""
@ -354,6 +355,7 @@ else # if $LOGGING
fi
[[ -n "$ZONES_DECLARATION_FILE" ]] || ZONES_DECLARATION_FILE="${CONF_FILE_DIR}/named.conf.local"
[[ -n "$ZONE_FILE_MASTER_DIR" ]] || ZONE_FILE_MASTER_DIR="${CONF_FILE_DIR}/master"
fi
@ -376,6 +378,18 @@ else
echo_ok
fi
if [[ -d "$ZONE_FILE_MASTER_DIR" ]] ; then
echononl " Backup directory '${ZONE_FILE_MASTER_DIR}'.."
cp -a "${ZONE_FILE_MASTER_DIR}" "${ZONE_FILE_MASTER_DIR}.${backup_date}" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $log_file)"
fi
fi
declare -i line_number=0
_found=false
@ -479,6 +493,18 @@ if [[ -n "$key_directory" ]]; then
$LOGGING && echo ""
if [[ "$(dirname ${key_directory})" != "$CONF_FILE_DIR" ]]; then
backup_key_dir="$(dirname ${key_directory})"
echononl " Backup directory '${backup_key_dir}'.."
cp -a "${backup_key_dir}" "${backup_key_dir}.${backup_date}" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fatal "$(cat $log_file)"
fi
fi
_dir="$(dirname ${key_directory})/DELETED"
echononl " Create directory '${_dir}'.."
if [[ ! -d "${_dir}" ]] ; then
@ -530,6 +556,54 @@ if [[ -n "$key_directory" ]]; then
fi
fi
if [[ -f "${ZONES_DECLARATION_FILE}.$backup_date" ]]; then
diff "$ZONES_DECLARATION_FILE" "${ZONES_DECLARATION_FILE}.$backup_date" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
info "Zone declaration file $(basename $ZONES_DECLARATION_FILE) has not changed.\n\t Removing previously created backup now."
echononl "\tDelete '${ZONES_DECLARATION_FILE}.$backup_date'.."
rm "${ZONES_DECLARATION_FILE}.$backup_date" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fi
fi
fi
if [[ -d "${ZONE_FILE_MASTER_DIR}.${backup_date}" ]] ; then
diff -Nur "${ZONE_FILE_MASTER_DIR}" "${ZONE_FILE_MASTER_DIR}.${backup_date}" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
info "No zone file has changed.\n\t Removing previously created backup."
echononl "\tDelete '${ZONE_FILE_MASTER_DIR}.${backup_date}'.."
rm -rf "${ZONE_FILE_MASTER_DIR}.${backup_date}" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
fi
fi
if [[ -d "${backup_key_dir}.${backup_date}" ]] ; then
diff -Nur "${backup_key_dir}" "${backup_key_dir}.${backup_date}" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
info "Key directory '${backup_key_dir}' has not changed.\n\t Removing previously created backup now."
echononl "\tDelete '${backup_key_dir}.${backup_date}'.."
rm -rf "${backup_key_dir}.${backup_date}" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "$(cat $log_file)"
fi
fi
fi
$LOGGING && echo ""
echononl " Reeload bind configuration"

View File

@ -42,6 +42,8 @@ conf_file="${working_dir}/conf/bind.conf"
log_file="$(mktemp)"
backup_date="$(date +%Y-%m-%d-%H%M)"
#---------------------------------------
#-----------------------------
@ -348,12 +350,12 @@ zone_file_dir=`dirname $zone_file`
echononl "\t Backup existing directory containg zonefiles.."
if [[ -d "$zone_file_dir" ]] ; then
cp -a $zone_file_dir ${zone_file_dir}.BAK.`date +%Y-%m-%d-%H%M`
cp -a "$zone_file_dir" "${zone_file_dir}.$backup_date" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
error "Backup directory 'zone_file_dir' containg zonefiles failed!"
error "$(cat $log_file)"
clean_up 99
fi
else
@ -418,6 +420,22 @@ else
fi
if [[ -d "${zone_file_dir}.$backup_date" ]] ; then
diff -Nur "$zone_file_dir" "${zone_file_dir}.$backup_date" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
info "No zone file has changed.\n\t Removing previously created backup."
echononl "\t Delete '${zone_file_dir}.$backup_date'.."
rm -rf "${zone_file_dir}.$backup_date" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fi
fi
fi
$verbose && echo ""
# - Reload Zone
# -
echononl "\tReloading zone \"$domain\".."

View File

@ -42,6 +42,8 @@ conf_file="${working_dir}/conf/bind.conf"
log_file="$(mktemp)"
backup_date="$(date +%Y-%m-%d-%H%M)"
#---------------------------------------
#-----------------------------
@ -155,7 +157,7 @@ backup_dir () {
dir_to_backup=$1
echononl "\tBackup existing directory \"$dir_to_backup\" .."
if [[ -d "$dir_to_backup" ]] ; then
cp -a $dir_to_backup ${dir_to_backup}.BAK.`date +%Y-%m-%d-%H%M`
cp -a "$dir_to_backup" "${dir_to_backup}.$backup_date" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
@ -357,8 +359,9 @@ fi
zone_file_dir="$(dirname $zone_file)"
# - Backup existing zone file directory
# - Backup zone directory
# -
backup_dir $zone_file_dir
# - Update/Add TLSA recotd if needed
@ -374,8 +377,6 @@ if grep -E "^$record_name.+$record_type" $zone_file > /dev/null 2>&1 ; then
clean_up 0
else
_replac_string=${record_arr[@]}
# - Backup Zone directory
backup_dir $zone_file_dir
# - Replace TLSA Record
echononl "\tGoing to replace TLSA Record.."
@ -433,9 +434,6 @@ else
_tmpfile=`mktemp`
> $_tmpfile
# - backup zone directory
backup_dir $zone_file_dir
# - Add new TLSA record
echononl "\tAdd new TLSA record to zonefile \"\".."
while read -r line || [[ -n "$line" ]]; do
@ -493,5 +491,21 @@ else
clean_up 2
fi
if [[ -d "${zone_file_dir}.$backup_date" ]] ; then
diff -Nur "$zone_file_dir" "${zone_file_dir}.$backup_date" > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
info "No zone file has changed.\n\t Removing previously created backup."
echononl "\t Delete '${zone_file_dir}.$backup_date'.."
rm -rf "${zone_file_dir}.$backup_date" > $log_file 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
else
echo_failed
fi
fi
fi
$verbose && echo ""
clean_up 99