X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;ds=sidebyside;f=handlers%2Fsys.in;h=e6cb273a86cbe6cd03e2b0c100d7fd8292f5365b;hb=386c4275946520bc590428e730a9d515155436a0;hp=de81435463d01e4b44e2bdb051aaee483fab59cb;hpb=36854a51d46e4e63a663fe3e5fa1c68385984b78;p=matthijs%2Fupstream%2Fbackupninja.git diff --git a/handlers/sys.in b/handlers/sys.in index de81435..e6cb273 100755 --- a/handlers/sys.in +++ b/handlers/sys.in @@ -30,6 +30,8 @@ # and restore it later by running "dd if=luksheader.sda2.bin of=/dev/sda2" # (MAKE SURE YOU PASS THE CORRECT DEVICE AS of= !!!) # +# (6) LVM metadata for every detected volume group, if "lvm = yes" +# if [ -f /etc/debian_version ] then @@ -93,6 +95,10 @@ getconf DD `which dd` getconf luksheaders no getconf luksheadersfile $parentdir/luksheader.__star__.bin +getconf VGS `which vgs` +getconf VGCFGBACKUP `which vgcfgbackup` +getconf lvm no + getconf vsnames all # If vservers are configured, check that the ones listed in $vsnames are running. @@ -121,6 +127,17 @@ if [ "$luksheaders" == "yes" ]; then fi fi +if [ "$lvm" == "yes" ]; then + if [ ! -x "$VGS" ]; then + warning "can't find vgs, skipping backup of LVM metadata" + lvm="no" + fi + if [ ! -x "$VGCFGBACKUP" ]; then + warning "can't find vgcfgbackup, skipping backup of LVM metadata" + lvm="no" + fi +fi + ## PACKAGES ############################## # @@ -461,6 +478,9 @@ if [ $os = "redhat" ]; then elif [ $os = "debian" ]; then catifexec "/sbin/vgdisplay" "-vv" fi + +STATUS="Collecting device-mapper (dm) information:" +catifexec '/sbin/dmsetup' 'info' STATUS="Collecting SCSI Tape information (/etc/stinit.def)" catiffile "/etc/stinit.def" @@ -534,7 +554,6 @@ if [ "$hardware" == "yes" ]; then fi fi - ## PARTITIONS ############################# # here we use sfdisk to dump a listing of all the partitions. @@ -604,3 +623,60 @@ if [ "$luksheaders" == "yes" ]; then fi done fi + +## LVM #################################### + +# returns 0 on success, 1 on error, 2 if not tried +# outputs error message if error, reason if not tried +function doLvmBackup () { + local lvmdir="$1" + if [ ! -d "$lvmdir" ]; then + if ! mkdir "$lvmdir"; then + echo "could not create $lvmdir" + return 2 + else + info "successfully created $lvmdir" + fi + fi + if [ ! -w "$lvmdir" ]; then + echo "can not write to directory $lvmdir" + return 2 + fi + debug "Let's try to gather the list of LVM volume groups" + debug "$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '" + vgs=`$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '` + debug "Let's try to backup LVM metadata for detected volume groups: $vgs" + debug "$VGCFGBACKUP --file \"${lvmdir}\"/\'%s\' $vgs" + output=`$VGCFGBACKUP --file "${lvmdir}"/'%s' $vgs` + exit_code=$? + debug $output + case $exit_code in + 0) + info "LVM metadata was saved to $lvmdir for volume groups: $vgs" + return 0 + ;; + *) + echo "LVM metadata could not be saved for at least one of these volume groups: $vgs" + return 1 + ;; + esac +} + +if [ "$lvm" == "yes" ]; then + output=`doLvmBackup "${parentdir}/lvm"` + exit_code=$? + case $exit_code in + 0) # success. info message has already been displayed + true + ;; + 1) # error + fatal "$output" + ;; + 2) # could not even try + fatal "LVM metadata backup was not tried: $output" + ;; + *) # should never happen + fatal "Unhandled error ($exit_code) while trying to backup LVM metadata, please report a bug" + ;; + esac +fi