version 0.4.1
[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 #     a simple report is generated of the kernel modules, the devices,
18 #     and the model of the hardware which 'discover' is able to detect.
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 fi
42
43 if [ "$hardware" == "yes" ]; then
44         if [ ! -x "`which discover`" ]; then
45                 warning "can't find discover, skipping hardware report."
46                 hardware="no"
47         fi
48 fi
49
50 ## PACKAGES ##############################
51
52 #
53 # here we grab a list of the packages installed and removed.
54 #
55
56 if [ "$packages" == "yes" ]; then
57         dpkg --get-selections > $packagesfile
58 fi
59
60 ## PARTITIONS #############################
61
62 #
63 # here we use sfdisk to dump a listing of all the partitions. 
64 # these files can be used to directly partition a disk of the same size.
65 #
66
67 if [ "$partitions" == "yes" ]; then
68         for i in `sfdisk -l | grep "^/dev/" | awk '{print $1}'`; do
69                 devices=`echo $i | sed 's/[0-9]//'`
70         done
71         devices=`echo $devices | sort | uniq`
72         for dev in $devices; do
73                 # remove leading /dev/
74                 label=${devices#/dev/}
75                 # replace any remaining '/'
76                 label=${label//\//-}
77                 outputfile=${partitionsfile//__star__/$label}
78                 sfdisk -d $dev > $outputfile
79         done
80 fi
81
82 ## HARDWARE #############################
83
84 #
85 # here we use discover to dump a table listing all the
86 # information we can find on the hardware of this machine
87
88
89 if [ "$hardware" == "yes" ]; then
90         printf "%15s%15s    %s / %s\n" "kernel module" "device" "vender" "model" > $hardwarefile
91         printf "%15s%15s    %s / %s\n\n" "=============" "======" "======" "=====" >> $hardwarefile
92         oldifs=$IFS
93         IFS=$'\t\n'
94         discover --format="'%m'\t'%d'\t'%V'\t'%M'\n" all | \
95                 while read module device vender model
96                 do printf "%15s%15s    %s / %s\n" "${module//\'/}" "${device//\'/}" "${vender//\'/}" "${model//\'/}" >> $hardwarefile
97                 done
98         IFS=$oldifs
99 fi