Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crw 2.0 requires backing up non-default container inside a pod #58

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}