Skip to content

Commit

Permalink
Merge pull request #58 from pb82/INTLY-8637
Browse files Browse the repository at this point in the history
fix: crw 2.0 requires backing up non-default container inside a pod
  • Loading branch information
pb82 authored Jun 30, 2020
2 parents 79f10e3 + 8d6f88c commit 2fa27ce
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion image/tools/lib/component/codeready_pv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function dump_pod_data {
workspace_pod_name=$1
dump_dest=$2
workspace_id=$(echo ${workspace_pod_name} | awk -F"." '{ print $1}')
cp_pod_data "${PRODUCT_NAMESPACE}/${workspace_pod_name}:/projects" "${dump_dest}/${workspace_id}"
cp_container_data "${workspace_pod_name}" "${PRODUCT_NAMESPACE}/${workspace_pod_name}:/projects" "${dump_dest}/${workspace_id}"
}

function component_dump_data {
Expand Down
33 changes: 33 additions & 0 deletions image/tools/lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,39 @@ function cp_pod_data {
done
}

# Backup every container inside a pod
function cp_container_data {
pod_name=$1
pod_data_src=$2
cp_dest=$3

# Get a list of containers inside the pod
containers=$(oc get pods "$pod_name" -ojsonpath='{.spec.containers[*].name}' -n "${PRODUCT_NAMESPACE}")

for container in ${containers}; do
container_dest="$cp_dest-$container"
timestamp_echo "backing up container $container in pod $pod_name"
num_attempted_copy=0
max_tries=5

# 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")
# 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 ]
do
timestamp_echo "A file has been overwritten during copying, executing 'oc cp' again"
sleep 5
copy_output=$(oc cp "$pod_data_src" "$container_dest" -c "$container")
((num_attempted_copy++))
done

# Re-enable errors
set -eo pipefail
done
}

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

0 comments on commit 2fa27ce

Please sign in to comment.