]> sourceware.org Git - lvm2.git/blob - scripts/lvmdump.sh
Refer to details of snapshot of raid problem.
[lvm2.git] / scripts / lvmdump.sh
1 #!/bin/bash
2 # We use some bash-isms (getopts?)
3
4 # Copyright (C) 2007-2010 Red Hat, Inc. All rights reserved.
5 #
6 # This file is part of LVM2.
7 #
8 # This copyrighted material is made available to anyone wishing to use,
9 # modify, copy, or redistribute it subject to the terms and conditions
10 # of the GNU General Public License v.2.
11 #
12 # You should have received a copy of the GNU General Public License
13 # along with this program; if not, write to the Free Software Foundation,
14 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
16 # lvm_dump: This script is used to collect pertinent information for
17 # the debugging of lvm issues.
18
19 # following external commands are used throughout the script
20 # echo and test are internal in bash at least
21 MKDIR=mkdir # need -p
22 TAR=tar # need czf
23 RM=rm # need -rf
24 CP=cp
25 TAIL=tail # we need -n
26 LS=ls # need -la
27 PS=ps # need alx
28 SED=sed
29 DD=dd
30 CUT=cut
31 DATE=date
32 BASENAME=basename
33 UDEVADM=udevadm
34 UNAME=uname
35
36 # user may override lvm and dmsetup location by setting LVM_BINARY
37 # and DMSETUP_BINARY respectively
38 LVM=${LVM_BINARY-lvm}
39 DMSETUP=${DMSETUP_BINARY-dmsetup}
40
41 die() {
42 code=$1; shift
43 echo "$@" 1>&2
44 exit $code
45 }
46
47 "$LVM" version >& /dev/null || die 2 "Could not run lvm binary '$LVM'"
48 "$DMSETUP" version >& /dev/null || DMSETUP=:
49
50 function usage {
51 echo "$0 [options]"
52 echo " -h print this message"
53 echo " -a advanced collection - warning: if lvm is already hung,"
54 echo " then this script may hang as well if -a is used"
55 echo " -m gather LVM metadata from the PVs"
56 echo " -d <directory> dump into a directory instead of tarball"
57 echo " -c if running clvmd, gather cluster data as well"
58 echo " -u gather udev info and context"
59 echo ""
60
61 exit 1
62 }
63
64 advanced=0
65 clustered=0
66 metadata=0
67 udev=0
68 while getopts :acd:hmu opt; do
69 case $opt in
70 s) sysreport=1 ;;
71 a) advanced=1 ;;
72 c) clustered=1 ;;
73 d) userdir=$OPTARG ;;
74 h) usage ;;
75 m) metadata=1 ;;
76 u) udev=1 ;;
77 :) echo "$0: $OPTARG requires a value:"; usage ;;
78 \?) echo "$0: unknown option $OPTARG"; usage ;;
79 *) usage ;;
80 esac
81 done
82
83 NOW=`$DATE -u +%G%m%d%k%M%S | /usr/bin/tr -d ' '`
84 if test -n "$userdir"; then
85 dir="$userdir"
86 else
87 dirbase="lvmdump-$HOSTNAME-$NOW"
88 dir="$HOME/$dirbase"
89 fi
90
91 test -e $dir && die 3 "Fatal: $dir already exists"
92 $MKDIR -p $dir || die 4 "Fatal: could not create $dir"
93
94 log="$dir/lvmdump.log"
95
96 myecho() {
97 echo "$@"
98 echo "$@" >> "$log"
99 }
100
101 log() {
102 echo "$@" >> "$log"
103 eval "$@"
104 }
105
106 warnings() {
107 if test "$UID" != "0" && test "$EUID" != "0"; then
108 myecho "WARNING! Running as non-privileged user, dump is likely incomplete!"
109 elif test "$DMSETUP" = ":"; then
110 myecho "WARNING! Could not run dmsetup, dump is likely incomplete."
111 fi
112 }
113
114 warnings
115
116 myecho "Creating dump directory: $dir"
117 echo " "
118
119 if (( $advanced )); then
120 myecho "Gathering LVM volume info..."
121
122 myecho " vgscan..."
123 log "\"$LVM\" vgscan -vvvv >> \"$dir/vgscan\" 2>&1"
124
125 myecho " pvscan..."
126 log "\"$LVM\" pvscan -v >> \"$dir/pvscan\" 2>> \"$log\""
127
128 myecho " lvs..."
129 log "\"$LVM\" lvs -a -o +devices >> \"$dir/lvs\" 2>> \"$log\""
130
131 myecho " pvs..."
132 log "\"$LVM\" pvs -a -v >> \"$dir/pvs\" 2>> \"$log\""
133
134 myecho " vgs..."
135 log "\"$LVM\" vgs -v >> \"$dir/vgs\" 2>> \"$log\""
136 fi
137
138 if (( $clustered )); then
139 myecho "Gathering cluster info..."
140
141 {
142 for i in nodes status services; do
143 cap_i=$(echo $i|tr a-z A-Z)
144 printf "$cap_i:\n----------------------------------\n"
145 log "cman_tool $i 2>> \"$log\""
146 echo
147 done
148
149 echo "LOCKS:"
150 echo "----------------------------------"
151 if [ -f /proc/cluster/dlm_locks ]
152 then
153 echo clvmd > /proc/cluster/dlm_locks
154 cat /proc/cluster/dlm_locks
155 echo
156 echo "RESOURCE DIR:"
157 cat /proc/cluster/dlm_dir
158 echo
159 echo "DEBUG LOG:"
160 cat /proc/cluster/dlm_debug
161 echo
162 fi
163 if [ -f /debug/dlm/clvmd ]
164 then
165 cat /debug/dlm/clvmd
166 echo
167 echo "WAITERS:"
168 cat /debug/dlm/clvmd_waiters
169 echo
170 echo "MASTER:"
171 cat /debug/dlm/clvmd_master
172 fi
173 } >> $dir/cluster_info
174 fi
175
176 myecho "Gathering LVM & device-mapper version info..."
177 echo "LVM VERSION:" >> "$dir/versions"
178 "$LVM" lvs --version >> "$dir/versions" 2>> "$log"
179 echo "DEVICE MAPPER VERSION:" >> "$dir/versions"
180 "$DMSETUP" --version >> "$dir/versions" 2>> "$log"
181 echo "KERNEL VERSION:" >> "$dir/versions"
182 "$UNAME" -a >> "$dir/versions" 2>> "$log"
183 echo "DM TARGETS VERSIONS:" >> "$dir/versions"
184 "$DMSETUP" targets >> "$dir/versions" 2>> "$log"
185
186 myecho "Gathering dmsetup info..."
187 log "\"$DMSETUP\" info -c >> \"$dir/dmsetup_info\" 2>> \"$log\""
188 log "\"$DMSETUP\" table >> \"$dir/dmsetup_table\" 2>> \"$log\""
189 log "\"$DMSETUP\" status >> \"$dir/dmsetup_status\" 2>> \"$log\""
190
191 # cat as workaround to avoid tty ioctl (selinux)
192 log "\"$DMSETUP\" ls --tree 2>> \"$log\" | cat >> \"$dir/dmsetup_ls_tree\""
193
194 myecho "Gathering process info..."
195 log "$PS alx >> \"$dir/ps_info\" 2>> \"$log\""
196
197 myecho "Gathering console messages..."
198 log "$TAIL -n 75 /var/log/messages >> \"$dir/messages\" 2>> \"$log\""
199
200 myecho "Gathering /etc/lvm info..."
201 log "$CP -a /etc/lvm \"$dir/lvm\" 2>> \"$log\""
202
203 myecho "Gathering /dev listing..."
204 log "$LS -laR /dev >> \"$dir/dev_listing\" 2>> \"$log\""
205
206 myecho "Gathering /sys/block listing..."
207 log "$LS -laR /sys/block >> \"$dir/sysblock_listing\" 2>> \"$log\""
208 log "$LS -laR /sys/devices/virtual/block >> \"$dir/sysblock_listing\" 2>> \"$log\""
209
210 if (( $metadata )); then
211 myecho "Gathering LVM metadata from Physical Volumes..."
212
213 log "$MKDIR -p \"$dir/metadata\""
214
215 pvs="$("$LVM" pvs --separator , --noheadings --units s --nosuffix -o \
216 name,pe_start 2>> "$log" | $SED -e 's/^ *//')"
217 for line in $pvs
218 do
219 test -z "$line" && continue
220 pv="$(echo $line | $CUT -d, -f1)"
221 pe_start="$(echo $line | $CUT -d, -f2)"
222 name="$($BASENAME "$pv")"
223 myecho " $pv"
224 log "$DD if=$pv \"of=$dir/metadata/$name\" bs=512 count=$pe_start 2>> \"$log\""
225 done
226 fi
227
228 if (( $udev )); then
229 myecho "Gathering udev info..."
230
231 udev_dir="$dir/udev"
232
233 log "$MKDIR -p \"$udev_dir\""
234 log "$UDEVADM info --version >> \"$udev_dir/version\" 2>> \"$log\""
235 log "$UDEVADM info --export-db >> \"$udev_dir/db\" 2>> \"$log\""
236 log "$CP -a /etc/udev/udev.conf \"$udev_dir/conf\" 2>> \"$log\""
237 log "$LS -la /lib/udev >> \"$udev_dir/lib_dir\" 2>> \"$log\""
238 log "$CP -aR /etc/udev/rules.d \"$udev_dir/rules_etc\" 2>> \"$log\""
239 log "$CP -aR /lib/udev/rules.d \"$udev_dir/rules_lib\" 2>> \"$log\""
240 fi
241
242 if test -z "$userdir"; then
243 lvm_dump="$dirbase.tgz"
244 myecho "Creating report tarball in $HOME/$lvm_dump..."
245 fi
246
247 warnings
248
249 if test -z "$userdir"; then
250 cd "$HOME"
251 "$TAR" czf "$lvm_dump" "$dirbase" 2>/dev/null
252 "$RM" -rf "$dir"
253 fi
254
255 exit 0
This page took 0.049389 seconds and 5 git commands to generate.