Commit c316055a authored by HerrHase's avatar HerrHase

add echos for better logging

parent 07ad9438
......@@ -10,7 +10,8 @@
# @author Björn Hase
#
source $(dirname "$0")/_config.sh
_backup_path=$(dirname "$0")
source "${_backup_path}/_config.sh"
set -o errexit
set -o pipefail
......@@ -22,23 +23,28 @@ set -o nounset
#
_backup_tar_clean()
{
if [ ! -z $max_age ]; then
if [ -n "${max_age}" ]; then
# adding slash
if [ ! -z $remote_directory ]; then
if [ -n "${remote_directory}" ]; then
remote_directory="${remote_directory}/"
fi
# getting list from remote server
files=($(rsync --list-only -e 'ssh -p '${remote_port}'' ${remote_username}@${remote_host}:${remote_directory} | awk {'print $5'} | grep -P '^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z.tar.bz2'))
for file in ${files[@]}
do
_backup_tar_check_file "${file}"
done
files=$(rsync --list-only -e 'ssh -p '"${remote_port}"'' "${remote_username}"@"${remote_host}":"${remote_directory}" | awk {'print $5'} | grep -P '^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z.tar.bz2')
echo -e "Check files on Remote Server..."
echo -e "${files[@]}"
if [ -n "${files}" ]; then
for file in ${files[@]}
do
_backup_tar_check_file "${file}"
done
fi
fi
rm -R -f ${work_directory}
rm -R -f "${work_directory}"
}
#
......@@ -51,16 +57,16 @@ _backup_tar_check_file()
# replace characters to get a format that can be parsed by "date"
# @TODO find a better way, that is awfull
file_date=${file//.gpg/}
file_date=${file_date//.tar.bz2/}
file_date=${file_date//_/ }
file_date="${file//.gpg/}"
file_date="${file_date//.tar.bz2/}"
file_date="${file_date//_/ }"
# calculate max time and file time
max_time=$(date -d "now - $max_age days" +'%s')
file_time=$(date -d "$file_date" +%s)
max_time=$(date -d "now - ${max_age} days" +'%s')
file_time=$(date -d "${file_date}" +%s)
if [ ${max_time} -gt ${file_time} ]; then
rsync -avz --delete --ignore-existing --include="${file}" --exclude="*" "${work_directory}/" -e 'ssh -p '${remote_port}'' ${remote_username}@${remote_host}:${remote_directory}
if [ "${max_time}" -gt "${file_time}" ]; then
rsync -avz --delete --ignore-existing --include="${file}" --exclude="*" "${work_directory}/" -e 'ssh -p '"${remote_port}"'' "${remote_username}"@"${remote_host}":"${remote_directory}"
fi
}
......@@ -90,16 +96,16 @@ _backup_tar_main()
_config_init
# generate filename
local filename=$(_backup_tar_filename)
local filename="$(_backup_tar_filename)"
# check if mysql options are set, if run mysql.sh
if [ ! -z "${mysql_username}" ] && [ ! -z "${mysql_password}" ]; then
./_mysql.sh
fi
./_tar.sh ${filename}
./_gpg-encrypt.sh ${filename}
./_upload.sh ${filename}
./_tar.sh "${filename}"
./_gpg-encrypt.sh "${filename}"
./_upload.sh "${filename}"
_backup_tar_clean
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment