Skip to content

Instantly share code, notes, and snippets.

@Lotti
Created April 29, 2021 14:56
Show Gist options
  • Save Lotti/a0d6d648e90a04dac8a652d36a02cd27 to your computer and use it in GitHub Desktop.
Save Lotti/a0d6d648e90a04dac8a652d36a02cd27 to your computer and use it in GitHub Desktop.
Download application folder from a Cloud Foundry deployment through ssh
#!/bin/bash
#CONFIG
APP_NAME="$1"
DIR_NAME="."
REMOTE_PATH="~/app"
EXCLUDE="$2"
#----------------
APP_GUID=$(bx -q cf app ${APP_NAME} --guid)
echo "APP_GUID: ${APP_GUID}"
SSH_ENDPOINT=$(bx -q cf curl /v2/info | jq -r '.app_ssh_endpoint')
IFS=":"; SSH_ENDPOINT=(${SSH_ENDPOINT}); unset IFS;
ENDPOINT="${SSH_ENDPOINT[0]}"
echo "ENDPOINT: ${ENDPOINT}"
PORT="${SSH_ENDPOINT[1]}"
echo "PORT: ${PORT}"
SSH_CODE=$(bx -q cf ssh-code)
echo "SSH_CODE: ${SSH_CODE}"
USER="cf:${APP_GUID}/0"
if [ ! -d "${DIR_NAME}" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
mkdir -p "${DIR_NAME}"
fi
#scp -Crp -P ${PORT} -o User=${USER} ${ENDPOINT}:${REMOTE_PATH} ${DIR_NAME}
rsync -av -e "ssh -p ${PORT} -o User=${USER}" --exclude="${EXCLUDE}" --exclude="*/node_modules*" --exclude="*/.app-management*" ${ENDPOINT}:${REMOTE_PATH} ${DIR_NAME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment