source: server/lib/supportsave @ ddb3298

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since ddb3298 was ddb3298, checked in by Fredy <aluque@…>, 7 years ago

New feature first commit

  • Property mode set to 100644
File size: 8.4 KB
RevLine 
[ddb3298]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
79
80echo "- Packages"
81if [ -f /etc/debian_version ]; then
82    echo "--- dpkg -l ---"              >> $backup_dir/package_list.txt
83    dpkg -l                             >> $backup_dir/package_list.txt 2>&1
84elif [ -f /etc/redhat-release ]; then
85    echo "--- rpm -qa ---"              >> $backup_dir/package_list.txt
86    rpm -qa | sort                      >> $backup_dir/package_list.txt 2>&1
87else
88    echo "- WARNING: The package list can not be retrieved" | tee $backup_dir/package_list.txt
89fi
90
91echo "- Processes"
92echo "ps aux"                           >> $backup_dir/ps.txt
93ps aux                                  >> $backup_dir/ps.txt 2>&1
94
95echo "- Resources"
96echo "--- Uptime information ---"       >> $backup_dir/system_resources.txt
97uptime                                  >> $backup_dir/system_resources.txt 2>&1
98echo -e "\n--- Memory information ---"  >> $backup_dir/system_resources.txt
99free -m                                 >> $backup_dir/system_resources.txt 2>&1
100echo -e "\n--- CPU information ---"     >> $backup_dir/system_resources.txt
101cat /proc/cpuinfo                       >> $backup_dir/system_resources.txt 2>&1
102echo -e "\n--- TOP information ---"     >> $backup_dir/system_resources.txt
103top -b -n1                              >> $backup_dir/system_resources.txt 2>&1
104
105echo "- Filesystems"
106echo "--- cat /etc/fstab ---"           >> $backup_dir/filesystems.txt
107cat /etc/fstab                          >> $backup_dir/filesystems.txt 2>&1
108echo -e "\n--- df -h ---"               >> $backup_dir/filesystems.txt
109df -h                                   >> $backup_dir/filesystems.txt 2>&1
110echo -e "\n--- blkid ---"               >> $backup_dir/filesystems.txt
111blkid                                   >> $backup_dir/filesystems.txt 2>&1
112echo -e "\n--- lsblk -Jbp ---"          >> $backup_dir/filesystems.txt
113lsblk -Jbp                              >> $backup_dir/filesystems.txt 2>&1
114
115
116echo "Saving network information:"
117##################################
118
119echo "- Interfaces"
120ifconfig -a                             >> $backup_dir/ifconfig.txt 2>&1
121ip link show                            >> $backup_dir/ip_link.txt 2>&1
122ip addr show                            >> $backup_dir/ip_addr.txt 2>&1
123
124echo "- Routes"
125for i in `cat /etc/iproute2/rt_tables  | grep "table_" | awk {'print $2'}`
126do
127    echo "ip route list table $i"       >> $backup_dir/route.txt
128    ip route list table $i              >> $backup_dir/route.txt 2>&1
129done
130echo "ip route list table main"         >> $backup_dir/route.txt
131ip route list table main                >> $backup_dir/route.txt 2>&1
132echo "ip rule list"                     >> $backup_dir/route.txt
133ip rule list                            >> $backup_dir/route.txt 2>&1
134
135echo "- Sockets"
136echo "netstat -putan"                   >> $backup_dir/netstat.txt
137netstat -putan                          >> $backup_dir/netstat.txt 2>&1
138echo "netstat -nr"                      >> $backup_dir/netstat.txt
139netstat -nr                             >> $backup_dir/netstat.txt 2>&1
140
141echo "- Netfilter"
142echo "Filter table "                    >> $backup_dir/netfilter.txt
143iptables -nL -t filter                  >> $backup_dir/netfilter.txt 2>&1
144echo -e "\nNAT table "                  >> $backup_dir/netfilter.txt
145iptables -nL -t nat                     >> $backup_dir/netfilter.txt 2>&1
146echo -e "\nMangle table "               >> $backup_dir/netfilter.txt
147iptables -nL -t mangle                  >> $backup_dir/netfilter.txt 2>&1
148echo -e "\nRaw table "                  >> $backup_dir/netfilter.txt
149iptables -nL -t raw                     >> $backup_dir/netfilter.txt 2>&1
150
151echo "- nf_conntrack"
152if which conntrack &>/dev/null; then
153    conntrack -L                        >> $backup_dir/conntrack.txt 2>&1
154fi
155
156echo "- ipset"
157if which ipset &>/dev/null; then
158    ipset save                          >> $backup_dir/ipset_tables.txt 2>&1
159fi
160
161echo "Saving OpenGnsys information:"
162##################################
163
164echo "- OpenGnsys version"
165#echo `dpkg -l | grep opengnsys\  | awk '{print $3}'` > $backup_dir/opengnsys_version
166curl -ks --connect-timeout 10 https://localhost/opengnsys/rest/info | jq . > ${backup_dir}/opengnsys_version.txt 2>/dev/null
167if [ ! -s ${backup_dir}/opengnsys_version.txt ]; then
168    cp -a ${home_dir}/doc/VERSION.txt ${backup_dir}/opengnsys_version.txt 2>&1
169fi
170
171echo "- Directory list"
172ls -Ral ${home_dir}                     >> $backup_dir/opengnsys_files.txt 2>&1
173
174if [ -r ${home_dir}/etc/ogAdmServer.cfg ]; then
175    echo "- Database schema"
176    source ${home_dir}/etc/ogAdmServer.cfg
177    mysqldump -u "$USUARIO" -p"$PASSWORD" -d "$CATALOG" >> ${backup_dir}/opengnsys_schema.sql 2>&1
178else
179    echo "- WARNING: The OpenGnsys database can not be accessed" | tee ${backup_dir}/db_schema.txt
180fi
181
182echo "- Configuration and log files"
183# Looking for huge log files (> 1 MB).
184for log in $(find ${home_dir}/log -name "*.log" -size +1024 -print); do
185    # Copying last 5000 lines and excluding file.
186    tail -5000 ${log} > ${log}-tail5k 2>&1
187    config_paths="$config_paths --exclude=${log}"
188done
189tar zcf ${backup_dir}/opengnsys_config.tar.gz ${config_paths} 2>/dev/null
190
191echo "Saving other files"
192##############################
193tar zcf ${backup_dir}/logs.tar.gz ${other_paths} 2>/dev/null
194
195echo "Packing supportsave"
196##########################
197cd ${prefix}
198tar zcf ${ss_dir}.tar.gz ${ss_dir} 2>/dev/null
199cd - >/dev/null
200
201echo "Cleaning temporal files"
202##########################
203rm -rf ${backup_dir} ${home_dir}/log/*-tail5k
204
205ls -lh ${backup_dir}.tar.gz
Note: See TracBrowser for help on using the repository browser.