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 enabled and 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.
28 if [ -f /etc/debian_version ]
31 debug "Debian detected"
32 osversion="/etc/debian_version"
33 elif [ -f /etc/redhat-release ]
36 debug "Redhat detected"
37 osversion="/etc/redhat-release"
39 warning "Unknown OS detected!"
42 getconf parentdir /var/backups
47 if [ ! -d $parentdir ]; 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" ]
60 getconf packagesfile $parentdir/rpmpackages.txt
61 getconf packagemgr `which rpm`
62 getconf packagemgroptions ' -qa '
64 getconf SYSREPORT `which sysreport`
65 getconf sysreport_options ' -norpm '
67 getconf packagesfile $parentdir/unknownOS.txt
69 packagemgroptions="${packagemgroptions//__star__/*}"
71 getconf partitions yes
72 getconf partitionsfile $parentdir/partitions.__star__.txt
75 getconf hardwarefile $parentdir/hardware.txt
78 getconf sysreportfile $parentdir/sysreport.txt
80 getconf SFDISK `which sfdisk`
81 getconf HWINFO `which hwinfo`
82 getconf sfdisk_options ""
83 getconf hwinfo_options ""
87 # If vservers are configured, check that the ones listed in $vsnames are running.
89 if [ $vservers_are_available = yes ]; then
90 if [ "$vsnames" = all ]; then
91 vsnames="$found_vservers"
93 if ! vservers_running "$vsnames" ; then
94 fatal "At least one of the vservers listed in vsnames ($vsnames) is not running."
96 info "Using vservers '$vsnames'"
99 # Get the config value again, but now without a default value
101 [ -z "$vsnames" ] || warning 'vservers support disabled in backupninja.conf, vsnames configuration line will be ignored'
105 ## PACKAGES ##############################
108 # here we grab a list of the packages installed and removed.
111 if [ "$packages" == "yes" ]; then
113 if [ $usevserver = yes ]; then
114 info "vserver root directory set to: $VROOTDIR"
115 for vserver in $vsnames; do
116 info "examining vserver: $vserver"
118 vservers_running $vserver
119 if [ $? -ne 0 ]; then
120 warning "The vserver $vserver is not running."
123 # is $packagemgr available inside $vserver ?
124 if [ ! -x "${VROOTDIR}/${vserver}${packagemgr}" ]; then
125 warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
127 # don't expand * since it can be used in $packagemgroptions
129 debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
130 $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
133 # is $debconfgetselections available inside $vserver ?
135 # case #1: it is available on the host, is it available inside $vserver ?
136 if [ -n "$debconfgetselections" ]; then
137 [ -x "${VROOTDIR}/${vserver}${debconfgetselections}" ] && found=yes
138 # case #2: it is not available on the host, is it available inside $vserver ?
140 [ -n "`$VSERVER $vserver exec which debconf-get-selections`" ] && found=yes
142 if [ "$found" != yes ]; then
143 warning "can't find debconf-get-selections in vserver $vserver, skipping package selection states. You may want to install the debconf-utils package."
145 debug "$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile"
146 $VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile || fatal "can not save debconf-get-selections info to $selectionsfile"
152 # We want to perform this on the host as well
153 if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
154 warning "can't find ${packagemgr}, skipping installed packages report."
156 # don't expand * since it can be used in $packagemgroptions
158 debug "$packagemgr $packagemgroptions > $packagesfile"
159 $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
162 if [ -z "$debconfgetselections" ]; then
163 warning "can't find debconf-get-selections, skipping package selection states. You might want to install the debconf-utils package."
165 debug "$debconfgetselections > $selectionsfile"
166 $debconfgetselections > $selectionsfile || fatal "can not save $debconfgetselections info to $selectionsfile"
170 ## System report ##############################
173 # here we grab a bunch of system stuff for a report
178 HASHES="#################################################################"
179 DASHES="-----------------------------------------------------------------"
181 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
185 echo $HASHES >> $sysreportfile
186 echo "# $STATUS" >> $sysreportfile
187 echo $HASHES >> $sysreportfile
189 echo "file: $1" >> $sysreportfile
190 echo $DASHES >> $sysreportfile
191 cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
194 echo "directory: $1" >> $sysreportfile
195 echo $DASHES >> $sysreportfile
196 for file in `find $1 -maxdepth 3 -noleaf -type f`
201 echo $DASHES >> $sysreportfile
206 echo $HASHES >> $sysreportfile
207 echo "# $STATUS" >> $sysreportfile
208 echo $HASHES >> $sysreportfile
209 $* >> $sysreportfile 2>&1 || info "executing of $1 failed"
214 STATUS="Determining $os version:"
217 STATUS="Determinding your current hostname: "
218 catifexec "/bin/hostname"
220 STATUS="Getting the date:"
221 catifexec "/bin/date"
223 STATUS="Checking your systems current uptime and load average:"
224 catifexec "/usr/bin/uptime"
226 STATUS="Checking available memory:"
227 catifexec "/usr/bin/free"
229 STATUS="Checking free disk space:"
230 catifexec "/bin/df" "-al"
232 STATUS="Collecting what services run at what run level:"
233 if [ $os = "redhat" ]; then
234 catifexec "/sbin/chkconfig" "--list"
235 STATUS="Collecting information about /etc/rc.d:"
236 catiffile "/bin/ls /etc/rc.d/rc*.d/"
238 elif [ $os = "debian" ]; then
239 for level in 0 1 2 3 4 5 6 S; do
240 echo "Level: $level" >> $sysreportfile
241 for f in /etc/rc${level}.d/*; do
242 # Remove /etc/Knn or Snn from beginning
243 ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
244 if [ $f != $ff ]; then
245 echo $ff >> $sysreportfile
248 echo "" >> $sysreportfile
252 STATUS="Getting bootloader information:"
253 catifexec "/bin/ls" "-alR /boot"
255 # This covers sparc, alpha, and intel (respectively)
256 # updated for grub -mpg
257 if [ -f /etc/silo.conf ]; then
258 STATUS="Collecting information about the boot process (silo):"
259 catiffile "/etc/silo.conf"
261 if [ -f /etc/milo.conf ]; then
262 STATUS="Collecting information about the boot process (milo):"
263 catiffile "/etc/milo.conf"
265 if [ -f /etc/lilo.conf ]; then
266 STATUS="Collecting information about the boot process (lilo):"
267 catiffile "/etc/lilo.conf"
268 catifexec "/sbin/lilo" "-q"
270 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
271 STATUS="Collecting information about the boot process (grub.conf):"
272 catiffile "/boot/grub/grub.conf"
273 STATUS="Collecting information about the boot process (grub.map):"
274 catiffile "/boot/grub/device.map"
276 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
277 STATUS="Gathering information on cluster setup"
279 if [ -f /etc/cluster.conf ] ; then
280 catiffile "/etc/cluster.conf"
283 if [ -f /etc/cluster.xml ] ; then
284 catiffile "/etc/cluster.xml"
288 STATUS="Gathering sysctl information (sysctl -a):"
289 catiffile "sysctl -a 2>/dev/null"
290 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
291 catiffile "/etc/sysctl.conf"
293 STATUS="Gathering IP information (/sbin/ifconfig):"
294 catifexec "/sbin/ifconfig" "-a"
296 STATUS="Gathering additional IP information (/bin/ip addr list):"
297 catifexec "/bin/ip" "addr list"
299 STATUS="Checking network routes:"
300 catifexec "/sbin/route" "-n"
302 STATUS="Collecting Name Service Switch config information:"
303 catiffile "/etc/nsswitch.conf"
305 STATUS="Collecting information about system authentication (pam):"
306 catiffile "/etc/pam.conf"
307 catiffile "/etc/pam.d"
310 echo "Getting information about the kernel."
312 STATUS="Getting kernel version:"
313 catifexec "/bin/uname" "-a"
314 STATUS="Checking module information:"
315 catifexec "/sbin/lsmod"
316 for x in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
318 STATUS="Checking module information $x:"
319 catifexec "/sbin/modinfo" "$x"
322 STATUS="Gathering information about your filesystems:"
323 catiffile "/proc/filesystems"
325 STATUS="Gathering information about your system stat:"
326 catiffile "/proc/stat"
328 STATUS="Gathering information about your partitions:"
329 catiffile "/proc/partitions"
331 STATUS="Gathering information about your ksyms:"
332 catiffile "/proc/kallsyms"
334 STATUS="Gathering information about slabinfo:"
335 catiffile "/proc/slabinfo"
337 # Added support to cover for the new modules.conf layout in Red Hat 7
338 STATUS="Collecting information regarding kernel modules"
340 catiffile "/lib/modules/$VER/modules.dep"
341 if [ -f /etc/conf.modules ]; then
342 STATUS="Collecting information regarding kernel modules (conf.modules)"
343 catiffile "/etc/conf.modules"
345 if [ -f /etc/modules.conf ]; then
346 STATUS="Collecting information regarding kernel modules (modules.conf)"
347 catiffile "/etc/modules.conf"
349 if [ -f /etc/modprobe.conf ]; then
350 STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
351 catiffile "/etc/modprobe.conf"
355 if [ -x /usr/sbin/dkms ] ; then
356 STATUS="Gathering current status of modules, versions and kernels (dkms):"
357 catifexec "/usr/sbin/dkms" "status"
360 if [ -f /etc/sysconfig/isdncard ] ; then
361 STATUS="Gathering information about ISDN:"
362 catiffile "/etc/sysconfig/isdncard"
365 STATUS="Collecting information from the proc directory:"
366 catiffile "/proc/pci"
368 STATUS="Getting kernel command line"
369 catiffile "/proc/cmdline"
371 STATUS="Gathering information about your CPU:"
372 catiffile "/proc/cpuinfo"
374 STATUS="Gathering information about your Ram:"
375 catiffile "/proc/meminfo"
377 STATUS="Gathering information about your ioports:"
378 catiffile "/proc/ioports"
380 STATUS="Gathering information about your interrupts:"
381 catiffile "/proc/interrupts"
383 STATUS="Gathering information about your scsi devices:"
384 catiffile "/proc/scsi"
386 STATUS="Gathering information about your dma:"
387 catiffile "/proc/dma"
389 STATUS="Gathering information about your devices (/proc/devices):"
390 catiffile "/proc/devices"
392 STATUS="Gathering information about your rtc:"
393 catiffile "/proc/rtc"
395 STATUS="Gathering information about your ide drivers:"
396 catiffile "/proc/ide"
398 STATUS="Gathering information about your bus:"
399 catifexec "/usr/bin/lspci"
400 catiffile "/proc/bus"
403 echo "Getting disk and filesystem information."
406 STATUS="Collecting information from /etc/fstab:"
407 catiffile "/etc/fstab"
409 STATUS="Collecting disk partition information:"
410 catifexec "/sbin/fdisk" "-l"
412 STATUS="Checking mounted file systems (mount) "
413 catifexec "/bin/mount"
415 STATUS="Checking mounted file systems (/proc/mounts)"
416 catiffile "/proc/mounts"
418 STATUS="Collecting Software RAID information (/proc/mdstat)"
419 catiffile "/proc/mdstat"
421 STATUS="Collecting Software RAID information (/etc/raidtab)"
422 catiffile "/etc/raidtab"
424 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
425 catiffile "/etc/mdadm.conf"
427 STATUS="Collecting Software RAID information (/sbin/mdadm -Q)"
428 catifexec "/sbin/mdadm" "-Q" "--detail" '/dev/md?*'
430 STATUS="Collecting Automount information (auto.master)"
431 catiffile "/etc/auto.master"
433 STATUS="Collecting Automount information (auto.misc)"
434 catiffile "/etc/auto.misc"
436 STATUS="Collecting Automount information (auto.net)"
437 catiffile "/etc/auto.net"
439 STATUS="Collecting LVM information:"
440 if [ $os = "redhat" ]; then
441 catifexec "/usr/sbin/vgdisplay" "-vv"
442 elif [ $os = "debian" ]; then
443 catifexec "/sbin/vgdisplay" "-vv"
446 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
447 catiffile "/etc/stinit.def"
449 if [ -x /sbin/lsusb ] ; then
450 STATUS="Collecting USB devices list (lsusb):"
451 catifexec "/sbin/lsusb"
454 if [ -x /usr/bin/lshal ] ; then
455 STATUS="Collecting global devices list (lshal):"
456 catifexec "/usr/bin/lshal"
460 STATUS="Gathering information on SELinux setup"
461 catifexec "/usr/bin/selinuxconfig"
462 catifexec "/usr/sbin/sestatus"
463 if [ $os = "redhat" ]; then
464 catifexec "rpm" "-q -V selinux-policy-targeted"
465 catifexec "rpm" "-q -V selinux-policy-strict"
468 if [ $usevserver = yes ]; then
469 STATUS="Gathering vserver information"
470 catiffile "/proc/virtual"
473 if [ "$partitions" == "yes" ]; then
474 if [ "$dosfdisk" == "yes" ]; then
475 if [ ! -x "$SFDISK" ]; then
476 warning "can't find sfdisk, skipping sfdisk report."
480 if [ "$dohwinfo" == "yes" ]; then
481 if [ ! -x "$HWINFO" ]; then
482 warning "can't find hwinfo, skipping partition report."
488 if [ "$hardware" == "yes" ]; then
489 if [ ! -x "$HWINFO" ]; then
490 warning "can't find hwinfo, skipping hardware report."
495 ## HARDWARE #############################
498 # here we use hwinfo to dump a table listing all the
499 # information we can find on the hardware of this machine
502 if [ "$hardware" == "yes" ]; then
503 if [ "dohwinfo" == "yes" ]; then
504 if [ -f $hardwarefile ]; then
508 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
509 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
510 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
511 for flag in cpu network bios pci; do
512 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
513 $HWINFO --$flag >> $hardwarefile
519 ## PARTITIONS #############################
521 # here we use sfdisk to dump a listing of all the partitions.
522 # these files can be used to directly partition a disk of the same size.
524 if [ "$partitions" == "yes" ]; then
525 if [ "$dosfdisk" == "yes" ]; then
526 devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
527 if [ "$devices" == "" ]; then
528 warning "No harddisks found"
530 for dev in $devices; do
531 debug "$SFDISK will try to backup partition tables for device $dev"
532 [ -b $dev ] || continue
535 outputfile=${partitionsfile//__star__/$label}
536 debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
537 $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
538 if [ $? -ne 0 ]; then
539 warning "The partition table for $dev could not be saved."
543 if [ "$dohwinfo" == "yes" ]; then
544 debug "Using $HWINFO to get all available disk information"
545 echo -e "\n\n====================== $disk ======================\n" >> $hardwarefile
546 $HWINFO --disk >> $hardwarefile