feat: Add logging and output info
This commit is contained in:
@ -18,6 +18,7 @@
|
||||
|
||||
__version='0.0.0'
|
||||
__config=
|
||||
__verbose=
|
||||
__log_file='./log.txt'
|
||||
__tar_options='-czf'
|
||||
__name_date_fmt='_%Y%m%d-%H%M'
|
||||
@ -110,27 +111,59 @@ done
|
||||
# * Do backups #
|
||||
# ---------------------------------------------------------- #
|
||||
|
||||
# Scripts counter.
|
||||
_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[@]}"
|
||||
|
||||
# TODO source config
|
||||
|
||||
for script in "${__args[@]}"; do
|
||||
source_script "$script"
|
||||
|
||||
echo
|
||||
echo -e "\e[1m==> Script: ${__args[_iter-1]##*/} [$_iter/$_count]\e[0m" | log -p
|
||||
|
||||
# Initialise variables
|
||||
__user_script="$script"
|
||||
backups=() # Array of created backups, contains full pathes
|
||||
|
||||
# Run prepare() before all if set
|
||||
if is_function_set prepare; then
|
||||
log -p "Execute prepare() ..."
|
||||
prepare
|
||||
unset prepare
|
||||
fi
|
||||
|
||||
# Run user defined backup() if set or builtin_backup()
|
||||
if is_function_set backup; then
|
||||
echo -e "Execute \e[1mbackup()\e[0m ..." | log -p
|
||||
backup
|
||||
unset backup
|
||||
else
|
||||
echo -e "Execute \e[1mbuiltin_backup()\e[0m ..." | log -p
|
||||
builtin_backup
|
||||
fi
|
||||
|
||||
# Run post backup function if set
|
||||
if is_function_set finalise; then
|
||||
echo -e "Execute \e[1mfinalise()\e[0m ..." | log -p
|
||||
finalise
|
||||
unset finalise
|
||||
fi
|
||||
|
||||
# Increase counter
|
||||
((_iter++)) || true
|
||||
|
||||
# Unset user defined variables
|
||||
unset tar_options
|
||||
unset name_date_fmt
|
||||
done
|
||||
|
||||
log "Backup FINISHED"
|
||||
echo -e "\nBackup [Done]"
|
||||
|
Reference in New Issue
Block a user