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 # See if vservers are configured
30 if [ "$VSERVERS" = "yes" ]
34 fatal "vservers enabled, but $VROOTDIR does not exist!"
36 info "vserver method enabled"
41 if [ "$packages" == "yes" ]; then
44 for vserver in `ls $VROOTDIR |grep -v lost+found`
46 running=`vserver-info $vserver RUNNING`
47 if [ $running = 1]; then
48 if [ ! -x "`$VSERVER $vserver exec which dpkg`" ]; then
49 warning "can't find dpkg in vserver $vserver, skipping installed packages report."
50 nodpkg="$nodpkg $vserver"
53 warning "vserver $vserver is not running, skipping installed packages report."
54 nodpkg="$nodpkg $vserver"
59 if [ ! -x "`which dpkg`" ]; then
60 warning "can't find dpkg, skipping installed packages report."
66 if [ "$partitions" == "yes" ]; then
67 if [ ! -x "`which sfdisk`" ]; then
68 warning "can't find sfdisk, skipping partition report."
71 if [ ! -x "`which hwinfo`" ]; then
72 warning "can't find hwinfo, skipping partition report."
77 if [ "$hardware" == "yes" ]; then
78 if [ ! -x "`which hwinfo`" ]; then
79 warning "can't find hwinfo, skipping hardware report."
84 ## PACKAGES ##############################
87 # here we grab a list of the packages installed and removed.
92 for vserver in `ls $VROOTDIR | grep -v $nodpkg | grep -v lost+found`
94 debug "$VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile"
95 $VSERVER $vserver exec dpkg --get-selections > $VROOTDIR/$vserver$packagesfile
99 # We want to perform this on the host as well
100 if [ "$packages" == "yes" ]; then
101 debug "dpkg --get-selections > $packagesfile"
102 dpkg --get-selections > $packagesfile
106 ## PARTITIONS #############################
108 # here we use sfdisk to dump a listing of all the partitions.
109 # these files can be used to directly partition a disk of the same size.
111 if [ "$partitions" == "yes" ]; then
112 devices=`hwinfo --disk | grep "Device File" | cut -d\ -f5`
113 for dev in $devices; do
114 [ -b $dev ] || continue
117 outputfile=${partitionsfile//__star__/$label}
118 debug "sfdisk -d $dev > $outputfile"
119 sfdisk -d $dev > $outputfile
123 ## HARDWARE #############################
126 # here we use hwinfo to dump a table listing all the
127 # information we can find on the hardware of this machine
130 if [ "$hardware" == "yes" ]; then
131 if [ -f $hardwarefile ]; then
135 echo -e "\n\n====================== summary ======================\n" >> $hardwarefile
136 debug "hwinfo --short --cpu --network --disk --pci >> $hardwarefile"
137 hwinfo --short --cpu --network --disk --pci >> $hardwarefile
138 for flag in cpu network disk bios pci; do
139 echo -e "\n\n====================== $flag ======================\n" >> $hardwarefile
140 hwinfo --$flag >> $hardwarefile