Created
September 27, 2018 18:21
-
-
Save heug/de3a937f511ce27cca86e0db0f67f04e to your computer and use it in GitHub Desktop.
Get all docker logs & replicated logs.
This file contains hidden or 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 | |
# Please run as root user! | |
set -eu | |
output_dir="container-logs" | |
timestamp=$(date +%s) | |
generate_logs() { | |
container_ids=($(docker ps | awk '{if (NR!=1)print $1}')) | |
container_names=($(docker ps | awk '{if (NR!=1)print $NF}')) | |
if [[ $container_ids ]]; then | |
for i in "${!container_ids[@]}"; do | |
# echo "${container_ids[i]}" "${container_names[i]}" | |
docker logs ${container_ids[i]} > $output_dir/${container_names[i]}.log | |
done | |
else | |
echo "No containers running" | |
fi | |
} | |
get_upstart_logs() { | |
cp /var/log/*.log $output_dir/replicated 2>/dev/null | |
} | |
mkdir -p $output_dir/replicated | |
get_replicated_logs | |
generate_logs | |
tar czf container-logs-$timestamp.tar.gz $output_dir | |
rm -rf $output_dir | |
echo "Log bundle container-logs-$timestamp has been successfully created." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment