Created
April 29, 2021 14:56
-
-
Save Lotti/a0d6d648e90a04dac8a652d36a02cd27 to your computer and use it in GitHub Desktop.
Download application folder from a Cloud Foundry deployment through ssh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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