diff --git a/src/bafscript b/src/bafscript index 65fecde..078b62c 100755 --- a/src/bafscript +++ b/src/bafscript @@ -20,6 +20,7 @@ __version='0.0.0' __config= __verbose= __log_file='./log.txt' +__log_date_fmt='%d/%b/%Y:%H:%M:%S %z' __tar_options='-acf' __tar_compression='gzip' __name_date_fmt='_%Y%m%d-%H%M' @@ -113,14 +114,14 @@ done # ---------------------------------------------------------- # # Scripts counter. -_count=${#__args[@]} # count -_iter=1 # iterator +__count=${#__args[@]} # count +__iter=1 # iterator # Startup log. date +'Start: %d %b %Y %T %z' log "Backup STARTED" log -p "Configuration file: $([ "$__config" ] || echo not specified && echo "$__config")" -log "Scripts to process (${_count}): ${__args[@]}" +log "Scripts to process (${__count}): ${__args[@]}" for script in "${__args[@]}"; do @@ -130,7 +131,7 @@ for script in "${__args[@]}"; do [ -n "$__config" ] && . "$__config" echo - echo -e "\e[1m==> Script: ${__args[_iter-1]##*/} [$_iter/$_count]\e[0m" | log -p + echo -e "\e[1m==> Script: ${__args[__iter-1]##*/} [$__iter/$__count]\e[0m" | log -p # Initialise variables __user_script="$script" @@ -161,7 +162,7 @@ for script in "${__args[@]}"; do fi # Increase counter - ((_iter++)) || true + ((__iter++)) || true # Unset user defined variables unset tar_options diff --git a/src/lib/backup.sh b/src/lib/backup.sh index 97e477a..304bea8 100644 --- a/src/lib/backup.sh +++ b/src/lib/backup.sh @@ -294,8 +294,10 @@ gen_backup_name() { # Overwrite __name_date_fmt if [ -n "$name_date_fmt" ]; then - __name_date_fmt="$name_date_fmt" + date_fmt="$name_date_fmt" + else + date_fmt="$__name_date_fmt" fi - date +"${prefix}${name}${__name_date_fmt}${name_ext}" + date +"${prefix}${name}${date_fmt}${name_ext}" } diff --git a/src/lib/common.sh b/src/lib/common.sh index 6498b13..0ffc66b 100644 --- a/src/lib/common.sh +++ b/src/lib/common.sh @@ -34,7 +34,7 @@ log() { [[ ! -t 0 ]] || [[ "$#" == 0 ]] && message="$(cat <&0)" # Set log date format - [ "$log_date_fmt" ] || log_date_fmt='%d/%b/%Y:%H:%M:%S %z' + [ "$log_date_fmt" ] || log_date_fmt="$__log_date_fmt" while (( "$#" )); do case "$1" in diff --git a/tests/source_script.bats b/tests/source_script.bats index fc6f47c..100897d 100644 --- a/tests/source_script.bats +++ b/tests/source_script.bats @@ -61,12 +61,14 @@ setup() { . source.sh . uri.sh # for parse_uri() source_script $DIR/files/basic.plan - [ "$__main_target" == '/etc/lvm/backup' ] + [ "$__main_target" == 'file:/etc/lvm/backup' ] + [ "$__main_target_path" == '/etc/lvm/backup' ] } @test "Set __main_target from multiple 'file' targets" { . source.sh . uri.sh # for parse_uri() source_script $DIR/files/multiple_file_targets.plan - [ "$__main_target" == '/etc/lvm/backup' ] + [ "$__main_target" == 'file:///etc/lvm/backup' ] + [ "$__main_target_path" == '/etc/lvm/backup' ] }