Change backup handling.
This commit is contained in:
@@ -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
|
||||
@@ -233,7 +235,7 @@ fi
|
||||
info "Given TLSA Record: \n\t\033[1m$@\033[m"
|
||||
|
||||
|
||||
echononl "\t Loading default Configuration values from $(basename ${conf_file}).."
|
||||
echononl "\tLoading default Configuration values from $(basename ${conf_file}).."
|
||||
if [[ ! -f "$conf_file" ]]; then
|
||||
echo_skipped
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user