#!/usr/bin/env bash if [ "$EUID" -ne 0 ]; then echo "Please run as root" exit 1 fi HOSTNAME=$(hostname) TMPDIR=$(mktemp -d) MIT="/srv/mitigator" DATE=$(date '+%Y%m%d_%H%M%S') DELIMITER="" trap "rm -rf $TMPDIR" EXIT test -d $MIT if [ $? -eq 0 ]; then cd $MIT else echo -e "\033[31mCan't find /srv/mitigator directory! \033[0m" exit 1 fi echo "-------------------------------Copying current MITIGATOR configuration files------------------------" ls -lah $MIT > $TMPDIR/ls.txt test -f $MIT/data-plane.conf && cp $MIT/data-plane.conf $TMPDIR/ test -f /var/lib/docker/volumes/mitigator_own_id/_data/own_id.conf && cp /var/lib/docker/volumes/mitigator_own_id/_data/own_id.conf $TMPDIR/ test -f /etc/docker/daemon.json && cp /etc/docker/daemon.json $TMPDIR/ test -f $MIT/.env && cp $MIT/.env $TMPDIR/env.txt test -f /etc/default/grub && cp /etc/default/grub $TMPDIR/grub.txt test -f /etc/systemd/system/mitigator.service.d/nics.conf && cp /etc/systemd/system/mitigator.service.d/nics.conf $TMPDIR/ find $MIT -type f -name '*.yml' -exec cp {} $TMPDIR/ \; echo -e "\033[32mAll needed files was copied \033[0m" echo "-------------------------------Getting state and logs of docker containers-------------------------" docker-compose ps > $TMPDIR/docker_compose_ps.txt for service in $(docker-compose ps --service) do echo "Copying $service logs" docker-compose logs --no-color --timestamps --tail=10000 $service > $TMPDIR/LOGS_$service.txt done docker-compose exec postgres psql mitigator -c "\copy (select * from backend.journals) to /tmp/journal.txt;" 2>&1 > /dev/null docker cp mitigator_postgres_1:/tmp/journal.txt $TMPDIR/journal.txt for ports in $(nsenter -t $(docker inspect mitigator_data-plane_1 -f '{{ .State.Pid }}') \ -n curl --noproxy '*' -s http://127.0.0.1:8889/info \ | grep name: \ | awk '{ print substr($2, 2, length($2) - 2) }'); do nsenter -t $(docker inspect mitigator_data-plane_1 -f '{{ .State.Pid }}') \ -n curl \ --noproxy '*' \ -s http://127.0.0.1:8889/$ports/stats \ > $TMPDIR/CLICK_STATS_$ports.txt done echo "Collecting inspect files of all containers" for inspect in $(docker ps --format "{{.Names}}") do docker inspect $inspect > $TMPDIR/INSPECT_$inspect.json done echo -e "\033[32mGetting state of containers was successful \033[0m" echo "-------------------------------Collect ethernet interfaces information------------------------------" which lshw 2>&1 > /dev/null if [ $? -eq 0 ]; then lshw -class network > $TMPDIR/NETWORK_lshw.txt 2>/dev/null else echo -e "\033[31mAttention, the utility lshw not installed, if necessary, install and run the script again \033[0m" fi which ethtool 2>&1 > /dev/null if [ $? -eq 0 ]; then for interfaces in $(ip -o link show | awk -F': ' '{print $2}') do echo "Copying information of $interfaces state" ethtool -i $interfaces > $TMPDIR/NETWORK_$interfaces.txt 2>/dev/null done echo -e "\033[32mCollection was successful \033[0m" else echo -e "\033[31mAttention, the utility ethtool not installed, if necessary, install and run the script again \033[0m" fi echo "-------------------------------Copying current information of system state--------------------------" which curl 2>&1 > /dev/null if [ $? -eq 0 ]; then nsenter -t $(docker inspect mitigator_data-plane_1 -f '{{ .State.Pid }}') -n curl --noproxy '*' -s http://127.0.0.1:8889/settings > $TMPDIR/CLICK_settings.txt nsenter -t $(docker inspect mitigator_data-plane_1 -f '{{ .State.Pid }}') -n curl --noproxy '*' -s http://127.0.0.1:8889/info > $TMPDIR/CLICK_info.txt else echo -e "\033[31mAttention, install curl and run this script again \033[0m" fi dpdk-devbind -s > $TMPDIR/dpdk.txt 2>/dev/null df -ih > $TMPDIR/df_inodes.txt df -h > $TMPDIR/df.txt free -h > $TMPDIR/free.txt ps aux > $TMPDIR/ps.txt dmesg > $TMPDIR/dmesg.txt lscpu > $TMPDIR/lscpu.txt lspci > $TMPDIR/lspci.txt lsmod > $TMPDIR/lsmod.txt uname -a > $TMPDIR/uname.txt cat /etc/issue > $TMPDIR/issue.txt cat /etc/*release > $TMPDIR/release.txt docker ps -a --no-trunc > $TMPDIR/docker_ps.txt docker system df -v > $TMPDIR/docker_df.txt ip a > $TMPDIR/ip_a.txt ip r > $TMPDIR/ip_r.txt ip neigh > $TMPDIR/ip_neigh.txt docker version > $TMPDIR/docker_version.txt docker images > $TMPDIR/docker_images.txt docker-compose --version > $TMPDIR/docker_compose_version.txt docker-compose exec gateway wg > $TMPDIR/docker_exec_gateway_wg.txt cat /proc/meminfo > $TMPDIR/meminfo.txt date > $TMPDIR/date.txt cat /etc/modules > $TMPDIR/modules.txt echo -e "\033[32mCopying was successful \033[0m" echo $DELIMITER echo "--------------------------------Creating the final archive------------------------------------------" tar -czf $MIT/support_archive_$HOSTNAME-$DATE.tgz $TMPDIR/* 2>/dev/null echo -e "\033[32mDone. The archive located here:\033[33m /srv/mitigator/support_archive_$HOSTNAME-$DATE.tgz \033[0m"