2005-12-28 21:19:29 +01:00
# -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2009-05-22 15:27:09 +02:00
# vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
2004-12-23 03:54:53 +01:00
#
# this handler will save various reports of vital system information.
2009-01-22 23:14:22 +01:00
# by default, all the reports are saved in /var/backups.
2004-12-23 03:54:53 +01:00
#
2008-06-24 20:57:39 +02:00
# (1) a capture of the debconf package selection states. This file
# can be used to restore the answers to debconf questions for
# packages that you will be installing through (2) below. To
# do this, run: "debconf-set-selections < debconfsel.txt"
#
# (2) a list of all the packages installed and removed.
2004-12-23 03:54:53 +01:00
# this file can be used to restore the state of installed packages
2008-06-24 20:57:39 +02:00
# by running "dpkg --set-selections < dpkg-selections.txt and
2009-05-22 14:50:52 +02:00
# then run "apt-get -u dselect-upgrade". If you have the
2008-06-24 20:57:39 +02:00
# debconf-set-selections file from (1), you should restore those first.
2009-05-22 14:50:52 +02:00
#
# (3) the partition table of all disks.
2004-12-23 03:54:53 +01:00
# this partition table can be used to format another disk of
2009-05-22 14:50:52 +02:00
# the same size. this can be handy if using software raid and
2004-12-23 03:54:53 +01:00
# you have a disk go bad. just replace the disk and partition it
# by running "sfdisk /dev/sdb < partitions.sdb.txt"
# (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
#
2009-05-22 14:50:52 +02:00
# (4) hardware information.
2005-03-14 22:49:29 +01:00
# write to a text file the important things which hwinfo can gleen.
2005-03-10 12:22:27 +01:00
#
2009-01-22 23:14:22 +01:00
# (5) the Luks header of every Luks block device, if option luksheaders
# is enabled.
# in case you (have to) scramble such a Luks header (for some time),
# and restore it later by running "dd if=luksheader.sda2.bin of=/dev/sda2"
# (MAKE SURE YOU PASS THE CORRECT DEVICE AS of= !!!)
#
2009-01-22 23:15:13 +01:00
# (6) LVM metadata for every detected volume group, if "lvm = yes"
#
2004-12-23 03:54:53 +01:00
2006-04-13 18:51:25 +02:00
if [ -f /etc/debian_version ]
then
os=debian
debug "Debian detected"
osversion="/etc/debian_version"
elif [ -f /etc/redhat-release ]
then
os=redhat
debug "Redhat detected"
osversion="/etc/redhat-release"
else
warning "Unknown OS detected!"
fi
2007-11-24 22:32:30 +01:00
getconf parentdir /var/backups
2004-12-23 03:54:53 +01:00
getconf packages yes
2007-03-04 11:29:26 +01:00
getconf dosfdisk yes
getconf dohwinfo yes
2007-11-24 22:32:30 +01:00
if [ ! -d $parentdir ]; then
mkdir -p $parentdir
fi
2009-05-22 14:50:52 +02:00
2006-04-13 18:51:25 +02:00
if [ $os = "debian" ]
then
2007-11-24 22:32:30 +01:00
getconf packagesfile $parentdir/dpkg-selections.txt
2006-04-13 18:51:25 +02:00
getconf packagemgr `which dpkg`
2006-10-07 05:27:24 +02:00
getconf packagemgroptions ' --get-selections *'
2008-06-25 10:47:48 +02:00
getconf selectionsfile $parentdir/debconfsel.txt
2008-06-24 22:31:58 +02:00
getconf debconfgetselections `which debconf-get-selections`
2006-04-13 18:51:25 +02:00
elif [ $os = "redhat" ]
then
2009-05-22 14:50:52 +02:00
getconf packagesfile $parentdir/rpmpackages.txt
getconf packagemgr `which rpm`
getconf packagemgroptions ' -qa '
2006-04-13 18:51:25 +02:00
getconf SYSREPORT `which sysreport`
2006-10-07 05:27:24 +02:00
getconf sysreport_options ' -norpm '
2006-04-13 18:51:25 +02:00
else
2007-11-24 22:32:30 +01:00
getconf packagesfile $parentdir/unknownOS.txt
2006-04-13 18:51:25 +02:00
fi
2006-10-07 05:27:24 +02:00
packagemgroptions="${packagemgroptions//__star__/*}"
2004-12-23 03:54:53 +01:00
getconf partitions yes
2007-11-24 22:32:30 +01:00
getconf partitionsfile $parentdir/partitions.__star__.txt
2004-12-23 03:54:53 +01:00
getconf hardware yes
2007-11-24 22:32:30 +01:00
getconf hardwarefile $parentdir/hardware.txt
2004-12-23 03:54:53 +01:00
2006-04-13 18:51:25 +02:00
getconf sysreport yes
2007-11-24 22:32:30 +01:00
getconf sysreportfile $parentdir/sysreport.txt
2006-04-13 18:51:25 +02:00
2005-07-01 22:09:16 +02:00
getconf SFDISK `which sfdisk`
getconf HWINFO `which hwinfo`
getconf sfdisk_options ""
getconf hwinfo_options ""
2009-01-22 23:14:22 +01:00
getconf CRYPTSETUP `which cryptsetup`
getconf DD `which dd`
getconf luksheaders no
getconf luksheadersfile $parentdir/luksheader.__star__.bin
2009-01-22 23:15:13 +01:00
getconf VGS `which vgs`
getconf VGCFGBACKUP `which vgcfgbackup`
getconf lvm no
2008-06-24 18:05:44 +02:00
getconf vsnames all
# If vservers are configured, check that the ones listed in $vsnames are running.
2011-04-25 18:55:58 +02:00
usevserver=no
2008-06-24 18:05:44 +02:00
if [ $vservers_are_available = yes ]; then
if [ "$vsnames" = all ]; then
vsnames="$found_vservers"
fi
if ! vservers_running "$vsnames" ; then
fatal "At least one of the vservers listed in vsnames ($vsnames) is not running."
fi
info "Using vservers '$vsnames'"
2006-01-19 22:58:29 +01:00
usevserver=yes
2005-05-24 21:27:43 +02:00
fi
2009-01-22 23:14:22 +01:00
## SANITY CHECKS #########################
if [ "$luksheaders" == "yes" ]; then
if [ ! -x "$DD" ]; then
warning "can't find dd, skipping backup of Luks headers."
luksheaders="no"
fi
if [ ! -x "$CRYPTSETUP" ]; then
warning "can't find cryptsetup, skipping backup of Luks headers."
luksheaders="no"
fi
fi
2009-01-22 23:15:13 +01:00
if [ "$lvm" == "yes" ]; then
if [ ! -x "$VGS" ]; then
warning "can't find vgs, skipping backup of LVM metadata"
lvm="no"
fi
if [ ! -x "$VGCFGBACKUP" ]; then
warning "can't find vgcfgbackup, skipping backup of LVM metadata"
lvm="no"
fi
fi
2006-04-13 18:51:25 +02:00
## PACKAGES ##############################
#
# here we grab a list of the packages installed and removed.
#
2004-12-23 03:54:53 +01:00
if [ "$packages" == "yes" ]; then
2006-10-28 21:19:55 +02:00
if [ $usevserver = yes ]; then
info "vserver root directory set to: $VROOTDIR"
2008-06-24 18:05:44 +02:00
for vserver in $vsnames; do
2006-10-28 21:19:55 +02:00
info "examining vserver: $vserver"
# is it running ?
2008-06-24 17:49:06 +02:00
vservers_running $vserver
2006-10-28 21:19:55 +02:00
if [ $? -ne 0 ]; then
warning "The vserver $vserver is not running."
continue
fi
# is $packagemgr available inside $vserver ?
2008-06-25 11:21:11 +02:00
if [ ! -x "${VROOTDIR}/${vserver}${packagemgr}" ]; then
2006-10-28 21:19:55 +02:00
warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
2008-06-24 20:57:39 +02:00
else
# don't expand * since it can be used in $packagemgroptions
set -o noglob
debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
2009-05-22 14:50:52 +02:00
$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
2008-06-24 20:57:39 +02:00
set +o noglob
fi
# is $debconfgetselections available inside $vserver ?
2008-06-25 11:21:11 +02:00
found=no
# case #1: it is available on the host, is it available inside $vserver ?
if [ -n "$debconfgetselections" ]; then
[ -x "${VROOTDIR}/${vserver}${debconfgetselections}" ] && found=yes
# case #2: it is not available on the host, is it available inside $vserver ?
else
[ -n "`$VSERVER $vserver exec which debconf-get-selections`" ] && found=yes
fi
if [ "$found" != yes ]; then
2008-06-29 09:01:29 +02:00
warning "can't find debconf-get-selections in vserver $vserver, skipping package selection states. You may want to install the debconf-utils package."
2008-06-24 20:57:39 +02:00
else
debug "$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile"
2008-06-25 11:00:04 +02:00
$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile || fatal "can not save debconf-get-selections info to $selectionsfile"
2006-10-28 21:19:55 +02:00
fi
2008-06-25 11:21:11 +02:00
unset found
2006-04-13 18:51:25 +02:00
done
fi
2009-05-22 14:50:52 +02:00
2006-10-28 21:19:55 +02:00
# We want to perform this on the host as well
2009-05-22 14:50:52 +02:00
if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
2006-10-28 21:19:55 +02:00
warning "can't find ${packagemgr}, skipping installed packages report."
else
2006-10-07 05:27:24 +02:00
# don't expand * since it can be used in $packagemgroptions
set -o noglob
2006-04-13 18:51:25 +02:00
debug "$packagemgr $packagemgroptions > $packagesfile"
$packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
2006-10-07 05:27:24 +02:00
set +o noglob
2006-04-13 18:51:25 +02:00
fi
2008-06-24 20:57:39 +02:00
if [ -z "$debconfgetselections" ]; then
2008-06-29 09:01:29 +02:00
warning "can't find debconf-get-selections, skipping package selection states. You might want to install the debconf-utils package."
2008-06-24 20:57:39 +02:00
else
debug "$debconfgetselections > $selectionsfile"
$debconfgetselections > $selectionsfile || fatal "can not save $debconfgetselections info to $selectionsfile"
fi
2006-04-13 18:51:25 +02:00
fi
## System report ##############################
#
# here we grab a bunch of system stuff for a report
#
export STATUS
HASHES="#################################################################"
DASHES="-----------------------------------------------------------------"
cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
catiffile () {
echo $HASHES >> $sysreportfile
echo "# $STATUS" >> $sysreportfile
echo $HASHES >> $sysreportfile
if [ -f $1 ]; then
echo "file: $1" >> $sysreportfile
echo $DASHES >> $sysreportfile
cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
fi
if [ -d $1 ]; then
echo "directory: $1" >> $sysreportfile
echo $DASHES >> $sysreportfile
for file in `find $1 -maxdepth 3 -noleaf -type f`
do
catiffile $file
done
fi
echo $DASHES >> $sysreportfile
2009-05-22 14:50:52 +02:00
}
2006-04-13 18:51:25 +02:00
catifexec () {
2008-06-24 21:53:36 +02:00
if [ -x $1 ]; then
echo $HASHES >> $sysreportfile
echo "# $STATUS" >> $sysreportfile
echo $HASHES >> $sysreportfile
$* >> $sysreportfile 2>&1 || info "executing of $1 failed"
fi
2006-04-13 18:51:25 +02:00
}
2009-05-22 14:50:52 +02:00
2006-04-13 18:51:25 +02:00
STATUS="Determining $os version:"
catiffile $osversion
2009-05-22 14:50:52 +02:00
STATUS="Determinding your current hostname: "
2006-04-13 18:51:25 +02:00
catifexec "/bin/hostname"
STATUS="Getting the date:"
catifexec "/bin/date"
STATUS="Checking your systems current uptime and load average:"
catifexec "/usr/bin/uptime"
STATUS="Checking available memory:"
catifexec "/usr/bin/free"
STATUS="Checking free disk space:"
catifexec "/bin/df" "-al"
STATUS="Collecting what services run at what run level:"
if [ $os = "redhat" ]; then
2008-06-25 11:07:30 +02:00
catifexec "/sbin/chkconfig" "--list"
2006-04-13 18:51:25 +02:00
STATUS="Collecting information about /etc/rc.d:"
catiffile "/bin/ls /etc/rc.d/rc*.d/"
elif [ $os = "debian" ]; then
2009-05-22 14:50:52 +02:00
for level in 0 1 2 3 4 5 6 S; do
echo "Level: $level" >> $sysreportfile
for f in /etc/rc${level}.d/*; do
# Remove /etc/Knn or Snn from beginning
ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
if [ $f != $ff ]; then
echo $ff >> $sysreportfile
fi
done
echo "" >> $sysreportfile
done
2006-04-13 18:51:25 +02:00
fi
STATUS="Getting bootloader information:"
2008-06-25 11:07:30 +02:00
catifexec "/bin/ls" "-alR /boot"
2006-04-13 18:51:25 +02:00
# This covers sparc, alpha, and intel (respectively)
# updated for grub -mpg
if [ -f /etc/silo.conf ]; then
2009-05-22 14:50:52 +02:00
STATUS="Collecting information about the boot process (silo):"
catiffile "/etc/silo.conf"
2006-04-13 18:51:25 +02:00
fi
if [ -f /etc/milo.conf ]; then
2009-05-22 14:50:52 +02:00
STATUS="Collecting information about the boot process (milo):"
catiffile "/etc/milo.conf"
2006-04-13 18:51:25 +02:00
fi
if [ -f /etc/lilo.conf ]; then
2009-05-22 14:50:52 +02:00
STATUS="Collecting information about the boot process (lilo):"
catiffile "/etc/lilo.conf"
catifexec "/sbin/lilo" "-q"
2006-04-13 18:51:25 +02:00
fi
if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
2009-05-22 14:50:52 +02:00
STATUS="Collecting information about the boot process (grub.conf):"
catiffile "/boot/grub/grub.conf"
STATUS="Collecting information about the boot process (grub.map):"
catiffile "/boot/grub/device.map"
2006-04-13 18:51:25 +02:00
fi
if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
2009-05-22 14:50:52 +02:00
STATUS="Gathering information on cluster setup"
# 2.1 AS
if [ -f /etc/cluster.conf ] ; then
catiffile "/etc/cluster.conf"
fi
# Taroon
if [ -f /etc/cluster.xml ] ; then
catiffile "/etc/cluster.xml"
fi
2006-04-13 18:51:25 +02:00
fi
STATUS="Gathering sysctl information (sysctl -a):"
catiffile "sysctl -a 2>/dev/null"
STATUS="Gathering sysctl information (/etc/sysctl.conf):"
catiffile "/etc/sysctl.conf"
STATUS="Gathering IP information (/sbin/ifconfig):"
2008-06-25 11:07:30 +02:00
catifexec "/sbin/ifconfig" "-a"
2006-04-13 18:51:25 +02:00
STATUS="Gathering additional IP information (/bin/ip addr list):"
2008-06-25 11:07:30 +02:00
catifexec "/bin/ip" "addr list"
2006-04-13 18:51:25 +02:00
STATUS="Checking network routes:"
2008-06-25 11:07:30 +02:00
catifexec "/sbin/route" "-n"
2006-04-13 18:51:25 +02:00
STATUS="Collecting Name Service Switch config information:"
catiffile "/etc/nsswitch.conf"
STATUS="Collecting information about system authentication (pam):"
catiffile "/etc/pam.conf"
catiffile "/etc/pam.d"
echo
echo "Getting information about the kernel."
echo
STATUS="Getting kernel version:"
catifexec "/bin/uname" "-a"
STATUS="Checking module information:"
catifexec "/sbin/lsmod"
2011-05-15 19:19:48 +02:00
for x in $(/sbin/lsmod | /usr/bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
2006-04-13 18:51:25 +02:00
) ; do
2009-05-22 14:50:52 +02:00
STATUS="Checking module information $x:"
catifexec "/sbin/modinfo" "$x"
2006-04-13 18:51:25 +02:00
done
STATUS="Gathering information about your filesystems:"
catiffile "/proc/filesystems"
STATUS="Gathering information about your system stat:"
catiffile "/proc/stat"
STATUS="Gathering information about your partitions:"
catiffile "/proc/partitions"
2006-10-07 05:28:21 +02:00
STATUS="Gathering information about your ksyms:"
2008-06-24 17:13:51 +02:00
catiffile "/proc/kallsyms"
2006-04-13 18:51:25 +02:00
STATUS="Gathering information about slabinfo:"
catiffile "/proc/slabinfo"
# Added support to cover for the new modules.conf layout in Red Hat 7
STATUS="Collecting information regarding kernel modules"
VER=`uname -r`
catiffile "/lib/modules/$VER/modules.dep"
if [ -f /etc/conf.modules ]; then
2009-05-22 14:50:52 +02:00
STATUS="Collecting information regarding kernel modules (conf.modules)"
catiffile "/etc/conf.modules"
2006-04-13 18:51:25 +02:00
fi
if [ -f /etc/modules.conf ]; then
2009-05-22 14:50:52 +02:00
STATUS="Collecting information regarding kernel modules (modules.conf)"
catiffile "/etc/modules.conf"
2006-04-13 18:51:25 +02:00
fi
if [ -f /etc/modprobe.conf ]; then
2009-05-22 14:50:52 +02:00
STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
catiffile "/etc/modprobe.conf"
2006-04-13 18:51:25 +02:00
fi
# dkms status
if [ -x /usr/sbin/dkms ] ; then
STATUS="Gathering current status of modules, versions and kernels (dkms):"
2009-05-22 14:50:52 +02:00
catifexec "/usr/sbin/dkms" "status"
2006-04-13 18:51:25 +02:00
fi
if [ -f /etc/sysconfig/isdncard ] ; then
2009-05-22 14:50:52 +02:00
STATUS="Gathering information about ISDN:"
catiffile "/etc/sysconfig/isdncard"
2006-04-13 18:51:25 +02:00
fi
STATUS="Collecting information from the proc directory:"
catiffile "/proc/pci"
STATUS="Getting kernel command line"
catiffile "/proc/cmdline"
STATUS="Gathering information about your CPU:"
catiffile "/proc/cpuinfo"
STATUS="Gathering information about your Ram:"
catiffile "/proc/meminfo"
STATUS="Gathering information about your ioports:"
catiffile "/proc/ioports"
STATUS="Gathering information about your interrupts:"
catiffile "/proc/interrupts"
STATUS="Gathering information about your scsi devices:"
catiffile "/proc/scsi"
STATUS="Gathering information about your dma:"
catiffile "/proc/dma"
STATUS="Gathering information about your devices (/proc/devices):"
catiffile "/proc/devices"
STATUS="Gathering information about your rtc:"
catiffile "/proc/rtc"
STATUS="Gathering information about your ide drivers:"
catiffile "/proc/ide"
STATUS="Gathering information about your bus:"
2008-06-24 21:57:31 +02:00
catifexec "/usr/bin/lspci"
2006-04-13 18:51:25 +02:00
catiffile "/proc/bus"
echo
echo "Getting disk and filesystem information."
echo
STATUS="Collecting information from /etc/fstab:"
catiffile "/etc/fstab"
STATUS="Collecting disk partition information:"
2008-06-25 11:07:30 +02:00
catifexec "/sbin/fdisk" "-l"
2006-04-13 18:51:25 +02:00
STATUS="Checking mounted file systems (mount) "
catifexec "/bin/mount"
STATUS="Checking mounted file systems (/proc/mounts)"
catiffile "/proc/mounts"
STATUS="Collecting Software RAID information (/proc/mdstat)"
catiffile "/proc/mdstat"
STATUS="Collecting Software RAID information (/etc/raidtab)"
catiffile "/etc/raidtab"
STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
catiffile "/etc/mdadm.conf"
2008-06-24 21:57:31 +02:00
STATUS="Collecting Software RAID information (/sbin/mdadm -Q)"
2010-03-06 15:27:34 +01:00
if ls /dev/md?* >/dev/null 2>&1; then
catifexec "/sbin/mdadm" "-Q" "--detail" '/dev/md?*'
fi
2008-06-24 21:57:31 +02:00
2006-04-13 18:51:25 +02:00
STATUS="Collecting Automount information (auto.master)"
catiffile "/etc/auto.master"
STATUS="Collecting Automount information (auto.misc)"
catiffile "/etc/auto.misc"
STATUS="Collecting Automount information (auto.net)"
catiffile "/etc/auto.net"
STATUS="Collecting LVM information:"
if [ $os = "redhat" ]; then
catifexec "/usr/sbin/vgdisplay" "-vv"
elif [ $os = "debian" ]; then
catifexec "/sbin/vgdisplay" "-vv"
fi
2009-01-23 00:37:50 +01:00
STATUS="Collecting device-mapper (dm) information:"
catifexec '/sbin/dmsetup' 'info'
2009-05-22 14:50:52 +02:00
2006-04-13 18:51:25 +02:00
STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
catiffile "/etc/stinit.def"
if [ -x /sbin/lsusb ] ; then
2009-05-22 14:50:52 +02:00
STATUS="Collecting USB devices list (lsusb):"
catifexec "/sbin/lsusb"
2006-04-13 18:51:25 +02:00
fi
if [ -x /usr/bin/lshal ] ; then
2009-05-22 14:50:52 +02:00
STATUS="Collecting global devices list (lshal):"
catifexec "/usr/bin/lshal"
2006-04-13 18:51:25 +02:00
fi
STATUS="Gathering information on SELinux setup"
catifexec "/usr/bin/selinuxconfig"
catifexec "/usr/sbin/sestatus"
if [ $os = "redhat" ]; then
catifexec "rpm" "-q -V selinux-policy-targeted"
catifexec "rpm" "-q -V selinux-policy-strict"
fi
if [ $usevserver = yes ]; then
STATUS="Gathering vserver information"
catiffile "/proc/virtual"
fi
2004-12-23 03:54:53 +01:00
if [ "$partitions" == "yes" ]; then
2007-03-04 11:29:26 +01:00
if [ "$dosfdisk" == "yes" ]; then
2009-05-22 14:50:52 +02:00
if [ ! -x "$SFDISK" ]; then
warning "can't find sfdisk, skipping sfdisk report."
partitions="no"
fi
2007-03-04 11:29:26 +01:00
fi
if [ "$dohwinfo" == "yes" ]; then
2009-05-22 14:50:52 +02:00
if [ ! -x "$HWINFO" ]; then
warning "can't find hwinfo, skipping partition report."
partitions="no"
fi
2007-03-04 11:29:26 +01:00
fi
2004-12-23 03:54:53 +01:00
fi
if [ "$hardware" == "yes" ]; then
2009-05-22 14:50:52 +02:00
if [ ! -x "$HWINFO" ]; then
warning "can't find hwinfo, skipping hardware report."
hardware="no"
fi
2004-12-23 03:54:53 +01:00
fi
2007-03-04 11:29:26 +01:00
## HARDWARE #############################
#
# here we use hwinfo to dump a table listing all the
# information we can find on the hardware of this machine
2009-05-22 14:50:52 +02:00
#
2007-03-04 11:29:26 +01:00
if [ "$hardware" == "yes" ]; then
2011-05-05 09:16:59 +02:00
if [ "$dohwinfo" == "yes" ]; then
2007-03-04 11:29:26 +01:00
if [ -f $hardwarefile ]; then
2009-05-22 14:50:52 +02:00
rm $hardwarefile
2007-03-04 11:29:26 +01:00
fi
touch $hardwarefile
echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
$HWINFO --short --cpu --network --disk --pci >> $hardwarefile
for flag in cpu network bios pci; do
2009-05-22 14:50:52 +02:00
echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
$HWINFO --$flag >> $hardwarefile
2007-03-04 11:29:26 +01:00
done
fi
fi
2004-12-23 03:54:53 +01:00
## PARTITIONS #############################
2009-05-22 14:50:52 +02:00
# here we use sfdisk to dump a listing of all the partitions.
2004-12-23 03:54:53 +01:00
# these files can be used to directly partition a disk of the same size.
if [ "$partitions" == "yes" ]; then
2007-03-04 11:29:26 +01:00
if [ "$dosfdisk" == "yes" ]; then
2007-03-04 21:15:39 +01:00
devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
2009-05-22 14:50:52 +02:00
if [ "$devices" == "" ]; then
warning "No harddisks found"
fi
for dev in $devices; do
debug "$SFDISK will try to backup partition tables for device $dev"
[ -b $dev ] || continue
label=${dev#/dev/}
label=${label//\//-}
outputfile=${partitionsfile//__star__/$label}
debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
if [ $? -ne 0 ]; then
warning "The partition table for $dev could not be saved."
fi
done
2007-03-04 11:29:26 +01:00
fi
if [ "$dohwinfo" == "yes" ]; then
debug "Using $HWINFO to get all available disk information"
echo -e "\n\n====================== $disk ======================\n" >> $hardwarefile
$HWINFO --disk >> $hardwarefile
fi
2004-12-23 03:54:53 +01:00
fi
2009-01-22 23:14:22 +01:00
if [ "$luksheaders" == "yes" ]; then
devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
[ -n "$devices" ] || warning "No block device found"
targetdevices=""
for dev in $devices; do
[ -b $dev ] || continue
debug "$CRYPTSETUP isLuks $dev"
$CRYPTSETUP isLuks $dev
[ $? -eq 0 ] && targetdevices="$targetdevices $dev"
done
for dev in $targetdevices; do
label=${dev#/dev/}
label=${label//\//-}
outputfile=${luksheadersfile//__star__/$label}
# the following sizes are expressed in terms of 512-byte sectors
debug "Let us find out the Luks header size for $dev"
debug "$CRYPTSETUP luksDump \"$dev\" | grep '^Payload offset:' | @AWK@ '{print $3}'"
headersize=`$CRYPTSETUP luksDump "$dev" | grep '^Payload offset:' | @AWK@ '{print $3}'`
if [ $? -ne 0 ]; then
warning "Could not compute the size of Luks header, skipping device $dev"
continue
elif [ -z "$headersize" -o -n "`echo \"$headersize\" | sed 's/[0-9]*//g'`" ]; then
warning "The computed size of Luks header is not an integer, skipping device $dev"
continue
fi
debug "Let us backup the Luks header of device $dev"
debug "$DD if=\"${dev}\" of=\"${outputfile}\" bs=512 count=\"${headersize}\""
output=`$DD if="${dev}" of="${outputfile}" bs=512 count="${headersize}" 2>&1`
exit_code=$?
if [ $exit_code -eq 0 ]; then
debug $output
info "The Luks header of $dev was saved to $outputfile."
else
debug $output
fatal "The Luks header of $dev could not be saved."
fi
done
fi
2009-01-22 23:15:13 +01:00
## LVM ####################################
# returns 0 on success, 1 on error, 2 if not tried
# outputs error message if error, reason if not tried
function doLvmBackup () {
local lvmdir="$1"
if [ ! -d "$lvmdir" ]; then
if ! mkdir "$lvmdir"; then
echo "could not create $lvmdir"
return 2
else
info "successfully created $lvmdir"
fi
fi
if [ ! -w "$lvmdir" ]; then
2009-05-22 14:50:52 +02:00
echo "can not write to directory $lvmdir"
return 2
2009-01-22 23:15:13 +01:00
fi
debug "Let's try to gather the list of LVM volume groups"
debug "$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '"
vgs=`$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '`
debug "Let's try to backup LVM metadata for detected volume groups: $vgs"
2010-10-02 00:09:43 +02:00
for vg in $vgs
do
debug "$VGCFGBACKUP --file \"${lvmdir}\"/\'%s\' $vg"
output=`$VGCFGBACKUP --file "${lvmdir}"/'%s' $vg`
done
2009-01-22 23:15:13 +01:00
exit_code=$?
debug $output
case $exit_code in
0)
info "LVM metadata was saved to $lvmdir for volume groups: $vgs"
return 0
;;
*)
echo "LVM metadata could not be saved for at least one of these volume groups: $vgs"
return 1
;;
esac
}
if [ "$lvm" == "yes" ]; then
output=`doLvmBackup "${parentdir}/lvm"`
exit_code=$?
case $exit_code in
0) # success. info message has already been displayed
true
;;
1) # error
fatal "$output"
;;
2) # could not even try
fatal "LVM metadata backup was not tried: $output"
;;
*) # should never happen
fatal "Unhandled error ($exit_code) while trying to backup LVM metadata, please report a bug"
;;
esac
fi