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= !!!)
33 # (6) LVM metadata for every detected volume group, if "lvm = yes"
36 if [ -f /etc/debian_version ]
39 debug "Debian detected"
40 osversion="/etc/debian_version"
41 elif [ -f /etc/redhat-release ]
44 debug "Redhat detected"
45 osversion="/etc/redhat-release"
47 warning "Unknown OS detected!"
50 getconf parentdir /var/backups
55 if [ ! -d $parentdir ]; then
61 getconf packagesfile $parentdir/dpkg-selections.txt
62 getconf packagemgr `which dpkg`
63 getconf packagemgroptions ' --get-selections *'
64 getconf selectionsfile $parentdir/debconfsel.txt
65 getconf debconfgetselections `which debconf-get-selections`
66 elif [ $os = "redhat" ]
68 getconf packagesfile $parentdir/rpmpackages.txt
69 getconf packagemgr `which rpm`
70 getconf packagemgroptions ' -qa '
72 getconf SYSREPORT `which sysreport`
73 getconf sysreport_options ' -norpm '
75 getconf packagesfile $parentdir/unknownOS.txt
77 packagemgroptions="${packagemgroptions//__star__/*}"
79 getconf partitions yes
80 getconf partitionsfile $parentdir/partitions.__star__.txt
83 getconf hardwarefile $parentdir/hardware.txt
86 getconf sysreportfile $parentdir/sysreport.txt
88 getconf SFDISK `which sfdisk`
89 getconf HWINFO `which hwinfo`
90 getconf sfdisk_options ""
91 getconf hwinfo_options ""
93 getconf CRYPTSETUP `which cryptsetup`
95 getconf luksheaders no
96 getconf luksheadersfile $parentdir/luksheader.__star__.bin
98 getconf VGS `which vgs`
99 getconf VGCFGBACKUP `which vgcfgbackup`
104 # If vservers are configured, check that the ones listed in $vsnames are running.
106 if [ $vservers_are_available = yes ]; then
107 if [ "$vsnames" = all ]; then
108 vsnames="$found_vservers"
110 if ! vservers_running "$vsnames" ; then
111 fatal "At least one of the vservers listed in vsnames ($vsnames) is not running."
113 info "Using vservers '$vsnames'"
117 ## SANITY CHECKS #########################
119 if [ "$luksheaders" == "yes" ]; then
120 if [ ! -x "$DD" ]; then
121 warning "can't find dd, skipping backup of Luks headers."
124 if [ ! -x "$CRYPTSETUP" ]; then
125 warning "can't find cryptsetup, skipping backup of Luks headers."
130 if [ "$lvm" == "yes" ]; then
131 if [ ! -x "$VGS" ]; then
132 warning "can't find vgs, skipping backup of LVM metadata"
135 if [ ! -x "$VGCFGBACKUP" ]; then
136 warning "can't find vgcfgbackup, skipping backup of LVM metadata"
141 ## PACKAGES ##############################
144 # here we grab a list of the packages installed and removed.
147 if [ "$packages" == "yes" ]; then
149 if [ $usevserver = yes ]; then
150 info "vserver root directory set to: $VROOTDIR"
151 for vserver in $vsnames; do
152 info "examining vserver: $vserver"
154 vservers_running $vserver
155 if [ $? -ne 0 ]; then
156 warning "The vserver $vserver is not running."
159 # is $packagemgr available inside $vserver ?
160 if [ ! -x "${VROOTDIR}/${vserver}${packagemgr}" ]; then
161 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
163 # don't expand * since it can be used in $packagemgroptions
165 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
166 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
169 # is $debconfgetselections available inside $vserver ?
171 # case #1: it is available on the host, is it available inside $vserver ?
172 if [ -n "$debconfgetselections" ]; then
173 [ -x "${VROOTDIR}/${vserver}${debconfgetselections}" ] && found=yes
174 # case #2: it is not available on the host, is it available inside $vserver ?
176 [ -n "`$VSERVER $vserver exec which debconf-get-selections`" ] && found=yes
178 if [ "$found" != yes ]; then
179 warning "can't find debconf-get-selections in vserver $vserver, skipping package selection states. You may want to install the debconf-utils package."
181 debug "$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile"
182 $VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile || fatal "can not save debconf-get-selections info to $selectionsfile"
188 # We want to perform this on the host as well
189 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
190 warning "can't find ${packagemgr}, skipping installed packages report."
192 # don't expand * since it can be used in $packagemgroptions
194 debug "$packagemgr $packagemgroptions > $packagesfile"
195 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
198 if [ -z "$debconfgetselections" ]; then
199 warning "can't find debconf-get-selections, skipping package selection states. You might want to install the debconf-utils package."
201 debug "$debconfgetselections > $selectionsfile"
202 $debconfgetselections > $selectionsfile || fatal "can not save $debconfgetselections info to $selectionsfile"
206 ## System report ##############################
209 # here we grab a bunch of system stuff for a report
214 HASHES="#################################################################"
215 DASHES="-----------------------------------------------------------------"
217 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
221 echo $HASHES >> $sysreportfile
222 echo "# $STATUS" >> $sysreportfile
223 echo $HASHES >> $sysreportfile
225 echo "file: $1" >> $sysreportfile
226 echo $DASHES >> $sysreportfile
227 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
230 echo "directory: $1" >> $sysreportfile
231 echo $DASHES >> $sysreportfile
232 for file in `find $1 -maxdepth 3 -noleaf -type f`
237 echo $DASHES >> $sysreportfile
242 echo $HASHES >> $sysreportfile
243 echo "# $STATUS" >> $sysreportfile
244 echo $HASHES >> $sysreportfile
245 $* >> $sysreportfile 2>&1 || info "executing of $1 failed"
250 STATUS="Determining $os version:"
253 STATUS="Determinding your current hostname: "
254 catifexec "/bin/hostname"
256 STATUS="Getting the date:"
257 catifexec "/bin/date"
259 STATUS="Checking your systems current uptime and load average:"
260 catifexec "/usr/bin/uptime"
262 STATUS="Checking available memory:"
263 catifexec "/usr/bin/free"
265 STATUS="Checking free disk space:"
266 catifexec "/bin/df" "-al"
268 STATUS="Collecting what services run at what run level:"
269 if [ $os = "redhat" ]; then
270 catifexec "/sbin/chkconfig" "--list"
271 STATUS="Collecting information about /etc/rc.d:"
272 catiffile "/bin/ls /etc/rc.d/rc*.d/"
274 elif [ $os = "debian" ]; then
275 for level in 0 1 2 3 4 5 6 S; do
276 echo "Level: $level" >> $sysreportfile
277 for f in /etc/rc${level}.d/*; do
278 # Remove /etc/Knn or Snn from beginning
279 ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
280 if [ $f != $ff ]; then
281 echo $ff >> $sysreportfile
284 echo "" >> $sysreportfile
288 STATUS="Getting bootloader information:"
289 catifexec "/bin/ls" "-alR /boot"
291 # This covers sparc, alpha, and intel (respectively)
292 # updated for grub -mpg
293 if [ -f /etc/silo.conf ]; then
294 STATUS="Collecting information about the boot process (silo):"
295 catiffile "/etc/silo.conf"
297 if [ -f /etc/milo.conf ]; then
298 STATUS="Collecting information about the boot process (milo):"
299 catiffile "/etc/milo.conf"
301 if [ -f /etc/lilo.conf ]; then
302 STATUS="Collecting information about the boot process (lilo):"
303 catiffile "/etc/lilo.conf"
304 catifexec "/sbin/lilo" "-q"
306 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
307 STATUS="Collecting information about the boot process (grub.conf):"
308 catiffile "/boot/grub/grub.conf"
309 STATUS="Collecting information about the boot process (grub.map):"
310 catiffile "/boot/grub/device.map"
312 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
313 STATUS="Gathering information on cluster setup"
315 if [ -f /etc/cluster.conf ] ; then
316 catiffile "/etc/cluster.conf"
319 if [ -f /etc/cluster.xml ] ; then
320 catiffile "/etc/cluster.xml"
324 STATUS="Gathering sysctl information (sysctl -a):"
325 catiffile "sysctl -a 2>/dev/null"
326 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
327 catiffile "/etc/sysctl.conf"
329 STATUS="Gathering IP information (/sbin/ifconfig):"
330 catifexec "/sbin/ifconfig" "-a"
332 STATUS="Gathering additional IP information (/bin/ip addr list):"
333 catifexec "/bin/ip" "addr list"
335 STATUS="Checking network routes:"
336 catifexec "/sbin/route" "-n"
338 STATUS="Collecting Name Service Switch config information:"
339 catiffile "/etc/nsswitch.conf"
341 STATUS="Collecting information about system authentication (pam):"
342 catiffile "/etc/pam.conf"
343 catiffile "/etc/pam.d"
346 echo "Getting information about the kernel."
348 STATUS="Getting kernel version:"
349 catifexec "/bin/uname" "-a"
350 STATUS="Checking module information:"
351 catifexec "/sbin/lsmod"
352 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
354 STATUS="Checking module information $x:"
355 catifexec "/sbin/modinfo" "$x"
358 STATUS="Gathering information about your filesystems:"
359 catiffile "/proc/filesystems"
361 STATUS="Gathering information about your system stat:"
362 catiffile "/proc/stat"
364 STATUS="Gathering information about your partitions:"
365 catiffile "/proc/partitions"
367 STATUS="Gathering information about your ksyms:"
368 catiffile "/proc/kallsyms"
370 STATUS="Gathering information about slabinfo:"
371 catiffile "/proc/slabinfo"
373 # Added support to cover for the new modules.conf layout in Red Hat 7
374 STATUS="Collecting information regarding kernel modules"
376 catiffile "/lib/modules/$VER/modules.dep"
377 if [ -f /etc/conf.modules ]; then
378 STATUS="Collecting information regarding kernel modules (conf.modules)"
379 catiffile "/etc/conf.modules"
381 if [ -f /etc/modules.conf ]; then
382 STATUS="Collecting information regarding kernel modules (modules.conf)"
383 catiffile "/etc/modules.conf"
385 if [ -f /etc/modprobe.conf ]; then
386 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
387 catiffile "/etc/modprobe.conf"
391 if [ -x /usr/sbin/dkms ] ; then
392 STATUS="Gathering current status of modules, versions and kernels (dkms):"
393 catifexec "/usr/sbin/dkms" "status"
396 if [ -f /etc/sysconfig/isdncard ] ; then
397 STATUS="Gathering information about ISDN:"
398 catiffile "/etc/sysconfig/isdncard"
401 STATUS="Collecting information from the proc directory:"
402 catiffile "/proc/pci"
404 STATUS="Getting kernel command line"
405 catiffile "/proc/cmdline"
407 STATUS="Gathering information about your CPU:"
408 catiffile "/proc/cpuinfo"
410 STATUS="Gathering information about your Ram:"
411 catiffile "/proc/meminfo"
413 STATUS="Gathering information about your ioports:"
414 catiffile "/proc/ioports"
416 STATUS="Gathering information about your interrupts:"
417 catiffile "/proc/interrupts"
419 STATUS="Gathering information about your scsi devices:"
420 catiffile "/proc/scsi"
422 STATUS="Gathering information about your dma:"
423 catiffile "/proc/dma"
425 STATUS="Gathering information about your devices (/proc/devices):"
426 catiffile "/proc/devices"
428 STATUS="Gathering information about your rtc:"
429 catiffile "/proc/rtc"
431 STATUS="Gathering information about your ide drivers:"
432 catiffile "/proc/ide"
434 STATUS="Gathering information about your bus:"
435 catifexec "/usr/bin/lspci"
436 catiffile "/proc/bus"
439 echo "Getting disk and filesystem information."
442 STATUS="Collecting information from /etc/fstab:"
443 catiffile "/etc/fstab"
445 STATUS="Collecting disk partition information:"
446 catifexec "/sbin/fdisk" "-l"
448 STATUS="Checking mounted file systems (mount) "
449 catifexec "/bin/mount"
451 STATUS="Checking mounted file systems (/proc/mounts)"
452 catiffile "/proc/mounts"
454 STATUS="Collecting Software RAID information (/proc/mdstat)"
455 catiffile "/proc/mdstat"
457 STATUS="Collecting Software RAID information (/etc/raidtab)"
458 catiffile "/etc/raidtab"
460 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
461 catiffile "/etc/mdadm.conf"
463 STATUS="Collecting Software RAID information (/sbin/mdadm -Q)"
464 catifexec "/sbin/mdadm" "-Q" "--detail" '/dev/md?*'
466 STATUS="Collecting Automount information (auto.master)"
467 catiffile "/etc/auto.master"
469 STATUS="Collecting Automount information (auto.misc)"
470 catiffile "/etc/auto.misc"
472 STATUS="Collecting Automount information (auto.net)"
473 catiffile "/etc/auto.net"
475 STATUS="Collecting LVM information:"
476 if [ $os = "redhat" ]; then
477 catifexec "/usr/sbin/vgdisplay" "-vv"
478 elif [ $os = "debian" ]; then
479 catifexec "/sbin/vgdisplay" "-vv"
482 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
483 catiffile "/etc/stinit.def"
485 if [ -x /sbin/lsusb ] ; then
486 STATUS="Collecting USB devices list (lsusb):"
487 catifexec "/sbin/lsusb"
490 if [ -x /usr/bin/lshal ] ; then
491 STATUS="Collecting global devices list (lshal):"
492 catifexec "/usr/bin/lshal"
496 STATUS="Gathering information on SELinux setup"
497 catifexec "/usr/bin/selinuxconfig"
498 catifexec "/usr/sbin/sestatus"
499 if [ $os = "redhat" ]; then
500 catifexec "rpm" "-q -V selinux-policy-targeted"
501 catifexec "rpm" "-q -V selinux-policy-strict"
504 if [ $usevserver = yes ]; then
505 STATUS="Gathering vserver information"
506 catiffile "/proc/virtual"
509 if [ "$partitions" == "yes" ]; then
510 if [ "$dosfdisk" == "yes" ]; then
511 if [ ! -x "$SFDISK" ]; then
512 warning "can't find sfdisk, skipping sfdisk report."
516 if [ "$dohwinfo" == "yes" ]; then
517 if [ ! -x "$HWINFO" ]; then
518 warning "can't find hwinfo, skipping partition report."
524 if [ "$hardware" == "yes" ]; then
525 if [ ! -x "$HWINFO" ]; then
526 warning "can't find hwinfo, skipping hardware report."
531 ## HARDWARE #############################
534 # here we use hwinfo to dump a table listing all the
535 # information we can find on the hardware of this machine
538 if [ "$hardware" == "yes" ]; then
539 if [ "dohwinfo" == "yes" ]; then
540 if [ -f $hardwarefile ]; then
544 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
545 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
546 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
547 for flag in cpu network bios pci; do
548 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
549 $HWINFO --$flag >> $hardwarefile
554 ## PARTITIONS #############################
556 # here we use sfdisk to dump a listing of all the partitions.
557 # these files can be used to directly partition a disk of the same size.
559 if [ "$partitions" == "yes" ]; then
560 if [ "$dosfdisk" == "yes" ]; then
561 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
562 if [ "$devices" == "" ]; then
563 warning "No harddisks found"
565 for dev in $devices; do
566 debug "$SFDISK will try to backup partition tables for device $dev"
567 [ -b $dev ] || continue
570 outputfile=${partitionsfile//__star__/$label}
571 debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
572 $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
573 if [ $? -ne 0 ]; then
574 warning "The partition table for $dev could not be saved."
578 if [ "$dohwinfo" == "yes" ]; then
579 debug "Using $HWINFO to get all available disk information"
580 echo -e "\n\n====================== $disk ======================\n" >> $hardwarefile
581 $HWINFO --disk >> $hardwarefile
585 if [ "$luksheaders" == "yes" ]; then
586 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
587 [ -n "$devices" ] || warning "No block device found"
589 for dev in $devices; do
590 [ -b $dev ] || continue
591 debug "$CRYPTSETUP isLuks $dev"
592 $CRYPTSETUP isLuks $dev
593 [ $? -eq 0 ] && targetdevices="$targetdevices $dev"
595 for dev in $targetdevices; do
598 outputfile=${luksheadersfile//__star__/$label}
599 # the following sizes are expressed in terms of 512-byte sectors
600 debug "Let us find out the Luks header size for $dev"
601 debug "$CRYPTSETUP luksDump \"$dev\" | grep '^Payload offset:' | @AWK@ '{print $3}'"
602 headersize=`$CRYPTSETUP luksDump "$dev" | grep '^Payload offset:' | @AWK@ '{print $3}'`
603 if [ $? -ne 0 ]; then
604 warning "Could not compute the size of Luks header, skipping device $dev"
606 elif [ -z "$headersize" -o -n "`echo \"$headersize\" | sed 's/[0-9]*//g'`" ]; then
607 warning "The computed size of Luks header is not an integer, skipping device $dev"
610 debug "Let us backup the Luks header of device $dev"
611 debug "$DD if=\"${dev}\" of=\"${outputfile}\" bs=512 count=\"${headersize}\""
612 output=`$DD if="${dev}" of="${outputfile}" bs=512 count="${headersize}" 2>&1`
614 if [ $exit_code -eq 0 ]; then
616 info "The Luks header of $dev was saved to $outputfile."
619 fatal "The Luks header of $dev could not be saved."
624 ## LVM ####################################
626 # returns 0 on success, 1 on error, 2 if not tried
627 # outputs error message if error, reason if not tried
628 function doLvmBackup () {
630 if [ ! -d "$lvmdir" ]; then
631 if ! mkdir "$lvmdir"; then
632 echo "could not create $lvmdir"
635 info "successfully created $lvmdir"
638 if [ ! -w "$lvmdir" ]; then
639 echo "can not write to directory $lvmdir"
642 debug "Let's try to gather the list of LVM volume groups"
643 debug "$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '"
644 vgs=`$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '`
645 debug "Let's try to backup LVM metadata for detected volume groups: $vgs"
646 debug "$VGCFGBACKUP --file \"${lvmdir}\"/\'%s\' $vgs"
647 output=`$VGCFGBACKUP --file "${lvmdir}"/'%s' $vgs`
652 info "LVM metadata was saved to $lvmdir for volume groups: $vgs"
656 echo "LVM metadata could not be saved for at least one of these volume groups: $vgs"
662 if [ "$lvm" == "yes" ]; then
663 output=`doLvmBackup "${parentdir}/lvm"`
666 0) # success. info message has already been displayed
672 2) # could not even try
673 fatal "LVM metadata backup was not tried: $output"
675 *) # should never happen
676 fatal "Unhandled error ($exit_code) while trying to backup LVM metadata, please report a bug"