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 # a simple report is generated of the kernel modules, the devices,
18 # and the model of the hardware which 'discover' is able to detect.
21 getconf packagesfile /var/backups/dpkg-selections.txt
23 getconf partitions yes
24 getconf partitionsfile /var/backups/partitions.*.txt
27 getconf hardwarefile /var/backups/hardware.txt
29 if [ "$packages" == "yes" ]; then
30 if [ ! -x "`which dpkg`" ]; then
31 warning "can't find dpkg, skipping installed packages report."
36 if [ "$partitions" == "yes" ]; then
37 if [ ! -x "`which sfdisk`" ]; then
38 warning "can't find sfdisk, skipping partition report."
43 if [ "$hardware" == "yes" ]; then
44 if [ ! -x "`which discover`" ]; then
45 warning "can't find discover, skipping hardware report."
50 ## PACKAGES ##############################
53 # here we grab a list of the packages installed and removed.
56 if [ "$packages" == "yes" ]; then
57 dpkg --get-selections > $packagesfile
60 ## PARTITIONS #############################
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.
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]//'`
71 devices=`echo $devices | sort | uniq`
72 for dev in $devices; do
73 # remove leading /dev/
74 label=${devices#/dev/}
75 # replace any remaining '/'
77 outputfile=${partitionsfile//__star__/$label}
78 sfdisk -d $dev > $outputfile
82 ## HARDWARE #############################
85 # here we use discover to dump a table listing all the
86 # information we can find on the hardware of this machine
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
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