source: server/lib/supportsave @ cae6338

918-git-images-111dID-1020_logrotateBugID-1037_Mostrar.TipoDisco.WebID-1038_Muestra.el.numero.de.ordenadoresID-1039_Asignar_Disco.Particion.Imagen.AccesoRemotoID-824_Iniciar.Sistema.Restauradodevel-ogadmserver-for-masterdisk-imagemainmaster-1037opengnsys-1.1.1dpreqndtest
Last change on this file since cae6338 was 5ed4db4, checked in by Fredy <aluque@…>, 6 years ago

Added boot messages

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