1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
3 # this handler will save various reports of vital system information.
4 # by default, all the reports are saved in /var/backups.
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"
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.
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!!!)
24 # (4) hardware information.
25 # write to a text file the important things which hwinfo can gleen.
27 # (5) the Luks header of every Luks block device, if option luksheaders
29 # in case you (have to) scramble such a Luks header (for some time),
30 # and restore it later by running "dd if=luksheader.sda2.bin of=/dev/sda2"
31 # (MAKE SURE YOU PASS THE CORRECT DEVICE AS of= !!!)
34 if [ -f /etc/debian_version ]
37 debug "Debian detected"
38 osversion="/etc/debian_version"
39 elif [ -f /etc/redhat-release ]
42 debug "Redhat detected"
43 osversion="/etc/redhat-release"
45 warning "Unknown OS detected!"
48 getconf parentdir /var/backups
53 if [ ! -d $parentdir ]; then
59 getconf packagesfile $parentdir/dpkg-selections.txt
60 getconf packagemgr `which dpkg`
61 getconf packagemgroptions ' --get-selections *'
62 getconf selectionsfile $parentdir/debconfsel.txt
63 getconf debconfgetselections `which debconf-get-selections`
64 elif [ $os = "redhat" ]
66 getconf packagesfile $parentdir/rpmpackages.txt
67 getconf packagemgr `which rpm`
68 getconf packagemgroptions ' -qa '
70 getconf SYSREPORT `which sysreport`
71 getconf sysreport_options ' -norpm '
73 getconf packagesfile $parentdir/unknownOS.txt
75 packagemgroptions="${packagemgroptions//__star__/*}"
77 getconf partitions yes
78 getconf partitionsfile $parentdir/partitions.__star__.txt
81 getconf hardwarefile $parentdir/hardware.txt
84 getconf sysreportfile $parentdir/sysreport.txt
86 getconf SFDISK `which sfdisk`
87 getconf HWINFO `which hwinfo`
88 getconf sfdisk_options ""
89 getconf hwinfo_options ""
91 getconf CRYPTSETUP `which cryptsetup`
93 getconf luksheaders no
94 getconf luksheadersfile $parentdir/luksheader.__star__.bin
98 # If vservers are configured, check that the ones listed in $vsnames are running.
100 if [ $vservers_are_available = yes ]; then
101 if [ "$vsnames" = all ]; then
102 vsnames="$found_vservers"
104 if ! vservers_running "$vsnames" ; then
105 fatal "At least one of the vservers listed in vsnames ($vsnames) is not running."
107 info "Using vservers '$vsnames'"
111 ## SANITY CHECKS #########################
113 if [ "$luksheaders" == "yes" ]; then
114 if [ ! -x "$DD" ]; then
115 warning "can't find dd, skipping backup of Luks headers."
118 if [ ! -x "$CRYPTSETUP" ]; then
119 warning "can't find cryptsetup, skipping backup of Luks headers."
124 ## PACKAGES ##############################
127 # here we grab a list of the packages installed and removed.
130 if [ "$packages" == "yes" ]; then
132 if [ $usevserver = yes ]; then
133 info "vserver root directory set to: $VROOTDIR"
134 for vserver in $vsnames; do
135 info "examining vserver: $vserver"
137 vservers_running $vserver
138 if [ $? -ne 0 ]; then
139 warning "The vserver $vserver is not running."
142 # is $packagemgr available inside $vserver ?
143 if [ ! -x "${VROOTDIR}/${vserver}${packagemgr}" ]; then
144 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
146 # don't expand * since it can be used in $packagemgroptions
148 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
149 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
152 # is $debconfgetselections available inside $vserver ?
154 # case #1: it is available on the host, is it available inside $vserver ?
155 if [ -n "$debconfgetselections" ]; then
156 [ -x "${VROOTDIR}/${vserver}${debconfgetselections}" ] && found=yes
157 # case #2: it is not available on the host, is it available inside $vserver ?
159 [ -n "`$VSERVER $vserver exec which debconf-get-selections`" ] && found=yes
161 if [ "$found" != yes ]; then
162 warning "can't find debconf-get-selections in vserver $vserver, skipping package selection states. You may want to install the debconf-utils package."
164 debug "$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile"
165 $VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile || fatal "can not save debconf-get-selections info to $selectionsfile"
171 # We want to perform this on the host as well
172 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
173 warning "can't find ${packagemgr}, skipping installed packages report."
175 # don't expand * since it can be used in $packagemgroptions
177 debug "$packagemgr $packagemgroptions > $packagesfile"
178 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
181 if [ -z "$debconfgetselections" ]; then
182 warning "can't find debconf-get-selections, skipping package selection states. You might want to install the debconf-utils package."
184 debug "$debconfgetselections > $selectionsfile"
185 $debconfgetselections > $selectionsfile || fatal "can not save $debconfgetselections info to $selectionsfile"
189 ## System report ##############################
192 # here we grab a bunch of system stuff for a report
197 HASHES="#################################################################"
198 DASHES="-----------------------------------------------------------------"
200 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
204 echo $HASHES >> $sysreportfile
205 echo "# $STATUS" >> $sysreportfile
206 echo $HASHES >> $sysreportfile
208 echo "file: $1" >> $sysreportfile
209 echo $DASHES >> $sysreportfile
210 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
213 echo "directory: $1" >> $sysreportfile
214 echo $DASHES >> $sysreportfile
215 for file in `find $1 -maxdepth 3 -noleaf -type f`
220 echo $DASHES >> $sysreportfile
225 echo $HASHES >> $sysreportfile
226 echo "# $STATUS" >> $sysreportfile
227 echo $HASHES >> $sysreportfile
228 $* >> $sysreportfile 2>&1 || info "executing of $1 failed"
233 STATUS="Determining $os version:"
236 STATUS="Determinding your current hostname: "
237 catifexec "/bin/hostname"
239 STATUS="Getting the date:"
240 catifexec "/bin/date"
242 STATUS="Checking your systems current uptime and load average:"
243 catifexec "/usr/bin/uptime"
245 STATUS="Checking available memory:"
246 catifexec "/usr/bin/free"
248 STATUS="Checking free disk space:"
249 catifexec "/bin/df" "-al"
251 STATUS="Collecting what services run at what run level:"
252 if [ $os = "redhat" ]; then
253 catifexec "/sbin/chkconfig" "--list"
254 STATUS="Collecting information about /etc/rc.d:"
255 catiffile "/bin/ls /etc/rc.d/rc*.d/"
257 elif [ $os = "debian" ]; then
258 for level in 0 1 2 3 4 5 6 S; do
259 echo "Level: $level" >> $sysreportfile
260 for f in /etc/rc${level}.d/*; do
261 # Remove /etc/Knn or Snn from beginning
262 ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
263 if [ $f != $ff ]; then
264 echo $ff >> $sysreportfile
267 echo "" >> $sysreportfile
271 STATUS="Getting bootloader information:"
272 catifexec "/bin/ls" "-alR /boot"
274 # This covers sparc, alpha, and intel (respectively)
275 # updated for grub -mpg
276 if [ -f /etc/silo.conf ]; then
277 STATUS="Collecting information about the boot process (silo):"
278 catiffile "/etc/silo.conf"
280 if [ -f /etc/milo.conf ]; then
281 STATUS="Collecting information about the boot process (milo):"
282 catiffile "/etc/milo.conf"
284 if [ -f /etc/lilo.conf ]; then
285 STATUS="Collecting information about the boot process (lilo):"
286 catiffile "/etc/lilo.conf"
287 catifexec "/sbin/lilo" "-q"
289 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
290 STATUS="Collecting information about the boot process (grub.conf):"
291 catiffile "/boot/grub/grub.conf"
292 STATUS="Collecting information about the boot process (grub.map):"
293 catiffile "/boot/grub/device.map"
295 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
296 STATUS="Gathering information on cluster setup"
298 if [ -f /etc/cluster.conf ] ; then
299 catiffile "/etc/cluster.conf"
302 if [ -f /etc/cluster.xml ] ; then
303 catiffile "/etc/cluster.xml"
307 STATUS="Gathering sysctl information (sysctl -a):"
308 catiffile "sysctl -a 2>/dev/null"
309 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
310 catiffile "/etc/sysctl.conf"
312 STATUS="Gathering IP information (/sbin/ifconfig):"
313 catifexec "/sbin/ifconfig" "-a"
315 STATUS="Gathering additional IP information (/bin/ip addr list):"
316 catifexec "/bin/ip" "addr list"
318 STATUS="Checking network routes:"
319 catifexec "/sbin/route" "-n"
321 STATUS="Collecting Name Service Switch config information:"
322 catiffile "/etc/nsswitch.conf"
324 STATUS="Collecting information about system authentication (pam):"
325 catiffile "/etc/pam.conf"
326 catiffile "/etc/pam.d"
329 echo "Getting information about the kernel."
331 STATUS="Getting kernel version:"
332 catifexec "/bin/uname" "-a"
333 STATUS="Checking module information:"
334 catifexec "/sbin/lsmod"
335 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
337 STATUS="Checking module information $x:"
338 catifexec "/sbin/modinfo" "$x"
341 STATUS="Gathering information about your filesystems:"
342 catiffile "/proc/filesystems"
344 STATUS="Gathering information about your system stat:"
345 catiffile "/proc/stat"
347 STATUS="Gathering information about your partitions:"
348 catiffile "/proc/partitions"
350 STATUS="Gathering information about your ksyms:"
351 catiffile "/proc/kallsyms"
353 STATUS="Gathering information about slabinfo:"
354 catiffile "/proc/slabinfo"
356 # Added support to cover for the new modules.conf layout in Red Hat 7
357 STATUS="Collecting information regarding kernel modules"
359 catiffile "/lib/modules/$VER/modules.dep"
360 if [ -f /etc/conf.modules ]; then
361 STATUS="Collecting information regarding kernel modules (conf.modules)"
362 catiffile "/etc/conf.modules"
364 if [ -f /etc/modules.conf ]; then
365 STATUS="Collecting information regarding kernel modules (modules.conf)"
366 catiffile "/etc/modules.conf"
368 if [ -f /etc/modprobe.conf ]; then
369 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
370 catiffile "/etc/modprobe.conf"
374 if [ -x /usr/sbin/dkms ] ; then
375 STATUS="Gathering current status of modules, versions and kernels (dkms):"
376 catifexec "/usr/sbin/dkms" "status"
379 if [ -f /etc/sysconfig/isdncard ] ; then
380 STATUS="Gathering information about ISDN:"
381 catiffile "/etc/sysconfig/isdncard"
384 STATUS="Collecting information from the proc directory:"
385 catiffile "/proc/pci"
387 STATUS="Getting kernel command line"
388 catiffile "/proc/cmdline"
390 STATUS="Gathering information about your CPU:"
391 catiffile "/proc/cpuinfo"
393 STATUS="Gathering information about your Ram:"
394 catiffile "/proc/meminfo"
396 STATUS="Gathering information about your ioports:"
397 catiffile "/proc/ioports"
399 STATUS="Gathering information about your interrupts:"
400 catiffile "/proc/interrupts"
402 STATUS="Gathering information about your scsi devices:"
403 catiffile "/proc/scsi"
405 STATUS="Gathering information about your dma:"
406 catiffile "/proc/dma"
408 STATUS="Gathering information about your devices (/proc/devices):"
409 catiffile "/proc/devices"
411 STATUS="Gathering information about your rtc:"
412 catiffile "/proc/rtc"
414 STATUS="Gathering information about your ide drivers:"
415 catiffile "/proc/ide"
417 STATUS="Gathering information about your bus:"
418 catifexec "/usr/bin/lspci"
419 catiffile "/proc/bus"
422 echo "Getting disk and filesystem information."
425 STATUS="Collecting information from /etc/fstab:"
426 catiffile "/etc/fstab"
428 STATUS="Collecting disk partition information:"
429 catifexec "/sbin/fdisk" "-l"
431 STATUS="Checking mounted file systems (mount) "
432 catifexec "/bin/mount"
434 STATUS="Checking mounted file systems (/proc/mounts)"
435 catiffile "/proc/mounts"
437 STATUS="Collecting Software RAID information (/proc/mdstat)"
438 catiffile "/proc/mdstat"
440 STATUS="Collecting Software RAID information (/etc/raidtab)"
441 catiffile "/etc/raidtab"
443 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
444 catiffile "/etc/mdadm.conf"
446 STATUS="Collecting Software RAID information (/sbin/mdadm -Q)"
447 catifexec "/sbin/mdadm" "-Q" "--detail" '/dev/md?*'
449 STATUS="Collecting Automount information (auto.master)"
450 catiffile "/etc/auto.master"
452 STATUS="Collecting Automount information (auto.misc)"
453 catiffile "/etc/auto.misc"
455 STATUS="Collecting Automount information (auto.net)"
456 catiffile "/etc/auto.net"
458 STATUS="Collecting LVM information:"
459 if [ $os = "redhat" ]; then
460 catifexec "/usr/sbin/vgdisplay" "-vv"
461 elif [ $os = "debian" ]; then
462 catifexec "/sbin/vgdisplay" "-vv"
465 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
466 catiffile "/etc/stinit.def"
468 if [ -x /sbin/lsusb ] ; then
469 STATUS="Collecting USB devices list (lsusb):"
470 catifexec "/sbin/lsusb"
473 if [ -x /usr/bin/lshal ] ; then
474 STATUS="Collecting global devices list (lshal):"
475 catifexec "/usr/bin/lshal"
479 STATUS="Gathering information on SELinux setup"
480 catifexec "/usr/bin/selinuxconfig"
481 catifexec "/usr/sbin/sestatus"
482 if [ $os = "redhat" ]; then
483 catifexec "rpm" "-q -V selinux-policy-targeted"
484 catifexec "rpm" "-q -V selinux-policy-strict"
487 if [ $usevserver = yes ]; then
488 STATUS="Gathering vserver information"
489 catiffile "/proc/virtual"
492 if [ "$partitions" == "yes" ]; then
493 if [ "$dosfdisk" == "yes" ]; then
494 if [ ! -x "$SFDISK" ]; then
495 warning "can't find sfdisk, skipping sfdisk report."
499 if [ "$dohwinfo" == "yes" ]; then
500 if [ ! -x "$HWINFO" ]; then
501 warning "can't find hwinfo, skipping partition report."
507 if [ "$hardware" == "yes" ]; then
508 if [ ! -x "$HWINFO" ]; then
509 warning "can't find hwinfo, skipping hardware report."
514 ## HARDWARE #############################
517 # here we use hwinfo to dump a table listing all the
518 # information we can find on the hardware of this machine
521 if [ "$hardware" == "yes" ]; then
522 if [ "dohwinfo" == "yes" ]; then
523 if [ -f $hardwarefile ]; then
527 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
528 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
529 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
530 for flag in cpu network bios pci; do
531 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
532 $HWINFO --$flag >> $hardwarefile
538 ## PARTITIONS #############################
540 # here we use sfdisk to dump a listing of all the partitions.
541 # these files can be used to directly partition a disk of the same size.
543 if [ "$partitions" == "yes" ]; then
544 if [ "$dosfdisk" == "yes" ]; then
545 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
546 if [ "$devices" == "" ]; then
547 warning "No harddisks found"
549 for dev in $devices; do
550 debug "$SFDISK will try to backup partition tables for device $dev"
551 [ -b $dev ] || continue
554 outputfile=${partitionsfile//__star__/$label}
555 debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
556 $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
557 if [ $? -ne 0 ]; then
558 warning "The partition table for $dev could not be saved."
562 if [ "$dohwinfo" == "yes" ]; then
563 debug "Using $HWINFO to get all available disk information"
564 echo -e "\n\n====================== $disk ======================\n" >> $hardwarefile
565 $HWINFO --disk >> $hardwarefile
569 if [ "$luksheaders" == "yes" ]; then
570 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
571 [ -n "$devices" ] || warning "No block device found"
573 for dev in $devices; do
574 [ -b $dev ] || continue
575 debug "$CRYPTSETUP isLuks $dev"
576 $CRYPTSETUP isLuks $dev
577 [ $? -eq 0 ] && targetdevices="$targetdevices $dev"
579 for dev in $targetdevices; do
582 outputfile=${luksheadersfile//__star__/$label}
583 # the following sizes are expressed in terms of 512-byte sectors
584 debug "Let us find out the Luks header size for $dev"
585 debug "$CRYPTSETUP luksDump \"$dev\" | grep '^Payload offset:' | @AWK@ '{print $3}'"
586 headersize=`$CRYPTSETUP luksDump "$dev" | grep '^Payload offset:' | @AWK@ '{print $3}'`
587 if [ $? -ne 0 ]; then
588 warning "Could not compute the size of Luks header, skipping device $dev"
590 elif [ -z "$headersize" -o -n "`echo \"$headersize\" | sed 's/[0-9]*//g'`" ]; then
591 warning "The computed size of Luks header is not an integer, skipping device $dev"
594 debug "Let us backup the Luks header of device $dev"
595 debug "$DD if=\"${dev}\" of=\"${outputfile}\" bs=512 count=\"${headersize}\""
596 output=`$DD if="${dev}" of="${outputfile}" bs=512 count="${headersize}" 2>&1`
598 if [ $exit_code -eq 0 ]; then
600 info "The Luks header of $dev was saved to $outputfile."
603 fatal "The Luks header of $dev could not be saved."