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
36 if [ "$vservers" = "yes" ]
40 fatal "vservers enabled, but $VROOTDIR does not exist!"
42 info "vserver method enabled"
47 if [ "$packages" == "yes" ]; then
50 nodpkg="lost+found|ARCHIVES"
51 info "vserver root directory set to: $VROOTDIR"
52 for vserver in `ls $VROOTDIR | grep -E -v $nodpkg`
54 info "examining vserver: $vserver"
55 running=`$VSERVERINFO $vserver RUNNING`
56 if [ "$running" = "1" ]; then
57 if [ ! -x "$VROOTDIR/$vserver`$VSERVER $vserver exec which dpkg`" ]; then
58 warning "can't find dpkg in vserver $vserver, skipping installed packages report."
59 nodpkg="$nodpkg|$vserver"
62 warning "vserver $vserver is not running, skipping installed packages report."
63 nodpkg="$nodpkg|$vserver"
68 if [ ! -x "`which dpkg`" ]; then
69 warning "can't find dpkg, skipping installed packages report."
75 if [ "$partitions" == "yes" ]; then
76 if [ ! -x "$SFDISK" ]; then
77 warning "can't find sfdisk, skipping partition report."
80 if [ ! -x "$HWINFO" ]; then
81 warning "can't find hwinfo, skipping partition report."
86 if [ "$hardware" == "yes" ]; then
87 if [ ! -x "$HWINFO" ]; then
88 warning "can't find hwinfo, skipping hardware report."
93 ## PACKAGES ##############################
96 # here we grab a list of the packages installed and removed.
99 if [ "$packages" == "yes" ]; then
102 for vserver in `ls $VROOTDIR | grep -E -v $nodpkg`
104 debug "$VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile"
105 $VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile
109 # We want to perform this on the host as well
110 if [ "$packages" == "yes" ]; then
111 debug "dpkg --get-selections > $packagesfile"
112 dpkg --get-selections > $packagesfile
116 ## PARTITIONS #############################
118 # here we use sfdisk to dump a listing of all the partitions.
119 # these files can be used to directly partition a disk of the same size.
121 if [ "$partitions" == "yes" ]; then
122 devices=`$HWINFO --disk | grep "Device File" | cut -d\ -f5`
123 for dev in $devices; do
124 [ -b $dev ] || continue
127 outputfile=${partitionsfile//__star__/$label}
128 debug "$SFDISK $sfdisk_options -d $dev > $outputfile"
129 $SFDISK $sfdisk_options -d $dev > $outputfile
133 ## HARDWARE #############################
136 # here we use hwinfo to dump a table listing all the
137 # information we can find on the hardware of this machine
140 if [ "$hardware" == "yes" ]; then
141 if [ -f $hardwarefile ]; then
145 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
146 debug "$HWINFO --short --cpu --network --disk --pci >> $hardwarefile"
147 $HWINFO --short --cpu --network --disk --pci >> $hardwarefile
148 for flag in cpu network disk bios pci; do
149 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
150 $HWINFO --$flag >> $hardwarefile