2 # We use some bash-isms (getopts?)
4 # Copyright (C) 2007 Red Hat, Inc. All rights reserved.
6 # This file is part of LVM2.
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.
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
16 # lvm_dump: This script is used to collect pertinent information for
17 # the debugging of lvm issues.
19 # following external commands are used throughout the script
20 # echo and test are internal in bash at least
25 TAIL
=tail # we need -n
35 # user may override lvm and dmsetup location by setting LVM_BINARY
36 # and DMSETUP_BINARY respectively
38 DMSETUP
=${DMSETUP_BINARY-dmsetup}
46 "$LVM" version
>& /dev
/null || die
2 "Could not run lvm binary '$LVM'"
47 "$DMSETUP" version
>& /dev
/null || DMSETUP
=:
51 echo " -h print this message"
52 echo " -a advanced collection - warning: if lvm is already hung,"
53 echo " then this script may hang as well if -a is used"
54 echo " -m gather LVM metadata from the PVs"
55 echo " -d <directory> dump into a directory instead of tarball"
56 echo " -c if running clvmd, gather cluster data as well"
65 while getopts :acd
:hm opt
; do
73 :) echo "$0: $OPTARG requires a value:"; usage
;;
74 \?) echo "$0: unknown option $OPTARG"; usage
;;
79 NOW
=`$DATE -u +%G%m%d%k%M%S | /usr/bin/tr -d ' '`
80 if test -n "$userdir"; then
83 dirbase
="lvmdump-$HOSTNAME-$NOW"
87 test -e $dir && die
3 "Fatal: $dir already exists"
88 $MKDIR -p $dir || die
4 "Fatal: could not create $dir"
90 log
="$dir/lvmdump.log"
103 if test "$UID" != "0" && test "$EUID" != "0"; then
104 myecho
"WARNING! Running as non-privileged user, dump is likely incomplete!"
105 elif test "$DMSETUP" = ":"; then
106 myecho
"WARNING! Could not run dmsetup, dump is likely incomplete."
112 myecho
"Creating dump directory: $dir"
115 if (( $advanced )); then
116 myecho
"Gathering LVM volume info..."
119 log
"\"$LVM\" vgscan -vvvv > \"$dir/vgscan\" 2>&1"
122 log
"\"$LVM\" pvscan -v >> \"$dir/pvscan\" 2>> \"$log\""
125 log
"\"$LVM\" lvs -a -o +devices >> \"$dir/lvs\" 2>> \"$log\""
128 log
"\"$LVM\" pvs -a -v > \"$dir/pvs\" 2>> \"$log\""
131 log
"\"$LVM\" vgs -v > \"$dir/vgs\" 2>> \"$log\""
134 if (( $clustered )); then
135 myecho
"Gathering cluster info..."
138 for i
in nodes status services
; do
139 cap_i
=$
(echo $i|
tr a-z A-Z
)
140 printf "$cap_i:\n----------------------------------\n"
141 log
"cman_tool $i 2>> \"$log\""
146 echo "----------------------------------"
147 if [ -f /proc
/cluster
/dlm_locks
]
149 echo clvmd
> /proc
/cluster
/dlm_locks
150 cat /proc
/cluster
/dlm_locks
153 cat /proc
/cluster
/dlm_dir
156 cat /proc
/cluster
/dlm_debug
159 if [ -f /debug
/dlm
/clvmd
]
164 cat /debug
/dlm
/clvmd_waiters
167 cat /debug
/dlm
/clvmd_master
169 } > $dir/cluster_info
172 myecho
"Gathering LVM & device-mapper version info..."
173 echo "LVM VERSION:" > "$dir/versions"
174 "$LVM" lvs
--version >> "$dir/versions" 2>> "$log"
175 echo "DEVICE MAPPER VERSION:" >> "$dir/versions"
176 "$DMSETUP" --version >> "$dir/versions" 2>> "$log"
177 echo "KERNEL VERSION:" >> "$dir/versions"
178 "$UNAME" -a >> "$dir/versions" 2>> "$log"
179 echo "DM TARGETS VERSIONS:" >> "$dir/versions"
180 "$DMSETUP" targets
>> "$dir/versions" 2>> "$log"
182 myecho
"Gathering dmsetup info..."
183 log
"\"$DMSETUP\" info -c > \"$dir/dmsetup_info\" 2>> \"$log\""
184 log
"\"$DMSETUP\" table > \"$dir/dmsetup_table\" 2>> \"$log\""
185 log
"\"$DMSETUP\" status > \"$dir/dmsetup_status\" 2>> \"$log\""
187 myecho
"Gathering process info..."
188 log
"$PS alx > \"$dir/ps_info\" 2>> \"$log\""
190 myecho
"Gathering console messages..."
191 log
"$TAIL -n 75 /var/log/messages > \"$dir/messages\" 2>> \"$log\""
193 myecho
"Gathering /etc/lvm info..."
194 log
"$CP -a /etc/lvm \"$dir/lvm\" 2>> \"$log\""
196 myecho
"Gathering /dev listing..."
197 log
"$LS -laR /dev > \"$dir/dev_listing\" 2>> \"$log\""
199 myecho
"Gathering /sys/block listing..."
200 log
"$LS -laR /sys/block > \"$dir/sysblock_listing\" 2>> \"$log\""
201 log
"$LS -laR /sys/devices/virtual/block >> \"$dir/sysblock_listing\" 2>> \"$log\""
203 if (( $metadata )); then
204 myecho
"Gathering LVM metadata from Physical Volumes..."
206 log
"$MKDIR -p \"$dir/metadata\""
208 pvs
="$("$LVM" pvs --separator , --noheadings --units s --nosuffix -o \
209 name,pe_start 2>> "$log" | $SED -e 's/^ *//')"
212 test -z "$line" && continue
213 pv
="$(echo $line | $CUT -d, -f1)"
214 pe_start
="$(echo $line | $CUT -d, -f2)"
215 name
="$($BASENAME "$pv")"
217 log
"$DD if=$pv \"of=$dir/metadata/$name\" bs=512 count=$pe_start 2>> \"$log\""
221 if test -z "$userdir"; then
222 lvm_dump
="$dirbase.tgz"
223 myecho
"Creating report tarball in $HOME/$lvm_dump..."
228 if test -z "$userdir"; then
230 "$TAR" czf
"$lvm_dump" "$dirbase" 2>/dev
/null