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 for vserver in `ls $VROOTDIR |grep -v lost+found`
51 running=`vserver-info $vserver RUNNING`
52 if [ $running = 1 ]; then
53 if [ ! -x "`$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.
97 for vserver in `ls $VROOTDIR | grep -v $nodpkg | grep -v lost+found`
99 debug "$VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile"
100 $VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile
104 # We want to perform this on the host as well
105 if [ "$packages" == "yes" ]; then
106 debug "dpkg --get-selections > $packagesfile"
107 dpkg --get-selections > $packagesfile
111 ## PARTITIONS #############################
113 # here we use sfdisk to dump a listing of all the partitions.
114 # these files can be used to directly partition a disk of the same size.
116 if [ "$partitions" == "yes" ]; then
117 devices=`$HWINFO --disk | grep "Device File" | cut -d\ -f5`
118 for dev in $devices; do
119 [ -b $dev ] || continue
122 outputfile=${partitionsfile//__star__/$label}
123 debug "$SFDISK $sfdisk_options -d $dev > $outputfile"
124 $SFDISK $sfdisk_options -d $dev > $outputfile
128 ## HARDWARE #############################
131 # here we use hwinfo to dump a table listing all the
132 # information we can find on the hardware of this machine
135 if [ "$hardware" == "yes" ]; then
136 if [ -f $hardwarefile ]; then
140 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
141 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
142 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
143 for flag in cpu network disk bios pci; do
144 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
145 $HWINFO --$flag >> $hardwarefile