now we use hwinfo which is soooo much better than discover for this.
[matthijs/upstream/backupninja.git] / handlers / sys
1 #
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.
4 #
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
8
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!!!)
15 #
16 # (3) hardware information. 
17 #     write to a text file the important things which hwinfo can discover.
18 #
19
20 getconf packages yes
21 getconf packagesfile /var/backups/dpkg-selections.txt
22
23 getconf partitions yes
24 getconf partitionsfile '/var/backups/partitions.*.txt'
25
26 getconf hardware yes
27 getconf hardwarefile /var/backups/hardware.txt
28
29 if [ "$packages" == "yes" ]; then
30         if [ ! -x "`which dpkg`" ]; then
31                 warning "can't find dpkg, skipping installed packages report."
32                 packages="no"
33         fi
34 fi
35
36 if [ "$partitions" == "yes" ]; then
37         if [ ! -x "`which sfdisk`" ]; then
38                 warning "can't find sfdisk, skipping partition report."
39                 partitions="no"
40         fi
41         if [ ! -x "`which hwinfo`" ]; then
42                 warning "can't find hwinfo, skipping partition report."
43                 partitions="no"
44         fi
45 fi
46
47 if [ "$hardware" == "yes" ]; then
48         if [ ! -x "`which hwinfo`" ]; then
49                 warning "can't find hwinfo, skipping hardware report."
50                 hardware="no"
51         fi
52 fi
53
54 ## PACKAGES ##############################
55
56 #
57 # here we grab a list of the packages installed and removed.
58 #
59
60 if [ "$packages" == "yes" ]; then
61         dpkg --get-selections > $packagesfile
62 fi
63
64 ## PARTITIONS #############################
65
66 # here we use sfdisk to dump a listing of all the partitions. 
67 # these files can be used to directly partition a disk of the same size.
68
69 if [ "$partitions" == "yes" ]; then
70         devices=`hwinfo --disk | grep "Device File" | cut -d\  -f5`
71         for dev in $devices; do
72                 [ -b $dev ] || continue
73                 label=${dev#/dev/}
74                 label=${label//\//-}
75                 outputfile=${partitionsfile//__star__/$label}
76                 debug "sfdisk -d $dev > $outputfile"
77                 sfdisk -d $dev > $outputfile
78         done
79 fi
80
81 ## HARDWARE #############################
82
83 #
84 # here we use hwinfo to dump a table listing all the
85 # information we can find on the hardware of this machine
86
87
88 if [ "$hardware" == "yes" ]; then
89         if [ -f $hardwarefile ]; then
90                 rm $hardwarefile
91         fi
92         touch $hardwarefile
93         echo -e "\n\n====================== summary ======================\n" >>  $hardwarefile
94         hwinfo --short --cpu --network --disk --pci  >> $hardwarefile
95         for flag in cpu network disk bios pci; do
96                 echo -e "\n\n====================== $flag ======================\n" >>  $hardwarefile
97                 hwinfo --$flag >> $hardwarefile
98         done
99 fi