Skip to content

Commit

Permalink
🔀 Merge branch 'INTLY-10129' [#59]
Browse files Browse the repository at this point in the history
  • Loading branch information
grdryn committed Dec 17, 2020
2 parents 2fa27ce + 67cd860 commit fa24ecc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
23 changes: 16 additions & 7 deletions image/tools/lib/component/enmasse_pv.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,26 @@ function component_dump_data {

mkdir -p ${dump_dest}

local ts
ts=$(date '+%H_%M_%S')
local archive="${archive_path}/enmasse-pv-data-${ts}.tar"
tar -cvf "${archive}" --files-from /dev/null

for pod in ${pods}; do
timestamp_echo "Processing enmasse broker pod ${pod}"
dump_pod_data ${pod} ${dump_dest}

ls ${dump_dest}/*
if [ "$?" -eq "0" ]; then
tar --append -vf "${archive}" -C "${dump_dest}" .
rm -rf ${dump_dest:?}/*
else
timestamp_echo "No enmasse broker data to backup"
fi
done

ls ${dump_dest}/*
if [ "$?" -eq "0" ]; then
local ts=$(date '+%H_%M_%S')
tar -zcvf "$archive_path/enmasse-pv-data-${ts}.tar.gz" -C $dump_dest .
rm -rf $dump_dest
else
timestamp_echo "No enmasse broker data to backup"
if [[ -f ${archive} ]]; then
gzip "${archive}"
fi
rm -rf ${dump_dest}
}
29 changes: 17 additions & 12 deletions image/tools/lib/utils.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ function cp_pod_data {
cp_dest=$2

num_attempted_copy=0
max_tries=5
copy_output=$(oc cp $pod_data_src $cp_dest)
# Check if any files were rewritten to during oc cp, and copy it again if it was.
while [[ $copy_output == *"file changed as we read it"* ]] && [ $num_attempted_copy -lt $max_tries ]
max_tries=3

oc cp $pod_data_src $cp_dest
ret=$?

while [[ $ret != 0 && $num_attempted_copy -lt $max_tries ]]
do
timestamp_echo "A file has been overwritten during copying, executing 'oc cp' again"
timestamp_echo "'oc cp' failed with exit code ${ret}, will retry in 5 seconds, attempt ${num_attempted_copy} of ${max_tries}"
sleep 5
copy_output=$(oc cp $pod_data_src $cp_dest)
oc cp $pod_data_src $cp_dest
ret=$?
((num_attempted_copy++))
done
}
Expand All @@ -30,18 +33,20 @@ function cp_container_data {
container_dest="$cp_dest-$container"
timestamp_echo "backing up container $container in pod $pod_name"
num_attempted_copy=0
max_tries=5
max_tries=3

# Disable errors because some of the containers might not have the directory to back up
set +eo pipefail

copy_output=$(oc cp "$pod_data_src" "$container_dest" -c "$container")
oc cp "$pod_data_src" "$container_dest" -c "$container"
ret=$?
# Check if any files were rewritten to during oc cp, and copy it again if it was.
while [[ $copy_output == *"file changed as we read it"* ]] && [ $num_attempted_copy -lt $max_tries ]
while [[ $ret != 0 && $num_attempted_copy -lt $max_tries ]]
do
timestamp_echo "A file has been overwritten during copying, executing 'oc cp' again"
timestamp_echo "'oc cp' failed with exit code ${ret}, will retry in 5 seconds, attempt ${num_attempted_copy} of ${max_tries}"
sleep 5
copy_output=$(oc cp "$pod_data_src" "$container_dest" -c "$container")
oc cp "$pod_data_src" "$container_dest" -c "$container"
ret=$?
((num_attempted_copy++))
done

Expand All @@ -52,4 +57,4 @@ function cp_container_data {

function timestamp_echo {
echo `(date -u '+%Y-%m-%d %H:%M:%S')` '==>' $1
}
}

0 comments on commit fa24ecc

Please sign in to comment.