Skip to content

Instantly share code, notes, and snippets.

@heug
Created September 27, 2018 18:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heug/de3a937f511ce27cca86e0db0f67f04e to your computer and use it in GitHub Desktop.
Save heug/de3a937f511ce27cca86e0db0f67f04e to your computer and use it in GitHub Desktop.
Get all docker logs & replicated logs.
#! /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