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