]> sourceware.org Git - lvm2.git/blob - scripts/lvm_dump.sh
Add more cluster/clvmd information to lvmdump
[lvm2.git] / scripts / lvm_dump.sh
1 #!/bin/bash
2 # we use some bash-isms (getopts?)
3
4 # lvm_dump: This script is used to collect pertinent information for
5 # the debugging of lvm issues.
6
7 # following external commands are used throughout the script
8 # which, echo and test are internal in bash at least
9 MKDIR=mkdir # need -p
10 TAR=tar # need czf
11 RM=rm # need -rf
12 CP=cp
13 TAIL=tail # we need -n
14 LS=ls # need -la
15 PS=ps # need alx
16 SED=sed
17 DD=dd
18 CUT=cut
19 DATE=date
20 BASENAME=basename
21 UNAME=uname
22
23 # user may override lvm and dmsetup location by setting LVM_BINARY
24 # and DMSETUP_BINARY respectively
25 LVM=${LVM_BINARY-lvm}
26 DMSETUP=${DMSETUP_BINARY-dmsetup}
27
28 die() {
29 code=$1; shift
30 echo "$@" 1>&2
31 exit $code
32 }
33
34 # which should error out if the binary is not executable, although i
35 # am not sure we can rely on this
36 which $LVM >& /dev/null || die 2 "Fatal: could not find lvm binary '$LVM'"
37 test -x `which $LVM` || die 2 "Fatal: lvm binary '$LVM' not executable"
38 which $DMSETUP >& /dev/null || die 2 "Fatal: could not find dmsetup binary '$DMSETUP'"
39 test -x `which $DMSETUP` || die 2 "Fatal: dmsetup binary '$DMSETUP' not executable"
40
41 function usage {
42 echo "$0 [options]"
43 echo " -h print this message"
44 echo " -a advanced collection - warning: if lvm is already hung,"
45 echo " then this script may hang as well if -a is used"
46 echo " -m gather LVM metadata from the PVs"
47 echo " -d <directory> dump into a directory instead of tarball"
48 echo " -c if running clvmd, gather cluster data as well"
49 echo ""
50
51 exit 1
52 }
53
54 advanced=0
55 clustered=0
56 metadata=0
57 while getopts :acd:hm opt; do
58 case $opt in
59 s) sysreport=1 ;;
60 a) advanced=1 ;;
61 c) clustered=1 ;;
62 d) userdir=$OPTARG ;;
63 h) usage ;;
64 m) metadata=1 ;;
65 :) echo "$0: $OPTARG requires a value:"; usage ;;
66 \?) echo "$0: unknown option $OPTARG"; usage ;;
67 *) usage ;;
68 esac
69 done
70
71 NOW=`$DATE -u +%G%m%d%k%M%S | /usr/bin/tr -d ' '`
72 if test -n "$userdir"; then
73 dir="$userdir"
74 else
75 dirbase="lvmdump-$HOSTNAME-$NOW"
76 dir="$HOME/$dirbase"
77 fi
78
79 test -e $dir && die 3 "Fatal: $dir already exists"
80 $MKDIR -p $dir || die 4 "Fatal: could not create $dir"
81
82 log="$dir/lvmdump.log"
83
84 myecho() {
85 echo "$@"
86 echo "$@" >> $log
87 }
88
89 log() {
90 echo "$@" >> $log
91 eval "$@"
92 }
93
94 echo " "
95 myecho "Creating dump directory: $dir"
96 echo " "
97
98 if (( $advanced )); then
99 myecho "Gathering LVM volume info..."
100
101 myecho " vgscan..."
102 log "$LVM vgscan -vvvv > $dir/vgscan 2>&1"
103
104 myecho " pvscan..."
105 log "$LVM pvscan -v >> $dir/pvscan 2>> $log"
106
107 myecho " lvs..."
108 log "$LVM lvs -a -o +devices >> $dir/lvs 2>> $log"
109
110 myecho " pvs..."
111 log "$LVM pvs -a -v > $dir/pvs 2>> $log"
112
113 echo " vgs..."
114 log "$LVM vgs -v > $dir/vgs 2>> $log"
115 fi
116
117 if (( $clustered )); then
118 myecho "Gathering cluster info..."
119 echo "NODES: " > $dir/cluster_info
120 echo "----------------------------------" >> $dir/cluster_info
121 log "cman_tool nodes >> $dir/cluster_info 2>> $log"
122 echo " " >> $dir/cluster_info
123
124 echo "STATUS: " > $dir/cluster_info
125 echo "----------------------------------" >> $dir/cluster_info
126 log "cman_tool status >> $dir/cluster_info 2>> $log"
127 echo " " >> $dir/cluster_info
128
129 echo "SERVICES: " >> $dir/cluster_info
130 echo "----------------------------------" >> $dir/cluster_info
131 log "cman_tool services >> $dir/cluster_info 2>> $log"
132 echo " " >> $dir/cluster_info
133
134 echo "LOCKS: " >> $dir/cluster_info
135 echo "----------------------------------" >> $dir/cluster_info
136 if [ -f /proc/cluster/dlm_locks ]
137 then
138 echo "clvmd" > /proc/cluster/dlm_locks
139 cat /proc/cluster/dlm_locks >> $dir/cluster_info
140 echo " " >> $dir/cluster_info
141 echo "RESOURCE DIR: " >> $dir/cluster_info
142 cat /proc/cluster/dlm_dir >> $dir/cluster_info
143 echo " " >> $dir/cluster_info
144 echo "DEBUG LOG: " >> $dir/cluster_info
145 cat /proc/cluster/dlm_debug >> $dir/cluster_info
146 echo " " >> $dir/cluster_info
147 fi
148 if [ -f /debug/dlm/clvmd ]
149 then
150 cat /debug/dlm/clvmd >> $dir/cluster_info
151 echo " " >> $dir/cluster_info
152 echo "WAITERS: " >> $dir/cluster_info
153 cat /debug/dlm/clvmd_waiters >> $dir/cluster_info
154 echo " " >> $dir/cluster_info
155 echo "MASTER: " >> $dir/cluster_info
156 cat /debug/dlm/clvmd_master >> $dir/cluster_info
157 fi
158 fi
159
160 myecho "Gathering LVM & device-mapper version info..."
161 echo "LVM VERSION:" > $dir/versions
162 $LVM lvs --version >> $dir/versions 2>> $log
163 echo "DEVICE MAPPER VERSION:" >> $dir/versions
164 $DMSETUP --version >> $dir/versions 2>> $log
165 echo "KERNEL VERSION:" >> $dir/versions
166 $UNAME -a >> $dir/versions 2>> $log
167 echo "DM TARGETS VERSIONS:" >> $dir/versions
168 $DMSETUP targets >> $dir/versions 2>> $log
169
170 myecho "Gathering dmsetup info..."
171 log "$DMSETUP info -c > $dir/dmsetup_info 2>> $log"
172 log "$DMSETUP table > $dir/dmsetup_table 2>> $log"
173 log "$DMSETUP status > $dir/dmsetup_status 2>> $log"
174
175 myecho "Gathering process info..."
176 log "$PS alx > $dir/ps_info 2>> $log"
177
178 myecho "Gathering console messages..."
179 log "$TAIL -n 75 /var/log/messages > $dir/messages 2>> $log"
180
181 myecho "Gathering /etc/lvm info..."
182 log "$CP -a /etc/lvm $dir/lvm 2>> $log"
183
184 myecho "Gathering /dev listing..."
185 log "$LS -laR /dev > $dir/dev_listing 2>> $log"
186
187 myecho "Gathering /sys/block listing..."
188 log "$LS -laR /sys/block > $dir/sysblock_listing"
189
190 if (( $metadata )); then
191 myecho "Gathering LVM metadata from Physical Volumes..."
192
193 log "$MKDIR -p $dir/metadata"
194
195 pvs="$($LVM pvs --separator , --noheadings --units s --nosuffix -o \
196 name,pe_start 2>> $log | $SED -e 's/^ *//')"
197 for line in "$pvs"
198 do
199 test -z "$line" && continue
200 pv="$(echo $line | $CUT -d, -f1)"
201 pe_start="$(echo $line | $CUT -d, -f2)"
202 name="$($BASENAME $pv)"
203 myecho " $pv"
204 log "$DD if=$pv of=$dir/metadata/$name bs=512 count=$pe_start 2>> $log"
205 done
206 fi
207
208 if test -z "$userdir"; then
209 lvm_dump="$dirbase.tgz"
210 myecho "Creating report tarball in $HOME/$lvm_dump..."
211 cd $HOME
212 $TAR czf $lvm_dump $dirbase 2>/dev/null
213 $RM -rf $dir
214 fi
215
216 if test "$UID" != "0" && test "$EUID" != "0"; then
217 myecho
218 myecho "WARNING! Running as non-privileged user, dump is likely incomplete!"
219 myecho
220 fi
221
222 exit 0
223
This page took 0.048305 seconds and 6 git commands to generate.