Created
September 3, 2018 14:55
-
-
Save ljjjustin/e806ca0b4d04b7ea1c6d0dd2ab4f2eba to your computer and use it in GitHub Desktop.
synclog
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 | |
control_hosts="TX-LNSZF-MANAGE-01 TX-LNSZF-MANAGE-04 TX-LNSZF-MANAGE-07" | |
compute_hosts=$(cat /etc/hosts | grep COMPUTE | awk '{print $2}') | |
all_hosts="${control_hosts} ${compute_hosts}" | |
sync_logfiles() { | |
local host=$1 | |
mkdir -p ${host} | |
pushd ${host} | |
echo -n > logfiles | |
# messages | |
(ssh ${host} find /var/log -name "messages-201808[2,3]*") >> logfiles | |
(ssh ${host} find /var/log -name "messages-2018090*") >> logfiles | |
# ovs | |
(ssh ${host} find /var/log -name "ovs-vswitchd.log-201808[2,3]*") >> logfiles | |
(ssh ${host} find /var/log -name "ovs-vswitchd.log-2018090*") >> logfiles | |
(ssh ${host} find /var/log -name "ovsdb-server.log-201808[2,3]*") >> logfiles | |
(ssh ${host} find /var/log -name "ovsdb-server.log-2018090*") >> logfiles | |
# nova-compute | |
(ssh ${host} find /data/log -name "nova-compute.log-201808[2,3]*") >> logfiles | |
(ssh ${host} find /data/log -name "nova-compute.log-2018090*") >> logfiles | |
# openvswitch-agent | |
(ssh ${host} find /data/log -name "openvswitch-agent.log-201808[2,3]*") >> logfiles | |
(ssh ${host} find /data/log -name "openvswitch-agent.log-2018090*") >> logfiles | |
# l3 agent | |
if [[ "${host}" =~ "MANAGE" ]]; then | |
(ssh ${host} find /data/log -name "l3-agent.log-201808[2,3]*") >> logfiles | |
(ssh ${host} find /data/log -name "l3-agent.log-2018090*") >> logfiles | |
fi | |
# rsync | |
rsync -a --files-from logfiles ${host}:/ ./ | |
popd | |
} | |
export -f sync_logfiles | |
decompress_logfiles() { | |
local host=$1 | |
pushd ${host} | |
find -name "*.gz" -print0 | xargs -0 -n1 -P2 -I{} gunzip {} | |
popd | |
} | |
export -f decompress_logfiles | |
# sync log | |
echo ${all_hosts} | xargs -t -n1 -P10 bash -c 'sync_logfiles "$@"' _ | |
# decompress log | |
echo ${all_hosts} | xargs -t -n1 -P2 bash -c 'decompress_logfiles "$@"' _ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment