fixed autotools build, broken since r466, inhandlers/Makefile.am
[matthijs/upstream/backupninja.git] / handlers / sys.in
1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2 #
3 # this handler will save various reports of vital system information.
4 # by default, all the reports are enabled and are saved in /var/backups.
5 #
6 # (1) a list of all the packages installed and removed.
7 #     this file can be used to restore the state of installed packages
8 #     by running "dpkg --set-selections < dpkg-selections.txt
9
10 # (2) the partition table of all disks. 
11 #     this partition table can be used to format another disk of
12 #     the same size. this can be handy if using software raid and 
13 #     you have a disk go bad. just replace the disk and partition it
14 #     by running "sfdisk /dev/sdb < partitions.sdb.txt"
15 #     (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
16 #
17 # (3) hardware information. 
18 #     write to a text file the important things which hwinfo can gleen.
19 #
20
21 if [ -f /etc/debian_version ]
22 then
23    os=debian
24    debug "Debian detected"
25    osversion="/etc/debian_version"
26 elif [ -f /etc/redhat-release ]
27 then
28    os=redhat
29    debug "Redhat detected"
30    osversion="/etc/redhat-release"
31 else
32    warning "Unknown OS detected!"
33 fi
34
35 getconf packages yes
36 getconf dosfdisk yes
37 getconf dohwinfo yes
38 if [ $os = "debian" ]
39 then
40    getconf packagesfile /var/backups/dpkg-selections.txt
41    getconf packagemgr   `which dpkg`
42    getconf packagemgroptions ' --get-selections *'
43 elif [ $os = "redhat" ]
44 then
45    getconf packagesfile  /var/backups/rpmpackages.txt 
46    getconf packagemgr   `which rpm`
47    getconf packagemgroptions    ' -qa '
48
49    getconf SYSREPORT `which sysreport`
50    getconf sysreport_options ' -norpm '
51 else
52    getconf packagesfile /var/backups/unknownOS.txt
53 fi
54 packagemgroptions="${packagemgroptions//__star__/*}"
55
56 getconf partitions yes
57 getconf partitionsfile /var/backups/partitions.__star__.txt
58
59 getconf hardware yes
60 getconf hardwarefile /var/backups/hardware.txt
61
62 getconf sysreport yes
63 getconf sysreportfile /var/backups/sysreport.txt
64
65 getconf SFDISK `which sfdisk`
66 getconf HWINFO `which hwinfo`
67 getconf sfdisk_options ""
68 getconf hwinfo_options ""
69
70 # See if vservers are configured
71 local usevserver=no
72 if [ $vservers_are_available = yes ]
73 then
74    info "vserver method enabled"
75    usevserver=yes
76 fi
77
78 ## PACKAGES ##############################
79
80 #
81 # here we grab a list of the packages installed and removed.
82 #
83
84 if [ "$packages" == "yes" ]; then
85
86    if [ $usevserver = yes ]; then
87       info "vserver root directory set to: $VROOTDIR"
88       for vserver in $found_vservers; do
89          info "examining vserver: $vserver"
90          # is it running ?
91          $VSERVERINFO -q $vserver RUNNING
92          if [ $? -ne 0 ]; then
93             warning "The vserver $vserver is not running."
94             continue
95          fi
96          # is $packagemgr available inside $vserver ?
97          if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which $packagemgr`" ]; then
98             warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
99             continue
100          fi
101          # don't expand * since it can be used in $packagemgroptions
102          set -o noglob
103          debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
104          $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
105          set +o noglob
106       done
107    fi
108    
109    # We want to perform this on the host as well
110    if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then 
111       warning "can't find ${packagemgr}, skipping installed packages report."
112    else
113       # don't expand * since it can be used in $packagemgroptions
114       set -o noglob
115       debug "$packagemgr $packagemgroptions > $packagesfile"
116       $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
117       set +o noglob
118    fi
119
120 fi
121
122 ## System report ##############################
123
124 #
125 # here we grab a bunch of system stuff for a report
126 #
127
128 export STATUS
129
130 HASHES="#################################################################"
131 DASHES="-----------------------------------------------------------------"
132
133 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
134
135
136 catiffile () {
137    echo $HASHES >> $sysreportfile
138    echo "# $STATUS" >> $sysreportfile
139    echo $HASHES >> $sysreportfile
140    if [ -f $1 ]; then
141       echo "file: $1" >> $sysreportfile
142       echo $DASHES >> $sysreportfile
143       cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
144    fi
145    if [ -d $1 ]; then
146       echo "directory: $1" >> $sysreportfile
147       echo $DASHES >> $sysreportfile
148       for file in `find $1 -maxdepth 3 -noleaf -type f`
149       do
150        catiffile $file
151       done
152    fi
153    echo $DASHES >> $sysreportfile
154
155
156 catifexec () {
157    echo $HASHES >> $sysreportfile
158    echo "# $STATUS" >> $sysreportfile
159    echo $HASHES >> $sysreportfile
160    $1  >> $sysreportfile 2>&1 || info "executing of $1 failed"
161 }
162    
163
164 STATUS="Determining $os version:"
165 catiffile $osversion
166
167 STATUS="Determinding your current hostname: " 
168 catifexec "/bin/hostname"
169
170 STATUS="Getting the date:"
171 catifexec "/bin/date"
172
173 STATUS="Checking your systems current uptime and load average:"
174 catifexec "/usr/bin/uptime"
175
176 STATUS="Checking available memory:"
177 catifexec "/usr/bin/free"
178
179 STATUS="Checking free disk space:"
180 catifexec "/bin/df" "-al"
181
182 STATUS="Collecting what services run at what run level:"
183 if [ $os = "redhat" ]; then
184    catifexec "/sbin/chkconfig --list"
185    STATUS="Collecting information about /etc/rc.d:"
186    catiffile "/bin/ls /etc/rc.d/rc*.d/"
187
188 elif [ $os = "debian" ]; then
189     for level in 0 1 2 3 4 5 6 S; do
190        echo "Level: $level" >> $sysreportfile
191        for f in /etc/rc${level}.d/*; do
192         # Remove /etc/Knn or Snn from beginning
193           ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
194           if [ $f != $ff ]; then
195              echo $ff >> $sysreportfile
196           fi
197        done
198        echo "" >> $sysreportfile
199     done
200 fi
201
202 STATUS="Getting bootloader information:"
203 catifexec "/bin/ls -alR /boot"
204
205 # This covers sparc, alpha, and intel (respectively)
206 # updated for grub -mpg
207 if [ -f /etc/silo.conf ]; then
208   STATUS="Collecting information about the boot process (silo):"
209   catiffile "/etc/silo.conf"
210 fi
211 if [ -f /etc/milo.conf ]; then
212   STATUS="Collecting information about the boot process (milo):"
213   catiffile "/etc/milo.conf"
214 fi
215 if [ -f /etc/lilo.conf ]; then
216   STATUS="Collecting information about the boot process (lilo):"
217   catiffile "/etc/lilo.conf"
218   catifexec "/sbin/lilo -q"
219 fi
220 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
221   STATUS="Collecting information about the boot process (grub.conf):"
222   catiffile "/boot/grub/grub.conf"
223   STATUS="Collecting information about the boot process (grub.map):"
224   catiffile "/boot/grub/device.map"
225 fi
226 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
227   STATUS="Gathering information on cluster setup"
228   # 2.1 AS
229   if [ -f /etc/cluster.conf ] ; then
230     catiffile "/etc/cluster.conf"
231   fi
232   # Taroon
233   if [ -f /etc/cluster.xml ] ; then
234     catiffile "/etc/cluster.xml"
235   fi
236 fi
237
238 STATUS="Gathering sysctl information (sysctl -a):"
239 catiffile "sysctl -a 2>/dev/null"
240 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
241 catiffile "/etc/sysctl.conf"
242
243 STATUS="Gathering IP information (/sbin/ifconfig):"
244 catifexec "/sbin/ifconfig -a"
245
246 STATUS="Gathering additional IP information (/bin/ip addr list):"
247 catifexec "/bin/ip addr list"
248
249 STATUS="Checking network routes:"
250 catifexec "/sbin/route -n"
251
252 STATUS="Collecting Name Service Switch config information:"
253 catiffile "/etc/nsswitch.conf"
254
255 STATUS="Collecting information about system authentication (pam):"
256 catiffile "/etc/pam.conf"
257 catiffile "/etc/pam.d"
258
259 echo
260 echo "Getting information about the kernel."
261 echo
262 STATUS="Getting kernel version:"
263 catifexec "/bin/uname" "-a"
264 STATUS="Checking module information:"
265 catifexec "/sbin/lsmod"
266 for x  in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null 
267 ) ; do
268   STATUS="Checking module information $x:"
269   catifexec "/sbin/modinfo  $x"
270 done
271
272 STATUS="Currently getting ksysms information:"
273 catifexec "/sbin/ksyms"
274
275 STATUS="Gathering information about your filesystems:"
276 catiffile "/proc/filesystems"
277
278 STATUS="Gathering information about your system stat:"
279 catiffile "/proc/stat"
280
281 STATUS="Gathering information about your partitions:"
282 catiffile "/proc/partitions"
283
284 STATUS="Gathering information about your ksyms:"
285 catiffile "/proc/ksyms"
286
287 STATUS="Gathering information about slabinfo:"
288 catiffile "/proc/slabinfo"
289
290 # Added support to cover for the new modules.conf layout in Red Hat 7
291 STATUS="Collecting information regarding kernel modules"
292 VER=`uname -r`
293 catiffile "/lib/modules/$VER/modules.dep"
294 if [ -f /etc/conf.modules ]; then
295   STATUS="Collecting information regarding kernel modules (conf.modules)"
296   catiffile "/etc/conf.modules"
297 fi
298 if [ -f /etc/modules.conf ]; then
299   STATUS="Collecting information regarding kernel modules (modules.conf)"
300   catiffile "/etc/modules.conf"
301 fi
302 if [ -f /etc/modprobe.conf ]; then
303   STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
304   catiffile "/etc/modprobe.conf"
305 fi
306
307 # dkms status
308 if [ -x /usr/sbin/dkms ] ; then
309    STATUS="Gathering current status of modules, versions and kernels (dkms):"
310   catifexec "/usr/sbin/dkms" "status"
311 fi
312
313 if [ -f /etc/sysconfig/isdncard ] ; then
314   STATUS="Gathering information about ISDN:"
315   catiffile "/etc/sysconfig/isdncard"
316 fi
317
318 STATUS="Collecting information from the proc directory:"
319 catiffile "/proc/pci"
320
321 STATUS="Getting kernel command line"
322 catiffile "/proc/cmdline"
323
324 STATUS="Gathering information about your CPU:"
325 catiffile "/proc/cpuinfo"
326
327 STATUS="Gathering information about your Ram:"
328 catiffile "/proc/meminfo"
329
330 STATUS="Gathering information about your ioports:"
331 catiffile "/proc/ioports"
332
333 STATUS="Gathering information about your interrupts:"
334 catiffile "/proc/interrupts"
335
336 STATUS="Gathering information about your scsi devices:"
337 catiffile "/proc/scsi"
338
339 STATUS="Gathering information about your dma:"
340 catiffile "/proc/dma"
341
342 STATUS="Gathering information about your devices (/proc/devices):"
343 catiffile "/proc/devices"
344
345 STATUS="Gathering information about your rtc:"
346 catiffile "/proc/rtc"
347
348 STATUS="Gathering information about your ide drivers:"
349 catiffile "/proc/ide"
350
351 STATUS="Gathering information about your bus:"
352 catifexec lspci
353 catiffile "/proc/bus"
354
355 echo
356 echo "Getting disk and filesystem information."
357 echo
358
359 STATUS="Collecting information from /etc/fstab:"
360 catiffile "/etc/fstab"
361
362 STATUS="Collecting disk partition information:"
363 catifexec "fdisk -l"
364
365 STATUS="Checking mounted file systems (mount) "
366 catifexec "/bin/mount"
367
368 STATUS="Checking mounted file systems (/proc/mounts)"
369 catiffile "/proc/mounts"
370
371 STATUS="Collecting Software RAID information (/proc/mdstat)"
372 catiffile "/proc/mdstat"
373
374 STATUS="Collecting Software RAID information (/etc/raidtab)"
375 catiffile "/etc/raidtab"
376
377 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
378 catiffile "/etc/mdadm.conf"
379
380 STATUS="Collecting Automount information (auto.master)"
381 catiffile "/etc/auto.master"
382
383 STATUS="Collecting Automount information (auto.misc)"
384 catiffile "/etc/auto.misc"
385
386 STATUS="Collecting Automount information (auto.net)"
387 catiffile "/etc/auto.net"
388
389 STATUS="Collecting LVM information:"
390 if [ $os = "redhat" ]; then
391    catifexec "/usr/sbin/vgdisplay" "-vv"
392 elif [ $os = "debian" ]; then
393    catifexec "/sbin/vgdisplay" "-vv"
394 fi
395    
396 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
397 catiffile "/etc/stinit.def"
398
399 if [ -x /sbin/lsusb ] ; then
400   STATUS="Collecting USB devices list (lsusb):"
401   catifexec "/sbin/lsusb"
402 fi
403
404 if [ -x /usr/bin/lshal ] ; then
405   STATUS="Collecting global devices list (lshal):"
406   catifexec "/usr/bin/lshal"
407 fi
408
409
410 STATUS="Gathering information on SELinux setup"
411 catifexec "/usr/bin/selinuxconfig"
412 catifexec "/usr/sbin/sestatus"
413 if [ $os = "redhat" ]; then
414    catifexec "rpm" "-q -V selinux-policy-targeted"
415    catifexec "rpm" "-q -V selinux-policy-strict"
416 fi
417
418 if [ $usevserver = yes ]; then
419    STATUS="Gathering vserver information"
420    catiffile "/proc/virtual"
421 fi
422
423 if [ "$partitions" == "yes" ]; then
424    if [ "$dosfdisk" == "yes" ]; then
425         if [ ! -x "$SFDISK" ]; then
426                 warning "can't find sfdisk, skipping sfdisk report."
427                 partitions="no"
428         fi
429    fi
430    if [ "$dohwinfo" == "yes" ]; then
431         if [ ! -x "$HWINFO" ]; then
432                 warning "can't find hwinfo, skipping partition report."
433                 partitions="no"
434         fi
435    fi
436 fi
437
438 if [ "$hardware" == "yes" ]; then
439         if [ ! -x "$HWINFO" ]; then
440                 warning "can't find hwinfo, skipping hardware report."
441                 hardware="no"
442         fi
443 fi
444
445 ## HARDWARE #############################
446
447 #
448 # here we use hwinfo to dump a table listing all the
449 # information we can find on the hardware of this machine
450
451
452 if [ "$hardware" == "yes" ]; then
453    if [ "dohwinfo" == "yes" ]; then
454       if [ -f $hardwarefile ]; then
455          rm $hardwarefile
456       fi
457       touch $hardwarefile
458       echo -e "\n\n====================== summary ======================\n" >>  $hardwarefile
459       debug "$HWINFO --short --cpu --network --disk --pci  >> $hardwarefile"
460       $HWINFO --short --cpu --network --disk --pci  >> $hardwarefile
461       for flag in cpu network bios pci; do
462          echo -e "\n\n====================== $flag ======================\n" >>  $hardwarefile
463          $HWINFO --$flag >> $hardwarefile
464       done
465    fi
466 fi
467
468
469 ## PARTITIONS #############################
470
471 # here we use sfdisk to dump a listing of all the partitions. 
472 # these files can be used to directly partition a disk of the same size.
473
474 if [ "$partitions" == "yes" ]; then
475    if [ "$dosfdisk" == "yes" ]; then
476       devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
477         if [ "$devices" == "" ]; then 
478            warning "No harddisks found" 
479         fi
480         for dev in $devices; do
481                 debug "$SFDISK will try to backup partition tables for device $dev"
482                 [ -b $dev ] || continue
483                 label=${dev#/dev/}
484                 label=${label//\//-}
485                 outputfile=${partitionsfile//__star__/$label}
486                 debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
487                 $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
488                 if [ $? -ne 0 ]; then
489                    warning "The partition table for $dev could not be saved."
490                 fi
491         done
492    fi
493    if [ "$dohwinfo" == "yes" ]; then
494       debug "Using $HWINFO to get all available disk information"
495       echo -e "\n\n====================== $disk ======================\n" >>  $hardwarefile
496       $HWINFO --disk >> $hardwarefile
497    fi
498 fi