2 # this handler will save various reports of vital system information.
3 # by default, all the reports are enabled and are saved in /var/backups.
5 # (1) a list of all the packages installed and removed.
6 # this file can be used to restore the state of installed packages
7 # by running "dpkg --set-selections < dpkg-selections.txt
9 # (2) the partition table of all disks.
10 # this partition table can be used to format another disk of
11 # the same size. this can be handy if using software raid and
12 # you have a disk go bad. just replace the disk and partition it
13 # by running "sfdisk /dev/sdb < partitions.sdb.txt"
14 # (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
16 # (3) hardware information.
17 # write to a text file the important things which hwinfo can gleen.
21 getconf packagesfile /var/backups/dpkg-selections.txt
23 getconf partitions yes
24 getconf partitionsfile /var/backups/partitions.__star__.txt
27 getconf hardwarefile /var/backups/hardware.txt
29 getconf SFDISK `which sfdisk`
30 getconf HWINFO `which hwinfo`
31 getconf sfdisk_options ""
32 getconf hwinfo_options ""
34 # See if vservers are configured
35 if [ "$vservers" = "yes" ]
39 fatal "vservers enabled, but $VROOTDIR does not exist!"
41 info "vserver method enabled"
46 if [ "$packages" == "yes" ]; then
49 nodpkg="lost+found|ARCHIVES"
50 info "vserver root directory set to: $VROOTDIR"
51 for vserver in `ls $VROOTDIR | grep -E -v $nodpkg`
53 info "examining vserver: $vserver"
54 running=`$VSERVERINFO $vserver RUNNING`
55 if [ "$running" = "1" ]; then
56 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which dpkg`" ]; then
57 warning "can't find dpkg in vserver $vserver, skipping installed packages report."
58 nodpkg="$nodpkg|$vserver"
61 warning "vserver $vserver is not running, skipping installed packages report."
62 nodpkg="$nodpkg|$vserver"
67 if [ ! -x "`which dpkg`" ]; then
68 warning "can't find dpkg, skipping installed packages report."
74 if [ "$partitions" == "yes" ]; then
75 if [ ! -x "$SFDISK" ]; then
76 warning "can't find sfdisk, skipping partition report."
79 if [ ! -x "$HWINFO" ]; then
80 warning "can't find hwinfo, skipping partition report."
85 if [ "$hardware" == "yes" ]; then
86 if [ ! -x "$HWINFO" ]; then
87 warning "can't find hwinfo, skipping hardware report."
92 ## PACKAGES ##############################
95 # here we grab a list of the packages installed and removed.
98 if [ "$packages" == "yes" ]; then
101 for vserver in `ls $VROOTDIR | grep -E -v $nodpkg`
103 debug "$VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile"
104 $VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile
108 # We want to perform this on the host as well
109 if [ "$packages" == "yes" ]; then
110 debug "dpkg --get-selections > $packagesfile"
111 dpkg --get-selections > $packagesfile
115 ## PARTITIONS #############################
117 # here we use sfdisk to dump a listing of all the partitions.
118 # these files can be used to directly partition a disk of the same size.
120 if [ "$partitions" == "yes" ]; then
121 devices=`$HWINFO --disk | grep "Device File" | cut -d\ -f5`
122 for dev in $devices; do
123 [ -b $dev ] || continue
126 outputfile=${partitionsfile//__star__/$label}
127 debug "$SFDISK $sfdisk_options -d $dev > $outputfile"
128 $SFDISK $sfdisk_options -d $dev > $outputfile
132 ## HARDWARE #############################
135 # here we use hwinfo to dump a table listing all the
136 # information we can find on the hardware of this machine
139 if [ "$hardware" == "yes" ]; then
140 if [ -f $hardwarefile ]; then
144 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
145 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
146 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
147 for flag in cpu network disk bios pci; do
148 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
149 $HWINFO --$flag >> $hardwarefile