Commit 1a52a157 authored by Matteo Melli's avatar Matteo Melli
Browse files

Added logs with timestamps

parent c42e037b
Pipeline #88718 failed with stage
in 16 seconds
source_vars
.project
\ No newline at end of file
.project
migration.log
\ No newline at end of file
#!/bin/bash
set -eu
[[ $# -lt 2 ]] && { echo "Specify the environment and role"; exit 1 ; }
......
......@@ -2,8 +2,15 @@
function do_step(){
echo "Executing: $@"
"$@" || { echo "Step `$@` Failed." ; exit 2 ; } \
&& echo "Step `$@` ran OK"
echo
if "$@"
then
echo
echo "==================== Step $@ ran OK ===================="
else
echo
>&2 echo "!!!!!!!!!!!!!!!!!!!!! Step $@ Failed !!!!!!!!!!!!!!!!!!!!!"
fi
}
......@@ -53,10 +60,26 @@ function step_check(){
fi
}
function next_step(){
printf "%03d" "$(($(step_number "$1")+1))"
}
function prepend_timestamp(){
while IFS= read -r line; do printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$line"; done
}
function do_menu(){
next_step="$(step_3digit_number "${steps[0]}")"
while true
do
echo "Environment:"
echo "Azure master: $AZURE_MASTER"
echo "Azure slaves: ${AZURE_SLAVES[*]}"
echo "Azure pgbouncers: ${AZURE_PGBOUNCERS[*]}"
echo "GCP master candidate: $GCP_MASTER_CANDIDATE"
echo "GCP slaves: ${GCP_SLAVES[*]}"
echo "GCP pgbouncers: ${GCP_PGBOUNCERS[*]}"
echo
echo "Available steps:"
echo
for step in "${steps[@]}"
......@@ -127,10 +150,13 @@ function do_menu(){
fi
echo
read -r -s -N 1 -p "Press [y] to continue, any other key to abort." key
echo
if [ "$key" == "y" ]
then
next_step="$(printf "%03d" "$(($(step_number "$step")+1))")"
do_step "$script"
next_step="$(next_step "$step")"
do_step "$script" > >(prepend_timestamp | tee -a migration.log) 2> >(prepend_timestamp | tee -a migration.log >&2)
# wait for the redirect subshells to complete
sleep 1
fi
echo
step=
......
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