Skip to content
Snippets Groups Projects
Commit 54ec07be authored by micah's avatar micah :speech_balloon:
Browse files

add additional sys backup options to provide the ability to backup the MBR for...

add additional sys backup options to provide the ability to backup the MBR for every device found, and to backup the BIOS (if the flashrom program is installed, and the mainboard is supported)
parent 373c6bcc
No related branches found
No related tags found
No related merge requests found
...@@ -33,6 +33,15 @@ ...@@ -33,6 +33,15 @@
# #
# (6) LVM metadata for every detected volume group, if "lvm = yes" # (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: # here are the defaults, commented out:
...@@ -65,6 +74,12 @@ ...@@ -65,6 +74,12 @@
# lvm = no # 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 # If vservers = yes in /etc/backupninja.conf then the following variables can
# be used: # be used:
# vsnames = all | <vserver1> <vserver2> ... (default = all) # vsnames = all | <vserver1> <vserver2> ... (default = all)
...@@ -20,6 +20,8 @@ sys_wizard() { ...@@ -20,6 +20,8 @@ sys_wizard() {
hardware="hardware = no" hardware="hardware = no"
luksheaders="luksheaders = no" luksheaders="luksheaders = no"
lvm="lvm = no" lvm="lvm = no"
mbr="mbr = no"
bios="bios = no"
for opt in $result; do for opt in $result; do
case $opt in case $opt in
'"packages"') packages="packages = yes";; '"packages"') packages="packages = yes";;
...@@ -28,6 +30,8 @@ sys_wizard() { ...@@ -28,6 +30,8 @@ sys_wizard() {
'"hardware"') hardware="hardware = yes";; '"hardware"') hardware="hardware = yes";;
'"luksheaders"') luksheaders="luksheaders = yes";; '"luksheaders"') luksheaders="luksheaders = yes";;
'"lvm"') lvm="lvm = yes";; '"lvm"') lvm="lvm = yes";;
'"mbr"') mbr="mbr = yes";;
'"bios"') bios="bios = yes";;
esac esac
done done
get_next_filename $configdirectory/10.sys get_next_filename $configdirectory/10.sys
...@@ -38,6 +42,8 @@ $sfdisk ...@@ -38,6 +42,8 @@ $sfdisk
$hardware $hardware
$luksheaders $luksheaders
$lvm $lvm
$mbr
$bios
# packagesfile = /var/backups/dpkg-selections.txt # packagesfile = /var/backups/dpkg-selections.txt
# selectionsfile = /var/backups/debconfsel.txt # selectionsfile = /var/backups/debconfsel.txt
......
...@@ -33,6 +33,15 @@ ...@@ -33,6 +33,15 @@
# #
# (6) LVM metadata for every detected volume group, if "lvm = yes" # (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 ] if [ -f /etc/debian_version ]
then then
...@@ -100,6 +109,12 @@ getconf VGS `which vgs` ...@@ -100,6 +109,12 @@ getconf VGS `which vgs`
getconf VGCFGBACKUP `which vgcfgbackup` getconf VGCFGBACKUP `which vgcfgbackup`
getconf lvm no getconf lvm no
getconf mbr no
getconf mbrfile $parentdir/mbr.__star__.bin
getconf FLASHROM `which flashrom`
getconf bios no
getconf vsnames all getconf vsnames all
# If vservers are configured, check that the ones listed in $vsnames are running. # If vservers are configured, check that the ones listed in $vsnames are running.
...@@ -139,6 +154,20 @@ if [ "$lvm" == "yes" ]; then ...@@ -139,6 +154,20 @@ if [ "$lvm" == "yes" ]; then
fi fi
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 ############################## ## PACKAGES ##############################
# #
...@@ -633,6 +662,25 @@ if [ "$luksheaders" == "yes" ]; then ...@@ -633,6 +662,25 @@ if [ "$luksheaders" == "yes" ]; then
done done
fi 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 #################################### ## LVM ####################################
# returns 0 on success, 1 on error, 2 if not tried # returns 0 on success, 1 on error, 2 if not tried
...@@ -692,3 +740,15 @@ if [ "$lvm" == "yes" ]; then ...@@ -692,3 +740,15 @@ if [ "$lvm" == "yes" ]; then
;; ;;
esac esac
fi 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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment