Skip to content

Commit

Permalink
add additional sys backup options to provide the ability to backup th…
Browse files Browse the repository at this point in the history
…e MBR for every device found, and to backup the BIOS (if the flashrom program is installed, and the mainboard is supported)
  • Loading branch information
micah committed Sep 20, 2013
1 parent 373c6bc commit 54ec07b
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/example.sys
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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)
6 changes: 6 additions & 0 deletions handlers/sys.helper.in
Original file line number Diff line number Diff line change
Expand Up @@ -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";;
Expand All @@ -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
Expand All @@ -38,6 +42,8 @@ $sfdisk
$hardware
$luksheaders
$lvm
$mbr
$bios
# packagesfile = /var/backups/dpkg-selections.txt
# selectionsfile = /var/backups/debconfsel.txt
Expand Down
60 changes: 60 additions & 0 deletions handlers/sys.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 ##############################

#
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 54ec07b

Please sign in to comment.