source: server/lib/supportsave

qndtest
Last change on this file was ca75d29, checked in by Ramón M. Gómez <ramongomez@…>, 4 years ago

#957: Script supportsave uses global functions to show help and manage errors.

  • Property mode set to 100755
File size: 8.5 KB
Line 
1#!/bin/bash
2
3#/**
4#@file    supportsave
5#@brief   This script creates a tarball containing all logs and necesary files in order to debug a remote system.
6#@brief   Initially the tarball would be manually sent by the final user to the support team.
7#@brief   On a second stage this support save would be inclued in the GUI.
8#@usage   supportsave
9#@version 1.1.0
10#@author  Fredy <aluque@soleta.eu>
11#@date    2018-03-01
12#*/ ##
13
14
15# Basic structure
16# Date, Hostname and Paths
17# List of desired files to be saved
18# Usefull system commands output to be saved (ie. uname -a > file.txt)
19# Final compression
20
21PATH=/bin:/sbin:/usr/bin:/usr/sbin
22
23tmp_name=`date +%Y%m%d_%H%M`
24hostname=`hostname`
25home_dir="/opt/opengnsys"
26ss_dir="supportsave_${hostname}_${tmp_name}"
27prefix="/tmp"
28
29if [ ! -d ${home_dir} ]; then
30    echo "ERROR: The OpenGnsys directory does not exist." >&2
31    exit 1
32fi
33
34source ${home_dir}/lib/ogfunctions.sh || exit 1
35
36[ "$*" == "help" ] && help
37[ "$*" == "version" ] && version
38[ "$*" ] && raiseError usage
39[ "$(whoami)" != "root" ] && raiseError access "Need to be root."
40
41if [ -d "$1" ]; then
42    prefix=${1}
43fi
44
45backup_dir="${prefix}/${ss_dir}"
46
47config_paths="${home_dir}/etc ${home_dir}/tftpboot/menu.lst ${home_dir}/client/etc ${home_dir}/log /etc/default/opengnsys"
48other_paths="/var/log/syslog* /var/log/messages*"
49
50echo "Saving information for support in the path ${backup_dir}.tar.gz"
51mkdir -p $backup_dir
52
53
54echo "Saving system information:"
55#################################
56
57echo "- System version"
58if [ -r /etc/os-release ]; then
59    cat /etc/os-release                 >> $backup_dir/operating_system.txt 2>&1
60elif which lsb_release &>/dev/null; then
61    lsb_release -a                      >> $backup_dir/operating_system.txt 2>&1
62elif [ -r /etc/system-release ]; then
63    cat /etc/system-release             >> $backup_dir/operating_system.txt 2>&1
64fi
65
66echo "- Hardware"
67echo "--- hostname ---"                 >> $backup_dir/hardware.txt
68hostname                                >> $backup_dir/hardware.txt 2>&1
69echo -e "\n--- dmidecode ---"           >> $backup_dir/hardware.txt
70dmidecode                               >> $backup_dir/hardware.txt 2>&1
71echo -e "\n--- lshw -short ---"         >> $backup_dir/hardware.txt
72lshw -short                             >> $backup_dir/hardware.txt 2>&1
73echo -e "\n--- lspci ---"               >> $backup_dir/hardware.txt
74lspci                                   >> $backup_dir/hardware.txt 2>&1
75echo -e "\n--- lsusb ---"               >> $backup_dir/hardware.txt
76lsusb                                   >> $backup_dir/hardware.txt 2>&1
77
78echo "- Kernel"
79echo "--- uname -a ---"                 >> $backup_dir/kernel.txt
80uname -a                                >> $backup_dir/kernel.txt 2>&1
81echo -e "\n--- lsmod ---"               >> $backup_dir/kernel.txt
82lsmod                                   >> $backup_dir/kernel.txt 2>&1
83echo -e "\n--- Boot parameters ---"     >> $backup_dir/kernel.txt
84cat /proc/cmdline                       >> $backup_dir/kernel.txt 2>&1
85echo "- Kernel boot messages"
86echo -e "\n--- dmesg ---"                    >> $backup_dir/kernel.txt
87dmesg                                   >> $backup_dir/kernel.txt 2>&1
88
89echo "- Packages"
90if [ -f /etc/debian_version ]; then
91    echo "--- dpkg -l ---"              >> $backup_dir/package_list.txt
92    dpkg -l                             >> $backup_dir/package_list.txt 2>&1
93elif [ -f /etc/redhat-release ]; then
94    echo "--- rpm -qa ---"              >> $backup_dir/package_list.txt
95    rpm -qa | sort                      >> $backup_dir/package_list.txt 2>&1
96else
97    echo "- WARNING: The package list can not be retrieved" | tee $backup_dir/package_list.txt
98fi
99
100echo "- Processes"
101echo "ps aux"                           >> $backup_dir/ps.txt
102ps aux                                  >> $backup_dir/ps.txt 2>&1
103
104echo "- Resources"
105echo "--- Uptime information ---"       >> $backup_dir/system_resources.txt
106uptime                                  >> $backup_dir/system_resources.txt 2>&1
107echo -e "\n--- Memory information ---"  >> $backup_dir/system_resources.txt
108free -m                                 >> $backup_dir/system_resources.txt 2>&1
109echo -e "\n--- CPU information ---"     >> $backup_dir/system_resources.txt
110cat /proc/cpuinfo                       >> $backup_dir/system_resources.txt 2>&1
111echo -e "\n--- TOP information ---"     >> $backup_dir/system_resources.txt
112top -b -n1                              >> $backup_dir/system_resources.txt 2>&1
113
114echo "- Filesystems"
115echo "--- cat /etc/fstab ---"           >> $backup_dir/filesystems.txt
116cat /etc/fstab                          >> $backup_dir/filesystems.txt 2>&1
117echo -e "\n--- df -h ---"               >> $backup_dir/filesystems.txt
118df -h                                   >> $backup_dir/filesystems.txt 2>&1
119echo -e "\n--- blkid ---"               >> $backup_dir/filesystems.txt
120blkid                                   >> $backup_dir/filesystems.txt 2>&1
121echo -e "\n--- lsblk -Jbp ---"          >> $backup_dir/filesystems.txt
122lsblk -Jbp                              >> $backup_dir/filesystems.txt 2>&1
123
124
125echo "Saving network information:"
126##################################
127
128echo "- Interfaces"
129ifconfig -a                             >> $backup_dir/ifconfig.txt 2>&1
130ip link show                            >> $backup_dir/ip_link.txt 2>&1
131ip addr show                            >> $backup_dir/ip_addr.txt 2>&1
132
133echo "- Routes"
134for i in `cat /etc/iproute2/rt_tables  | grep "table_" | awk {'print $2'}`
135do
136    echo "ip route list table $i"       >> $backup_dir/route.txt
137    ip route list table $i              >> $backup_dir/route.txt 2>&1
138done
139echo "ip route list table main"         >> $backup_dir/route.txt
140ip route list table main                >> $backup_dir/route.txt 2>&1
141echo "ip rule list"                     >> $backup_dir/route.txt
142ip rule list                            >> $backup_dir/route.txt 2>&1
143
144echo "- Sockets"
145echo "netstat -putan"                   >> $backup_dir/netstat.txt
146netstat -putan                          >> $backup_dir/netstat.txt 2>&1
147echo "netstat -nr"                      >> $backup_dir/netstat.txt
148netstat -nr                             >> $backup_dir/netstat.txt 2>&1
149
150echo "- Netfilter"
151echo "Filter table "                    >> $backup_dir/netfilter.txt
152iptables -nL -t filter                  >> $backup_dir/netfilter.txt 2>&1
153echo -e "\nNAT table "                  >> $backup_dir/netfilter.txt
154iptables -nL -t nat                     >> $backup_dir/netfilter.txt 2>&1
155echo -e "\nMangle table "               >> $backup_dir/netfilter.txt
156iptables -nL -t mangle                  >> $backup_dir/netfilter.txt 2>&1
157echo -e "\nRaw table "                  >> $backup_dir/netfilter.txt
158iptables -nL -t raw                     >> $backup_dir/netfilter.txt 2>&1
159
160echo "- nf_conntrack"
161if which conntrack &>/dev/null; then
162    conntrack -L                        >> $backup_dir/conntrack.txt 2>&1
163fi
164
165echo "- ipset"
166if which ipset &>/dev/null; then
167    ipset save                          >> $backup_dir/ipset_tables.txt 2>&1
168fi
169
170echo "Saving OpenGnsys information:"
171##################################
172
173echo "- OpenGnsys version"
174#echo `dpkg -l | grep opengnsys\  | awk '{print $3}'` > $backup_dir/opengnsys_version
175curl -ks --connect-timeout 10 https://localhost/opengnsys/rest/info | jq . > ${backup_dir}/opengnsys_version.txt 2>/dev/null
176if [ ! -s ${backup_dir}/opengnsys_version.txt ]; then
177    cp -a ${home_dir}/doc/VERSION.txt ${backup_dir}/opengnsys_version.txt 2>&1
178fi
179
180echo "- Directory list"
181ls -Ral ${home_dir}                     >> $backup_dir/opengnsys_files.txt 2>&1
182
183if [ -r ${home_dir}/etc/ogAdmServer.cfg ]; then
184    echo "- Database schema"
185    source ${home_dir}/etc/ogAdmServer.cfg
186    mysqldump -u "$USUARIO" -p"$PASSWORD" -d "$CATALOG" >> ${backup_dir}/opengnsys_schema.sql 2>&1
187else
188    echo "- WARNING: The OpenGnsys database can not be accessed" | tee ${backup_dir}/db_schema.txt
189fi
190
191echo "- Configuration and log files"
192# Looking for huge log files (> 1 MB).
193for log in $(find ${home_dir}/log -name "*.log" -size +1024 -print); do
194    # Copying last 5000 lines and excluding file.
195    tail -5000 ${log} > ${log}-tail5k 2>&1
196    config_paths="$config_paths --exclude=${log}"
197done
198tar zcf ${backup_dir}/opengnsys_config.tar.gz ${config_paths} 2>/dev/null
199
200echo "Saving other files"
201##############################
202tar zcf ${backup_dir}/logs.tar.gz ${other_paths} 2>/dev/null
203
204echo "Packing supportsave"
205##########################
206cd ${prefix}
207tar zcf ${ss_dir}.tar.gz ${ss_dir} 2>/dev/null
208cd - >/dev/null
209
210echo "Cleaning temporal files"
211##########################
212rm -rf ${backup_dir} ${home_dir}/log/*-tail5k
213
214ls -lh ${backup_dir}.tar.gz
Note: See TracBrowser for help on using the repository browser.