Last active
June 15, 2024 06:29
-
-
Save EarthmanWeb/51d923d607ba2873c9dc3c75734542a0 to your computer and use it in GitHub Desktop.
Aggregate logs from Pantheon server via Rsync
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 | |
# Usage from project root | |
# make sure your default public key (id_rsa.pub) is added to pantheon | |
# bash /path/to/bash/script/collect-php-error-log-rsync.sh | |
# ** put this in the folder you also want the '/logs' folder to land in | |
### SET SCRIPT PARAMS ### | |
# Site UUID is REQUIRED: Get from Pantheon Dashboard URL | |
SITE_UUID="12345678-1234-1234-abcd-0123456789ab" | |
# if you just want to aggregate the files already collected, set COLLECT_LOGS to FALSE | |
COLLECT_LOGS=true | |
# CLEANUP_DOWNLOADS removes all source logfiles except combined.logs from aggregate-logs directory. | |
CLEANUP_DOWNLOADS=true | |
# Environment is REQUIRED: dev/test/live/or a Multidev | |
# set to the first param or "live" by default | |
if [ -z "$1" ]; then | |
ENV="live" | |
else | |
ENV=$1 | |
fi | |
### END SCRIPT PARAMS ### | |
# current directory where the script resides | |
DIR="$(dirname "$0")" | |
# set base path for the script to run from, relative to where the script resides | |
# must have a trailing slash | |
BASEPATH="$DIR/logs/$ENV/" | |
# create if doesn't exist | |
echo -n "Creating the data folder at: $BASEPATH" | |
mkdir $BASEPATH | |
if [ $COLLECT_LOGS == true ]; then | |
echo -n 'COLLECT_LOGS set to $COLLECT_LOGS. Beginning the process...' | |
for app_server in $(dig +short -4 appserver.$ENV.$SITE_UUID.drush.in); | |
do | |
echo -n "Saving logs to: ${BASEPATH}app_server_${app_server}" | |
rsync -rlvz --size-only --ipv4 --progress -e "ssh -p 2222 -o StrictHostKeyChecking=no" "$ENV.$SITE_UUID@$app_server:logs" ${BASEPATH}app_server_${app_server} | |
done | |
else | |
echo -n 'skipping the collection of logs..' | |
fi | |
echo -n "Starting the process of combining php-error logs..." | |
# remove an existing logfile from previous runs | |
rm -f ${BASEPATH}php-error.log | |
for d in $(ls -d ${BASEPATH}app*/logs/php); do | |
for f in $(ls -f "$d"); do | |
if [[ $f == "php-error.log" ]]; then | |
cat "$d/$f" >> ${BASEPATH}php-error.log | |
cat "" >> ${BASEPATH}php-error.log | |
fi | |
done | |
done | |
if [ $CLEANUP_DOWNLOADS == true ]; then | |
echo -n 'CLEANUP_DOWNLOADS set to $CLEANUP_DOWNLOADS. Cleaning up the downloads from the ${BASEPATH} directory' | |
find $BASEPATH -name 'app_server*' -print -exec rm -R {} \; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment