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 list of all the packages installed and removed.
7 # this file can be used to restore the state of installed packages
8 # by running "dpkg --set-selections < dpkg-selections.txt
10 # (2) the partition table of all disks.
11 # this partition table can be used to format another disk of
12 # the same size. this can be handy if using software raid and
13 # you have a disk go bad. just replace the disk and partition it
14 # by running "sfdisk /dev/sdb < partitions.sdb.txt"
15 # (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
17 # (3) hardware information.
18 # write to a text file the important things which hwinfo can gleen.
22 getconf packagesfile /var/backups/dpkg-selections.txt
24 getconf partitions yes
25 getconf partitionsfile /var/backups/partitions.__star__.txt
28 getconf hardwarefile /var/backups/hardware.txt
30 getconf SFDISK `which sfdisk`
31 getconf HWINFO `which hwinfo`
32 getconf sfdisk_options ""
33 getconf hwinfo_options ""
35 # See if vservers are configured
37 if [ $vservers_are_available = yes ]
39 info "vserver method enabled"
43 if [ "$packages" == "yes" ]; then
44 if [ $usevserver = yes ]
46 nodpkg="lost+found|ARCHIVES"
47 info "vserver root directory set to: $VROOTDIR"
48 for vserver in $found_vservers
50 info "examining vserver: $vserver"
51 running=`$VSERVERINFO $vserver RUNNING`
52 if [ "$running" = "1" ]; then
53 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which dpkg`" ]; then
54 warning "can't find dpkg in vserver $vserver, skipping installed packages report."
55 nodpkg="$nodpkg|$vserver"
58 warning "vserver $vserver is not running, skipping installed packages report."
59 nodpkg="$nodpkg|$vserver"
64 if [ ! -x "`which dpkg`" ]; then
65 warning "can't find dpkg, skipping installed packages report."
71 if [ "$partitions" == "yes" ]; then
72 if [ ! -x "$SFDISK" ]; then
73 warning "can't find sfdisk, skipping partition report."
76 if [ ! -x "$HWINFO" ]; then
77 warning "can't find hwinfo, skipping partition report."
82 if [ "$hardware" == "yes" ]; then
83 if [ ! -x "$HWINFO" ]; then
84 warning "can't find hwinfo, skipping hardware report."
89 ## PACKAGES ##############################
92 # here we grab a list of the packages installed and removed.
95 if [ "$packages" == "yes" ]; then
96 if [ $usevserver = yes ]
98 for vserver in `ls $VROOTDIR | grep -E -v $nodpkg`
100 debug "$VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile"
101 $VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile
105 # We want to perform this on the host as well
106 if [ "$packages" == "yes" ]; then
107 debug "dpkg --get-selections > $packagesfile"
108 dpkg --get-selections > $packagesfile
112 ## PARTITIONS #############################
114 # here we use sfdisk to dump a listing of all the partitions.
115 # these files can be used to directly partition a disk of the same size.
117 if [ "$partitions" == "yes" ]; then
118 devices=`$HWINFO --disk | grep "Device File" | cut -d\ -f5`
119 for dev in $devices; do
120 [ -b $dev ] || continue
123 outputfile=${partitionsfile//__star__/$label}
124 debug "$SFDISK $sfdisk_options -d $dev > $outputfile"
125 $SFDISK $sfdisk_options -d $dev > $outputfile
129 ## HARDWARE #############################
132 # here we use hwinfo to dump a table listing all the
133 # information we can find on the hardware of this machine
136 if [ "$hardware" == "yes" ]; then
137 if [ -f $hardwarefile ]; then
141 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
142 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
143 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
144 for flag in cpu network disk bios pci; do
145 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
146 $HWINFO --$flag >> $hardwarefile