1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2 # vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
4 # this handler will save various reports of vital system information.
5 # by default, all the reports are saved in /var/backups.
7 # (1) a capture of the debconf package selection states. This file
8 # can be used to restore the answers to debconf questions for
9 # packages that you will be installing through (2) below. To
10 # do this, run: "debconf-set-selections < debconfsel.txt"
12 # (2) a list of all the packages installed and removed.
13 # this file can be used to restore the state of installed packages
14 # by running "dpkg --set-selections < dpkg-selections.txt and
15 # then run "apt-get -u dselect-upgrade". If you have the
16 # debconf-set-selections file from (1), you should restore those first.
18 # (3) the partition table of all disks.
19 # this partition table can be used to format another disk of
20 # the same size. this can be handy if using software raid and
21 # you have a disk go bad. just replace the disk and partition it
22 # by running "sfdisk /dev/sdb < partitions.sdb.txt"
23 # (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
25 # (4) hardware information.
26 # write to a text file the important things which hwinfo can gleen.
28 # (5) the Luks header of every Luks block device, if option luksheaders
30 # in case you (have to) scramble such a Luks header (for some time),
31 # and restore it later by running "dd if=luksheader.sda2.bin of=/dev/sda2"
32 # (MAKE SURE YOU PASS THE CORRECT DEVICE AS of= !!!)
34 # (6) LVM metadata for every detected volume group, if "lvm = yes"
37 if [ -f /etc/debian_version ]
40 debug "Debian detected"
41 osversion="/etc/debian_version"
42 elif [ -f /etc/redhat-release ]
45 debug "Redhat detected"
46 osversion="/etc/redhat-release"
48 warning "Unknown OS detected!"
51 getconf parentdir /var/backups
56 if [ ! -d $parentdir ]; then
62 getconf packagesfile $parentdir/dpkg-selections.txt
63 getconf packagemgr `which dpkg`
64 getconf packagemgroptions ' --get-selections *'
65 getconf selectionsfile $parentdir/debconfsel.txt
66 getconf debconfgetselections `which debconf-get-selections`
67 elif [ $os = "redhat" ]
69 getconf packagesfile $parentdir/rpmpackages.txt
70 getconf packagemgr `which rpm`
71 getconf packagemgroptions ' -qa '
73 getconf SYSREPORT `which sysreport`
74 getconf sysreport_options ' -norpm '
76 getconf packagesfile $parentdir/unknownOS.txt
78 packagemgroptions="${packagemgroptions//__star__/*}"
80 getconf partitions yes
81 getconf partitionsfile $parentdir/partitions.__star__.txt
84 getconf hardwarefile $parentdir/hardware.txt
87 getconf sysreportfile $parentdir/sysreport.txt
89 getconf SFDISK `which sfdisk`
90 getconf HWINFO `which hwinfo`
91 getconf sfdisk_options ""
92 getconf hwinfo_options ""
94 getconf CRYPTSETUP `which cryptsetup`
96 getconf luksheaders no
97 getconf luksheadersfile $parentdir/luksheader.__star__.bin
99 getconf VGS `which vgs`
100 getconf VGCFGBACKUP `which vgcfgbackup`
105 # If vservers are configured, check that the ones listed in $vsnames are running.
107 if [ $vservers_are_available = yes ]; then
108 if [ "$vsnames" = all ]; then
109 vsnames="$found_vservers"
111 if ! vservers_running "$vsnames" ; then
112 fatal "At least one of the vservers listed in vsnames ($vsnames) is not running."
114 info "Using vservers '$vsnames'"
118 ## SANITY CHECKS #########################
120 if [ "$luksheaders" == "yes" ]; then
121 if [ ! -x "$DD" ]; then
122 warning "can't find dd, skipping backup of Luks headers."
125 if [ ! -x "$CRYPTSETUP" ]; then
126 warning "can't find cryptsetup, skipping backup of Luks headers."
131 if [ "$lvm" == "yes" ]; then
132 if [ ! -x "$VGS" ]; then
133 warning "can't find vgs, skipping backup of LVM metadata"
136 if [ ! -x "$VGCFGBACKUP" ]; then
137 warning "can't find vgcfgbackup, skipping backup of LVM metadata"
142 ## PACKAGES ##############################
145 # here we grab a list of the packages installed and removed.
148 if [ "$packages" == "yes" ]; then
150 if [ $usevserver = yes ]; then
151 info "vserver root directory set to: $VROOTDIR"
152 for vserver in $vsnames; do
153 info "examining vserver: $vserver"
155 vservers_running $vserver
156 if [ $? -ne 0 ]; then
157 warning "The vserver $vserver is not running."
160 # is $packagemgr available inside $vserver ?
161 if [ ! -x "${VROOTDIR}/${vserver}${packagemgr}" ]; then
162 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
164 # don't expand * since it can be used in $packagemgroptions
166 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
167 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
170 # is $debconfgetselections available inside $vserver ?
172 # case #1: it is available on the host, is it available inside $vserver ?
173 if [ -n "$debconfgetselections" ]; then
174 [ -x "${VROOTDIR}/${vserver}${debconfgetselections}" ] && found=yes
175 # case #2: it is not available on the host, is it available inside $vserver ?
177 [ -n "`$VSERVER $vserver exec which debconf-get-selections`" ] && found=yes
179 if [ "$found" != yes ]; then
180 warning "can't find debconf-get-selections in vserver $vserver, skipping package selection states. You may want to install the debconf-utils package."
182 debug "$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile"
183 $VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile || fatal "can not save debconf-get-selections info to $selectionsfile"
189 # We want to perform this on the host as well
190 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
191 warning "can't find ${packagemgr}, skipping installed packages report."
193 # don't expand * since it can be used in $packagemgroptions
195 debug "$packagemgr $packagemgroptions > $packagesfile"
196 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
199 if [ -z "$debconfgetselections" ]; then
200 warning "can't find debconf-get-selections, skipping package selection states. You might want to install the debconf-utils package."
202 debug "$debconfgetselections > $selectionsfile"
203 $debconfgetselections > $selectionsfile || fatal "can not save $debconfgetselections info to $selectionsfile"
207 ## System report ##############################
210 # here we grab a bunch of system stuff for a report
215 HASHES="#################################################################"
216 DASHES="-----------------------------------------------------------------"
218 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
222 echo $HASHES >> $sysreportfile
223 echo "# $STATUS" >> $sysreportfile
224 echo $HASHES >> $sysreportfile
226 echo "file: $1" >> $sysreportfile
227 echo $DASHES >> $sysreportfile
228 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
231 echo "directory: $1" >> $sysreportfile
232 echo $DASHES >> $sysreportfile
233 for file in `find $1 -maxdepth 3 -noleaf -type f`
238 echo $DASHES >> $sysreportfile
243 echo $HASHES >> $sysreportfile
244 echo "# $STATUS" >> $sysreportfile
245 echo $HASHES >> $sysreportfile
246 $* >> $sysreportfile 2>&1 || info "executing of $1 failed"
251 STATUS="Determining $os version:"
254 STATUS="Determinding your current hostname: "
255 catifexec "/bin/hostname"
257 STATUS="Getting the date:"
258 catifexec "/bin/date"
260 STATUS="Checking your systems current uptime and load average:"
261 catifexec "/usr/bin/uptime"
263 STATUS="Checking available memory:"
264 catifexec "/usr/bin/free"
266 STATUS="Checking free disk space:"
267 catifexec "/bin/df" "-al"
269 STATUS="Collecting what services run at what run level:"
270 if [ $os = "redhat" ]; then
271 catifexec "/sbin/chkconfig" "--list"
272 STATUS="Collecting information about /etc/rc.d:"
273 catiffile "/bin/ls /etc/rc.d/rc*.d/"
275 elif [ $os = "debian" ]; then
276 for level in 0 1 2 3 4 5 6 S; do
277 echo "Level: $level" >> $sysreportfile
278 for f in /etc/rc${level}.d/*; do
279 # Remove /etc/Knn or Snn from beginning
280 ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
281 if [ $f != $ff ]; then
282 echo $ff >> $sysreportfile
285 echo "" >> $sysreportfile
289 STATUS="Getting bootloader information:"
290 catifexec "/bin/ls" "-alR /boot"
292 # This covers sparc, alpha, and intel (respectively)
293 # updated for grub -mpg
294 if [ -f /etc/silo.conf ]; then
295 STATUS="Collecting information about the boot process (silo):"
296 catiffile "/etc/silo.conf"
298 if [ -f /etc/milo.conf ]; then
299 STATUS="Collecting information about the boot process (milo):"
300 catiffile "/etc/milo.conf"
302 if [ -f /etc/lilo.conf ]; then
303 STATUS="Collecting information about the boot process (lilo):"
304 catiffile "/etc/lilo.conf"
305 catifexec "/sbin/lilo" "-q"
307 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
308 STATUS="Collecting information about the boot process (grub.conf):"
309 catiffile "/boot/grub/grub.conf"
310 STATUS="Collecting information about the boot process (grub.map):"
311 catiffile "/boot/grub/device.map"
313 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
314 STATUS="Gathering information on cluster setup"
316 if [ -f /etc/cluster.conf ] ; then
317 catiffile "/etc/cluster.conf"
320 if [ -f /etc/cluster.xml ] ; then
321 catiffile "/etc/cluster.xml"
325 STATUS="Gathering sysctl information (sysctl -a):"
326 catiffile "sysctl -a 2>/dev/null"
327 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
328 catiffile "/etc/sysctl.conf"
330 STATUS="Gathering IP information (/sbin/ifconfig):"
331 catifexec "/sbin/ifconfig" "-a"
333 STATUS="Gathering additional IP information (/bin/ip addr list):"
334 catifexec "/bin/ip" "addr list"
336 STATUS="Checking network routes:"
337 catifexec "/sbin/route" "-n"
339 STATUS="Collecting Name Service Switch config information:"
340 catiffile "/etc/nsswitch.conf"
342 STATUS="Collecting information about system authentication (pam):"
343 catiffile "/etc/pam.conf"
344 catiffile "/etc/pam.d"
347 echo "Getting information about the kernel."
349 STATUS="Getting kernel version:"
350 catifexec "/bin/uname" "-a"
351 STATUS="Checking module information:"
352 catifexec "/sbin/lsmod"
353 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
355 STATUS="Checking module information $x:"
356 catifexec "/sbin/modinfo" "$x"
359 STATUS="Gathering information about your filesystems:"
360 catiffile "/proc/filesystems"
362 STATUS="Gathering information about your system stat:"
363 catiffile "/proc/stat"
365 STATUS="Gathering information about your partitions:"
366 catiffile "/proc/partitions"
368 STATUS="Gathering information about your ksyms:"
369 catiffile "/proc/kallsyms"
371 STATUS="Gathering information about slabinfo:"
372 catiffile "/proc/slabinfo"
374 # Added support to cover for the new modules.conf layout in Red Hat 7
375 STATUS="Collecting information regarding kernel modules"
377 catiffile "/lib/modules/$VER/modules.dep"
378 if [ -f /etc/conf.modules ]; then
379 STATUS="Collecting information regarding kernel modules (conf.modules)"
380 catiffile "/etc/conf.modules"
382 if [ -f /etc/modules.conf ]; then
383 STATUS="Collecting information regarding kernel modules (modules.conf)"
384 catiffile "/etc/modules.conf"
386 if [ -f /etc/modprobe.conf ]; then
387 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
388 catiffile "/etc/modprobe.conf"
392 if [ -x /usr/sbin/dkms ] ; then
393 STATUS="Gathering current status of modules, versions and kernels (dkms):"
394 catifexec "/usr/sbin/dkms" "status"
397 if [ -f /etc/sysconfig/isdncard ] ; then
398 STATUS="Gathering information about ISDN:"
399 catiffile "/etc/sysconfig/isdncard"
402 STATUS="Collecting information from the proc directory:"
403 catiffile "/proc/pci"
405 STATUS="Getting kernel command line"
406 catiffile "/proc/cmdline"
408 STATUS="Gathering information about your CPU:"
409 catiffile "/proc/cpuinfo"
411 STATUS="Gathering information about your Ram:"
412 catiffile "/proc/meminfo"
414 STATUS="Gathering information about your ioports:"
415 catiffile "/proc/ioports"
417 STATUS="Gathering information about your interrupts:"
418 catiffile "/proc/interrupts"
420 STATUS="Gathering information about your scsi devices:"
421 catiffile "/proc/scsi"
423 STATUS="Gathering information about your dma:"
424 catiffile "/proc/dma"
426 STATUS="Gathering information about your devices (/proc/devices):"
427 catiffile "/proc/devices"
429 STATUS="Gathering information about your rtc:"
430 catiffile "/proc/rtc"
432 STATUS="Gathering information about your ide drivers:"
433 catiffile "/proc/ide"
435 STATUS="Gathering information about your bus:"
436 catifexec "/usr/bin/lspci"
437 catiffile "/proc/bus"
440 echo "Getting disk and filesystem information."
443 STATUS="Collecting information from /etc/fstab:"
444 catiffile "/etc/fstab"
446 STATUS="Collecting disk partition information:"
447 catifexec "/sbin/fdisk" "-l"
449 STATUS="Checking mounted file systems (mount) "
450 catifexec "/bin/mount"
452 STATUS="Checking mounted file systems (/proc/mounts)"
453 catiffile "/proc/mounts"
455 STATUS="Collecting Software RAID information (/proc/mdstat)"
456 catiffile "/proc/mdstat"
458 STATUS="Collecting Software RAID information (/etc/raidtab)"
459 catiffile "/etc/raidtab"
461 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
462 catiffile "/etc/mdadm.conf"
464 STATUS="Collecting Software RAID information (/sbin/mdadm -Q)"
465 catifexec "/sbin/mdadm" "-Q" "--detail" '/dev/md?*'
467 STATUS="Collecting Automount information (auto.master)"
468 catiffile "/etc/auto.master"
470 STATUS="Collecting Automount information (auto.misc)"
471 catiffile "/etc/auto.misc"
473 STATUS="Collecting Automount information (auto.net)"
474 catiffile "/etc/auto.net"
476 STATUS="Collecting LVM information:"
477 if [ $os = "redhat" ]; then
478 catifexec "/usr/sbin/vgdisplay" "-vv"
479 elif [ $os = "debian" ]; then
480 catifexec "/sbin/vgdisplay" "-vv"
483 STATUS="Collecting device-mapper (dm) information:"
484 catifexec '/sbin/dmsetup' 'info'
486 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
487 catiffile "/etc/stinit.def"
489 if [ -x /sbin/lsusb ] ; then
490 STATUS="Collecting USB devices list (lsusb):"
491 catifexec "/sbin/lsusb"
494 if [ -x /usr/bin/lshal ] ; then
495 STATUS="Collecting global devices list (lshal):"
496 catifexec "/usr/bin/lshal"
500 STATUS="Gathering information on SELinux setup"
501 catifexec "/usr/bin/selinuxconfig"
502 catifexec "/usr/sbin/sestatus"
503 if [ $os = "redhat" ]; then
504 catifexec "rpm" "-q -V selinux-policy-targeted"
505 catifexec "rpm" "-q -V selinux-policy-strict"
508 if [ $usevserver = yes ]; then
509 STATUS="Gathering vserver information"
510 catiffile "/proc/virtual"
513 if [ "$partitions" == "yes" ]; then
514 if [ "$dosfdisk" == "yes" ]; then
515 if [ ! -x "$SFDISK" ]; then
516 warning "can't find sfdisk, skipping sfdisk report."
520 if [ "$dohwinfo" == "yes" ]; then
521 if [ ! -x "$HWINFO" ]; then
522 warning "can't find hwinfo, skipping partition report."
528 if [ "$hardware" == "yes" ]; then
529 if [ ! -x "$HWINFO" ]; then
530 warning "can't find hwinfo, skipping hardware report."
535 ## HARDWARE #############################
538 # here we use hwinfo to dump a table listing all the
539 # information we can find on the hardware of this machine
542 if [ "$hardware" == "yes" ]; then
543 if [ "dohwinfo" == "yes" ]; then
544 if [ -f $hardwarefile ]; then
548 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
549 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
550 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
551 for flag in cpu network bios pci; do
552 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
553 $HWINFO --$flag >> $hardwarefile
558 ## PARTITIONS #############################
560 # here we use sfdisk to dump a listing of all the partitions.
561 # these files can be used to directly partition a disk of the same size.
563 if [ "$partitions" == "yes" ]; then
564 if [ "$dosfdisk" == "yes" ]; then
565 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
566 if [ "$devices" == "" ]; then
567 warning "No harddisks found"
569 for dev in $devices; do
570 debug "$SFDISK will try to backup partition tables for device $dev"
571 [ -b $dev ] || continue
574 outputfile=${partitionsfile//__star__/$label}
575 debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
576 $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
577 if [ $? -ne 0 ]; then
578 warning "The partition table for $dev could not be saved."
582 if [ "$dohwinfo" == "yes" ]; then
583 debug "Using $HWINFO to get all available disk information"
584 echo -e "\n\n====================== $disk ======================\n" >> $hardwarefile
585 $HWINFO --disk >> $hardwarefile
589 if [ "$luksheaders" == "yes" ]; then
590 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
591 [ -n "$devices" ] || warning "No block device found"
593 for dev in $devices; do
594 [ -b $dev ] || continue
595 debug "$CRYPTSETUP isLuks $dev"
596 $CRYPTSETUP isLuks $dev
597 [ $? -eq 0 ] && targetdevices="$targetdevices $dev"
599 for dev in $targetdevices; do
602 outputfile=${luksheadersfile//__star__/$label}
603 # the following sizes are expressed in terms of 512-byte sectors
604 debug "Let us find out the Luks header size for $dev"
605 debug "$CRYPTSETUP luksDump \"$dev\" | grep '^Payload offset:' | @AWK@ '{print $3}'"
606 headersize=`$CRYPTSETUP luksDump "$dev" | grep '^Payload offset:' | @AWK@ '{print $3}'`
607 if [ $? -ne 0 ]; then
608 warning "Could not compute the size of Luks header, skipping device $dev"
610 elif [ -z "$headersize" -o -n "`echo \"$headersize\" | sed 's/[0-9]*//g'`" ]; then
611 warning "The computed size of Luks header is not an integer, skipping device $dev"
614 debug "Let us backup the Luks header of device $dev"
615 debug "$DD if=\"${dev}\" of=\"${outputfile}\" bs=512 count=\"${headersize}\""
616 output=`$DD if="${dev}" of="${outputfile}" bs=512 count="${headersize}" 2>&1`
618 if [ $exit_code -eq 0 ]; then
620 info "The Luks header of $dev was saved to $outputfile."
623 fatal "The Luks header of $dev could not be saved."
628 ## LVM ####################################
630 # returns 0 on success, 1 on error, 2 if not tried
631 # outputs error message if error, reason if not tried
632 function doLvmBackup () {
634 if [ ! -d "$lvmdir" ]; then
635 if ! mkdir "$lvmdir"; then
636 echo "could not create $lvmdir"
639 info "successfully created $lvmdir"
642 if [ ! -w "$lvmdir" ]; then
643 echo "can not write to directory $lvmdir"
646 debug "Let's try to gather the list of LVM volume groups"
647 debug "$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '"
648 vgs=`$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '`
649 debug "Let's try to backup LVM metadata for detected volume groups: $vgs"
650 debug "$VGCFGBACKUP --file \"${lvmdir}\"/\'%s\' $vgs"
651 output=`$VGCFGBACKUP --file "${lvmdir}"/'%s' $vgs`
656 info "LVM metadata was saved to $lvmdir for volume groups: $vgs"
660 echo "LVM metadata could not be saved for at least one of these volume groups: $vgs"
666 if [ "$lvm" == "yes" ]; then
667 output=`doLvmBackup "${parentdir}/lvm"`
670 0) # success. info message has already been displayed
676 2) # could not even try
677 fatal "LVM metadata backup was not tried: $output"
679 *) # should never happen
680 fatal "Unhandled error ($exit_code) while trying to backup LVM metadata, please report a bug"