diff options
-rw-r--r-- | examples/example.sys | 15 | ||||
-rw-r--r-- | handlers/sys.helper.in | 6 | ||||
-rw-r--r-- | handlers/sys.in | 60 |
3 files changed, 81 insertions, 0 deletions
diff --git a/examples/example.sys b/examples/example.sys index fe34646..39d70bd 100644 --- a/examples/example.sys +++ b/examples/example.sys @@ -33,6 +33,15 @@ # # (6) LVM metadata for every detected volume group, if "lvm = yes" # +# (7) a copy of each device's MBR, if "mbr = yes". A master boot record +# (MBR) is the 512-byte boot sector that is the first sector of a +# partitioned data storage device of a hard disk. To restore the MBR +# one could do something like: dd if=sda.mbr of=/dev/sda +# (MAKE SURE YOU PASS THE CORRECT DEVICE AS of= !!!) +# WARNING: Restoring the MBR with a mismatching partition table will +# make your data unreadable and nearly impossible to recover +# +# (8) a copy of the BIOS, if "bios = yes" and flashrom is installed # here are the defaults, commented out: @@ -65,6 +74,12 @@ # lvm = no +# mbr = no + +# note: to backup your BIOS, you need the program 'flashrom' installed, and your +# mainboard needs to be supported, see http://flashrom.org/Supported_hardware#Supported_mainboards +# bios = no + # If vservers = yes in /etc/backupninja.conf then the following variables can # be used: # vsnames = all | <vserver1> <vserver2> ... (default = all) diff --git a/handlers/sys.helper.in b/handlers/sys.helper.in index 8a2fb07..7272f48 100644 --- a/handlers/sys.helper.in +++ b/handlers/sys.helper.in @@ -20,6 +20,8 @@ sys_wizard() { hardware="hardware = no" luksheaders="luksheaders = no" lvm="lvm = no" + mbr="mbr = no" + bios="bios = no" for opt in $result; do case $opt in '"packages"') packages="packages = yes";; @@ -28,6 +30,8 @@ sys_wizard() { '"hardware"') hardware="hardware = yes";; '"luksheaders"') luksheaders="luksheaders = yes";; '"lvm"') lvm="lvm = yes";; + '"mbr"') mbr="mbr = yes";; + '"bios"') bios="bios = yes";; esac done get_next_filename $configdirectory/10.sys @@ -38,6 +42,8 @@ $sfdisk $hardware $luksheaders $lvm +$mbr +$bios # packagesfile = /var/backups/dpkg-selections.txt # selectionsfile = /var/backups/debconfsel.txt diff --git a/handlers/sys.in b/handlers/sys.in index 9b03778..4ce18fc 100644 --- a/handlers/sys.in +++ b/handlers/sys.in @@ -33,6 +33,15 @@ # # (6) LVM metadata for every detected volume group, if "lvm = yes" # +# (7) a copy of each device's MBR, if "mbr = yes". A master boot record +# (MBR) is the 512-byte boot sector that is the first sector of a +# partitioned data storage device of a hard disk. To restore the MBR +# one could do something like: dd if=sda.mbr of=/dev/sda +# (MAKE SURE YOU PASS THE CORRECT DEVICE AS of= !!!) +# WARNING: Restoring the MBR with a mismatching partition table will +# make your data unreadable and nearly impossible to recover +# +# (8) a copy of the BIOS, if "bios = yes" and flashrom is installed if [ -f /etc/debian_version ] then @@ -100,6 +109,12 @@ getconf VGS `which vgs` getconf VGCFGBACKUP `which vgcfgbackup` getconf lvm no +getconf mbr no +getconf mbrfile $parentdir/mbr.__star__.bin + +getconf FLASHROM `which flashrom` +getconf bios no + getconf vsnames all # If vservers are configured, check that the ones listed in $vsnames are running. @@ -139,6 +154,20 @@ if [ "$lvm" == "yes" ]; then fi fi +if [ "$mbr" == "yes" ]; then + if [ ! -x "$DD" ]; then + warning "can't find dd, skipping backup of MBR." + mbr="no" + fi +fi + +if [ "$bios" == "yes" ]; then + if [ ! -x "$FLASHROM" ]; then + warning "can't find flashrom, skipping backup of BIOS." + mbr="no" + fi +fi + ## PACKAGES ############################## # @@ -633,6 +662,25 @@ if [ "$luksheaders" == "yes" ]; then done fi +if [ "$mbr" == "yes" ]; then + devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1` + if [ "$devices" == "" ]; then + warning "No harddisks found" + fi + for dev in $devices; do + debug "Will try to backup MBR tables for device $dev" + [ -b $dev ] || continue + label=${dev#/dev/} + label=${label//\//-} + outputfile=${mbrfile//__star__/$label} + debug "$DD if=$dev of=$outputfile bs=512 count=1 2>/dev/null" + $DD if=$dev of=$outputfile bs=512 count=1 2>/dev/null + if [ $? -ne 0 ]; then + warning "The MBR for $dev could not be saved." + fi + done +fi + ## LVM #################################### # returns 0 on success, 1 on error, 2 if not tried @@ -692,3 +740,15 @@ if [ "$lvm" == "yes" ]; then ;; esac fi + +## BIOS #################################### + +if [ "$bios" == "yes" ]; then + debug "Trying to backup BIOS" + debug "$FLASHROM -r ${parentdir}/bios --programmer internal >/dev/null 2>&1" + $FLASHROM -r ${parentdir}/bios --programmer internal >/dev/null 2>&1 + if [ $? -ne 0 ]; then + warning "The BIOS could not be saved." + fi +fi + |