]> sourceware.org Git - lvm2.git/blob - scripts/lvm_dump.sh
Make lvm_dump.sh capture a listing of /sys/block entries.
[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
22 # user may override lvm and dmsetup location by setting LVM_BINARY
23 # and DMSETUP_BINARY respectively
24 LVM=${LVM_BINARY-lvm}
25 DMSETUP=${DMSETUP_BINARY-dmsetup}
26
27 die() {
28 code=$1; shift
29 echo "$@" 1>&2
30 exit $code
31 }
32
33 # which should error out if the binary is not executable, although i
34 # am not sure we can rely on this
35 which $LVM >& /dev/null || die 2 "Fatal: could not find lvm binary '$LVM'"
36 test -x `which $LVM` || die 2 "Fatal: lvm binary '$LVM' not executable"
37 which $DMSETUP >& /dev/null || die 2 "Fatal: could not find dmsetup binary '$DMSETUP'"
38 test -x `which $DMSETUP` || die 2 "Fatal: dmsetup binary '$DMSETUP' not executable"
39
40 function usage {
41 echo "$0 [options]"
42 echo " -h print this message"
43 echo " -a advanced collection - warning: if lvm is already hung,"
44 echo " then this script may hang as well if -a is used"
45 echo " -m gather LVM metadata from the PVs"
46 echo " -d <directory> dump into a directory instead of tarball"
47 echo " -c if running clvmd, gather cluster data as well"
48 echo ""
49
50 exit 1
51 }
52
53 advanced=0
54 clustered=0
55 metadata=0
56 while getopts :acd:hm opt; do
57 case $opt in
58 s) sysreport=1 ;;
59 a) advanced=1 ;;
60 c) clustered=1 ;;
61 d) userdir=$OPTARG ;;
62 h) usage ;;
63 m) metadata=1 ;;
64 :) echo "$0: $OPTARG requires a value:"; usage ;;
65 \?) echo "$0: unknown option $OPTARG"; usage ;;
66 *) usage ;;
67 esac
68 done
69
70 NOW=`$DATE -u +%G%m%d%k%M%S | /usr/bin/tr -d ' '`
71 if test -n "$userdir"; then
72 dir="$userdir"
73 else
74 dirbase="lvmdump-$HOSTNAME-$NOW"
75 dir="$HOME/$dirbase"
76 fi
77
78 test -e $dir && die 3 "Fatal: $dir already exists"
79 $MKDIR -p $dir || die 4 "Fatal: could not create $dir"
80
81 log="$dir/lvmdump.log"
82
83 myecho() {
84 echo "$@"
85 echo "$@" >> $log
86 }
87
88 log() {
89 echo "$@" >> $log
90 eval "$@"
91 }
92
93 echo " "
94 myecho "Creating dump directory: $dir"
95 echo " "
96
97 if (( $advanced )); then
98 myecho "Gathering LVM volume info..."
99
100 myecho " vgscan..."
101 log "$LVM vgscan -vvvv > $dir/vgscan 2>&1"
102
103 myecho " pvscan..."
104 log "$LVM pvscan -v >> $dir/pvscan 2>> $log"
105
106 myecho " lvs..."
107 log "$LVM lvs -a -o +devices >> $dir/lvs 2>> $log"
108
109 myecho " pvs..."
110 log "$LVM pvs -a -v > $dir/pvs 2>> $log"
111
112 echo " vgs..."
113 log "$LVM vgs -v > $dir/vgs 2>> $log"
114 fi
115
116 if (( $clustered )); then
117 myecho "Gathering cluster info..."
118 echo "STATUS: " > $dir/cluster_info
119 echo "----------------------------------" >> $dir/cluster_info
120 log "cman_tool status >> $dir/cluster_info 2>> $log"
121 echo " " >> $dir/lvm_info
122
123 echo "SERVICES: " >> $dir/cluster_info
124 echo "----------------------------------" >> $dir/cluster_info
125 log "cman_tool services >> $dir/cluster_info 2>> $log"
126 echo " " >> $dir/lvm_info
127 fi
128
129 myecho "Gathering LVM & device-mapper version info..."
130 echo "LVM VERSION:" > $dir/versions
131 $LVM lvs --version >> $dir/versions 2>> $log
132 echo "DEVICE MAPPER VERSION:" >> $dir/versions
133 $DMSETUP --version >> $dir/versions 2>> $log
134
135 myecho "Gathering dmsetup info..."
136 log "$DMSETUP info -c > $dir/dmsetup_info 2>> $log"
137 log "$DMSETUP table > $dir/dmsetup_table 2>> $log"
138 log "$DMSETUP status > $dir/dmsetup_status 2>> $log"
139
140 myecho "Gathering process info..."
141 log "$PS alx > $dir/ps_info 2>> $log"
142
143 myecho "Gathering console messages..."
144 log "$TAIL -n 75 /var/log/messages > $dir/messages 2>> $log"
145
146 myecho "Gathering /etc/lvm info..."
147 log "$CP -a /etc/lvm $dir/lvm 2>> $log"
148
149 myecho "Gathering /dev listing..."
150 log "$LS -laR /dev > $dir/dev_listing 2>> $log"
151
152 myecho "Gathering /sys/block listing..."
153 log "$LS -laR /sys/block > $dir/sysblock_listing"
154
155 if (( $metadata )); then
156 myecho "Gathering LVM metadata from Physical Volumes..."
157
158 log "$MKDIR -p $dir/metadata"
159
160 pvs="$($LVM pvs --separator , --noheadings --units s --nosuffix -o \
161 name,pe_start 2>> $log | $SED -e 's/^ *//')"
162 for line in "$pvs"
163 do
164 test -z "$line" && continue
165 pv="$(echo $line | $CUT -d, -f1)"
166 pe_start="$(echo $line | $CUT -d, -f2)"
167 name="$($BASENAME $pv)"
168 myecho " $pv"
169 log "$DD if=$pv of=$dir/metadata/$name bs=512 count=$pe_start 2>> $log"
170 done
171 fi
172
173 if test -z "$userdir"; then
174 lvm_dump="$dirbase.tgz"
175 myecho "Creating report tarball in $HOME/$lvm_dump..."
176 cd $HOME
177 $TAR czf $lvm_dump $dirbase 2>/dev/null
178 $RM -rf $dir
179 fi
180
181 if test "$UID" != "0" && test "$EUID" != "0"; then
182 myecho
183 myecho "WARNING! Running as non-privileged user, dump is likely incomplete!"
184 myecho
185 fi
186
187 exit 0
188
This page took 0.050256 seconds and 6 git commands to generate.