Change backup handling.

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

View File

@@ -42,6 +42,8 @@ conf_file="${working_dir}/conf/bind.conf"
log_file="$(mktemp)"
backup_date="$(date +%Y-%m-%d-%H%M)"
#---------------------------------------
#-----------------------------
@@ -273,7 +275,7 @@ $verbose && echo ""
# - Validate Syntax of given domain
# -
valid_domain_regex="^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$"
echononl "\tValidate syntax of given domain.."
echononl "\t Validate syntax of given domain.."
if [[ $host_name =~ $valid_domain_regex ]]; then
if [[ ! $host_name =~ \. ]]; then
echo_failed
@@ -346,14 +348,14 @@ fi
zone_file_dir=`dirname $zone_file`
echononl "\tBackup existing directory containg zonefiles.."
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
@@ -365,7 +367,7 @@ fi
# - Determin new serial
# -
echononl "\tDetermin new serial.."
echononl "\t Determin new serial.."
_failed=false
declare -i serial_new=`date +%Y%m%d01`
serial_cur=`grep -e "^\s*[0-9]\{10\}" $zone_file | grep serial | awk '{print$1}'`
@@ -389,7 +391,7 @@ fi
# - Replace serial with the new one
# -
echononl "\tIncrease serial for zone file \"`basename $zone_file`\".."
echononl "\t Increase serial for zone file \"`basename $zone_file`\".."
perl -i -n -p -e "s#^(\s*)\s$serial_cur(.*)#\1 $serial_new\2#" $zone_file > /dev/null 2>&1
if [[ $? -eq 0 ]]; then
echo_ok
@@ -400,7 +402,7 @@ else
fi
$verbose && echo ""
echononl "\tCorrect Owner for $zone_file .."
echononl "\t Correct Owner for $zone_file .."
chown $BIND_USER:$BIND_GROUP $zone_file
if [[ $? -eq 0 ]] ; then
echo_ok
@@ -408,7 +410,7 @@ else
echo_failed
clean_up 99
fi
echononl "\tCorrect permissions on $zone_file .."
echononl "\t Correct permissions on $zone_file .."
chmod 644 $zone_file
if [[ $? -eq 0 ]] ; then
echo_ok
@@ -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\".."