]> sourceware.org Git - lvm2.git/blob - scripts/lvm_dump.sh
Fix underquotations in lvm_dump.sh.
[lvm2.git] / scripts / lvm_dump.sh
1 #!/bin/bash
2 # We use some bash-isms (getopts?)
3
4 # Copyright (C) 2007 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 UNAME=uname
34
35 # user may override lvm and dmsetup location by setting LVM_BINARY
36 # and DMSETUP_BINARY respectively
37 LVM=${LVM_BINARY-lvm}
38 DMSETUP=${DMSETUP_BINARY-dmsetup}
39
40 die() {
41 code=$1; shift
42 echo "$@" 1>&2
43 exit $code
44 }
45
46 "$LVM" version >& /dev/null || die 2 "Could not run lvm binary '$LVM'"
47 "$DMSETUP" help >& /dev/null || die 2 "Fatal: could not run dmsetup binary '$DMSETUP'"
48
49 function usage {
50 echo "$0 [options]"
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"
57 echo ""
58
59 exit 1
60 }
61
62 advanced=0
63 clustered=0
64 metadata=0
65 while getopts :acd:hm opt; do
66 case $opt in
67 s) sysreport=1 ;;
68 a) advanced=1 ;;
69 c) clustered=1 ;;
70 d) userdir=$OPTARG ;;
71 h) usage ;;
72 m) metadata=1 ;;
73 :) echo "$0: $OPTARG requires a value:"; usage ;;
74 \?) echo "$0: unknown option $OPTARG"; usage ;;
75 *) usage ;;
76 esac
77 done
78
79 NOW=`$DATE -u +%G%m%d%k%M%S | /usr/bin/tr -d ' '`
80 if test -n "$userdir"; then
81 dir="$userdir"
82 else
83 dirbase="lvmdump-$HOSTNAME-$NOW"
84 dir="$HOME/$dirbase"
85 fi
86
87 test -e $dir && die 3 "Fatal: $dir already exists"
88 $MKDIR -p $dir || die 4 "Fatal: could not create $dir"
89
90 log="$dir/lvmdump.log"
91
92 myecho() {
93 echo "$@"
94 echo "$@" >> "$log"
95 }
96
97 log() {
98 echo "$@" >> "$log"
99 eval "$@"
100 }
101
102 echo " "
103 myecho "Creating dump directory: $dir"
104 echo " "
105
106 if (( $advanced )); then
107 myecho "Gathering LVM volume info..."
108
109 myecho " vgscan..."
110 log "\"$LVM\" vgscan -vvvv > \"$dir/vgscan\" 2>&1"
111
112 myecho " pvscan..."
113 log "\"$LVM\" pvscan -v >> \"$dir/pvscan\" 2>> \"$log\""
114
115 myecho " lvs..."
116 log "\"$LVM\" lvs -a -o +devices >> \"$dir/lvs\" 2>> \"$log\""
117
118 myecho " pvs..."
119 log "\"$LVM\" pvs -a -v > \"$dir/pvs\" 2>> \"$log\""
120
121 myecho " vgs..."
122 log "\"$LVM\" vgs -v > \"$dir/vgs\" 2>> \"$log\""
123 fi
124
125 if (( $clustered )); then
126 myecho "Gathering cluster info..."
127
128 {
129 for i in nodes status services; do
130 cap_i=$(echo $i|tr a-z A-Z)
131 printf "$cap_i:\n----------------------------------\n"
132 log "cman_tool $i 2>> \"$log\""
133 echo
134 done
135
136 echo "LOCKS:"
137 echo "----------------------------------"
138 if [ -f /proc/cluster/dlm_locks ]
139 then
140 echo clvmd > /proc/cluster/dlm_locks
141 cat /proc/cluster/dlm_locks
142 echo
143 echo "RESOURCE DIR:"
144 cat /proc/cluster/dlm_dir
145 echo
146 echo "DEBUG LOG:"
147 cat /proc/cluster/dlm_debug
148 echo
149 fi
150 if [ -f /debug/dlm/clvmd ]
151 then
152 cat /debug/dlm/clvmd
153 echo
154 echo "WAITERS:"
155 cat /debug/dlm/clvmd_waiters
156 echo
157 echo "MASTER:"
158 cat /debug/dlm/clvmd_master
159 fi
160 } > $dir/cluster_info
161 fi
162
163 myecho "Gathering LVM & device-mapper version info..."
164 echo "LVM VERSION:" > "$dir/versions"
165 "$LVM" lvs --version >> "$dir/versions" 2>> "$log"
166 echo "DEVICE MAPPER VERSION:" >> "$dir/versions"
167 "$DMSETUP" --version >> "$dir/versions" 2>> "$log"
168 echo "KERNEL VERSION:" >> "$dir/versions"
169 "$UNAME" -a >> "$dir/versions" 2>> "$log"
170 echo "DM TARGETS VERSIONS:" >> "$dir/versions"
171 "$DMSETUP" targets >> "$dir/versions" 2>> "$log"
172
173 myecho "Gathering dmsetup info..."
174 log "\"$DMSETUP\" info -c > \"$dir/dmsetup_info\" 2>> \"$log\""
175 log "\"$DMSETUP\" table > \"$dir/dmsetup_table\" 2>> \"$log\""
176 log "\"$DMSETUP\" status > \"$dir/dmsetup_status\" 2>> \"$log\""
177
178 myecho "Gathering process info..."
179 log "$PS alx > \"$dir/ps_info\" 2>> \"$log\""
180
181 myecho "Gathering console messages..."
182 log "$TAIL -n 75 /var/log/messages > \"$dir/messages\" 2>> \"$log\""
183
184 myecho "Gathering /etc/lvm info..."
185 log "$CP -a /etc/lvm \"$dir/lvm\" 2>> \"$log\""
186
187 myecho "Gathering /dev listing..."
188 log "$LS -laR /dev > \"$dir/dev_listing\" 2>> \"$log\""
189
190 myecho "Gathering /sys/block listing..."
191 log "$LS -laR /sys/block > \"$dir/sysblock_listing\""
192
193 if (( $metadata )); then
194 myecho "Gathering LVM metadata from Physical Volumes..."
195
196 log "$MKDIR -p \"$dir/metadata\""
197
198 pvs="$("$LVM" pvs --separator , --noheadings --units s --nosuffix -o \
199 name,pe_start 2>> "$log" | $SED -e 's/^ *//')"
200 for line in "$pvs"
201 do
202 test -z "$line" && continue
203 pv="$(echo $line | $CUT -d, -f1)"
204 pe_start="$(echo $line | $CUT -d, -f2)"
205 name="$($BASENAME "$pv")"
206 myecho " $pv"
207 log "$DD if=$pv \"of=$dir/metadata/$name\" bs=512 count=$pe_start 2>> \"$log\""
208 done
209 fi
210
211 if test -z "$userdir"; then
212 lvm_dump="$dirbase.tgz"
213 myecho "Creating report tarball in $HOME/$lvm_dump..."
214 cd "$HOME"
215 "$TAR" czf "$lvm_dump" "$dirbase" 2>/dev/null
216 "$RM" -rf "$dir"
217 fi
218
219 if test "$UID" != "0" && test "$EUID" != "0"; then
220 myecho
221 myecho "WARNING! Running as non-privileged user, dump is likely incomplete!"
222 myecho
223 fi
224
225 exit 0
226
This page took 0.047952 seconds and 6 git commands to generate.