tar: Support running on multiple backends.
[matthijs/upstream/backupninja.git] / handlers / sys.in
1 # -*- mode: sh; sh-basic-offset: 3; indent-tabs-mode: nil; -*-
2 # vim: set filetype=sh sw=3 sts=3 expandtab autoindent:
3 #
4 # this handler will save various reports of vital system information.
5 # by default, all the reports are saved in /var/backups.
6 #
7 # (1) a capture of the debconf package selection states. This file
8 #     can be used to restore the answers to debconf questions for
9 #     packages that you will be installing through (2) below. To
10 #     do this, run: "debconf-set-selections < debconfsel.txt"
11 #
12 # (2) a list of all the packages installed and removed.
13 #     this file can be used to restore the state of installed packages
14 #     by running "dpkg --set-selections < dpkg-selections.txt and
15 #     then run "apt-get -u dselect-upgrade". If you have the
16 #     debconf-set-selections file from (1), you should restore those first.
17 #
18 # (3) the partition table of all disks.
19 #     this partition table can be used to format another disk of
20 #     the same size. this can be handy if using software raid and
21 #     you have a disk go bad. just replace the disk and partition it
22 #     by running "sfdisk /dev/sdb < partitions.sdb.txt"
23 #     (MAKE SURE YOU PARTITION THE CORRECT DISK!!!)
24 #
25 # (4) hardware information.
26 #     write to a text file the important things which hwinfo can gleen.
27 #
28 # (5) the Luks header of every Luks block device, if option luksheaders
29 #     is enabled.
30 #     in case you (have to) scramble such a Luks header (for some time),
31 #     and restore it later by running "dd if=luksheader.sda2.bin of=/dev/sda2"
32 #     (MAKE SURE YOU PASS THE CORRECT DEVICE AS of= !!!)
33 #
34 # (6) LVM metadata for every detected volume group, if "lvm = yes"
35 #
36
37 if [ -f /etc/debian_version ]
38 then
39    os=debian
40    debug "Debian detected"
41    osversion="/etc/debian_version"
42 elif [ -f /etc/redhat-release ]
43 then
44    os=redhat
45    debug "Redhat detected"
46    osversion="/etc/redhat-release"
47 else
48    warning "Unknown OS detected!"
49 fi
50
51 getconf parentdir /var/backups
52 getconf packages yes
53 getconf dosfdisk yes
54 getconf dohwinfo yes
55
56 if [ ! -d $parentdir ]; then
57    mkdir -p $parentdir
58 fi
59
60 if [ $os = "debian" ]
61 then
62    getconf packagesfile $parentdir/dpkg-selections.txt
63    getconf packagemgr   `which dpkg`
64    getconf packagemgroptions ' --get-selections *'
65    getconf selectionsfile $parentdir/debconfsel.txt
66    getconf debconfgetselections `which debconf-get-selections`
67 elif [ $os = "redhat" ]
68 then
69    getconf packagesfile  $parentdir/rpmpackages.txt
70    getconf packagemgr   `which rpm`
71    getconf packagemgroptions   ' -qa '
72
73    getconf SYSREPORT `which sysreport`
74    getconf sysreport_options ' -norpm '
75 else
76    getconf packagesfile $parentdir/unknownOS.txt
77 fi
78 packagemgroptions="${packagemgroptions//__star__/*}"
79
80 getconf partitions yes
81 getconf partitionsfile $parentdir/partitions.__star__.txt
82
83 getconf hardware yes
84 getconf hardwarefile $parentdir/hardware.txt
85
86 getconf sysreport yes
87 getconf sysreportfile $parentdir/sysreport.txt
88
89 getconf SFDISK `which sfdisk`
90 getconf HWINFO `which hwinfo`
91 getconf sfdisk_options ""
92 getconf hwinfo_options ""
93
94 getconf CRYPTSETUP `which cryptsetup`
95 getconf DD `which dd`
96 getconf luksheaders no
97 getconf luksheadersfile $parentdir/luksheader.__star__.bin
98
99 getconf VGS `which vgs`
100 getconf VGCFGBACKUP `which vgcfgbackup`
101 getconf lvm no
102
103 getconf vsnames all
104
105 # If vservers are configured, check that the ones listed in $vsnames are running.
106 local usevserver=no
107 if [ $vservers_are_available = yes ]; then
108    if [ "$vsnames" = all ]; then
109       vsnames="$found_vservers"
110    fi
111    if ! vservers_running "$vsnames" ; then
112       fatal "At least one of the vservers listed in vsnames ($vsnames) is not running."
113    fi
114    info "Using vservers '$vsnames'"
115    usevserver=yes
116 fi
117
118 ## SANITY CHECKS #########################
119
120 if [ "$luksheaders" == "yes" ]; then
121    if [ ! -x "$DD" ]; then
122       warning "can't find dd, skipping backup of Luks headers."
123       luksheaders="no"
124    fi
125    if [ ! -x "$CRYPTSETUP" ]; then
126       warning "can't find cryptsetup, skipping backup of Luks headers."
127       luksheaders="no"
128    fi
129 fi
130
131 if [ "$lvm" == "yes" ]; then
132    if [ ! -x "$VGS" ]; then
133       warning "can't find vgs, skipping backup of LVM metadata"
134       lvm="no"
135    fi
136    if [ ! -x "$VGCFGBACKUP" ]; then
137       warning "can't find vgcfgbackup, skipping backup of LVM metadata"
138       lvm="no"
139    fi
140 fi
141
142 ## PACKAGES ##############################
143
144 #
145 # here we grab a list of the packages installed and removed.
146 #
147
148 if [ "$packages" == "yes" ]; then
149
150    if [ $usevserver = yes ]; then
151       info "vserver root directory set to: $VROOTDIR"
152       for vserver in $vsnames; do
153          info "examining vserver: $vserver"
154          # is it running ?
155          vservers_running $vserver
156          if [ $? -ne 0 ]; then
157             warning "The vserver $vserver is not running."
158             continue
159          fi
160          # is $packagemgr available inside $vserver ?
161          if [ ! -x "${VROOTDIR}/${vserver}${packagemgr}" ]; then
162             warning "can't find $packagemgr in vserver $vserver, skipping installed packages report."
163          else
164             # don't expand * since it can be used in $packagemgroptions
165             set -o noglob
166             debug "$VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile"
167        $VSERVER $vserver exec $packagemgr $packagemgroptions > $VROOTDIR/$vserver$packagesfile || fatal "can not save $packagemgr info to $packagesfile"
168             set +o noglob
169          fi
170          # is $debconfgetselections available inside $vserver ?
171          found=no
172          # case #1: it is available on the host, is it available inside $vserver ?
173          if [ -n "$debconfgetselections" ]; then
174             [ -x "${VROOTDIR}/${vserver}${debconfgetselections}" ] && found=yes
175          # case #2: it is not available on the host, is it available inside $vserver ?
176          else
177             [ -n "`$VSERVER $vserver exec which debconf-get-selections`" ] && found=yes
178          fi
179          if [ "$found" != yes ]; then
180             warning "can't find debconf-get-selections in vserver $vserver, skipping package selection states. You may want to install the debconf-utils package."
181          else
182             debug "$VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile"
183             $VSERVER $vserver exec $debconfgetselections > $VROOTDIR/$vserver$selectionsfile || fatal "can not save debconf-get-selections info to $selectionsfile"
184          fi
185          unset found
186       done
187    fi
188
189    # We want to perform this on the host as well
190    if [ -z "$packagemgr" -o ! -x "$packagemgr" ]; then
191       warning "can't find ${packagemgr}, skipping installed packages report."
192    else
193       # don't expand * since it can be used in $packagemgroptions
194       set -o noglob
195       debug "$packagemgr $packagemgroptions > $packagesfile"
196       $packagemgr $packagemgroptions > $packagesfile || fatal "can not save $packagemgr info to $packagesfile"
197       set +o noglob
198    fi
199    if [ -z "$debconfgetselections" ]; then
200       warning "can't find debconf-get-selections, skipping package selection states. You might want to install the debconf-utils package."
201    else
202       debug "$debconfgetselections > $selectionsfile"
203       $debconfgetselections > $selectionsfile || fatal "can not save $debconfgetselections info to $selectionsfile"
204    fi
205 fi
206
207 ## System report ##############################
208
209 #
210 # here we grab a bunch of system stuff for a report
211 #
212
213 export STATUS
214
215 HASHES="#################################################################"
216 DASHES="-----------------------------------------------------------------"
217
218 cat /dev/null > $sysreportfile || fatal "can not write to $sysreportfile"
219
220
221 catiffile () {
222    echo $HASHES >> $sysreportfile
223    echo "# $STATUS" >> $sysreportfile
224    echo $HASHES >> $sysreportfile
225    if [ -f $1 ]; then
226       echo "file: $1" >> $sysreportfile
227       echo $DASHES >> $sysreportfile
228       cat $1 >> $sysreportfile 2>&1 || info "reading of $1 failed"
229    fi
230    if [ -d $1 ]; then
231       echo "directory: $1" >> $sysreportfile
232       echo $DASHES >> $sysreportfile
233       for file in `find $1 -maxdepth 3 -noleaf -type f`
234       do
235        catiffile $file
236       done
237    fi
238    echo $DASHES >> $sysreportfile
239 }
240
241 catifexec () {
242    if [ -x $1 ]; then
243       echo $HASHES >> $sysreportfile
244       echo "# $STATUS" >> $sysreportfile
245       echo $HASHES >> $sysreportfile
246       $*  >> $sysreportfile 2>&1 || info "executing of $1 failed"
247    fi
248 }
249
250
251 STATUS="Determining $os version:"
252 catiffile $osversion
253
254 STATUS="Determinding your current hostname: "
255 catifexec "/bin/hostname"
256
257 STATUS="Getting the date:"
258 catifexec "/bin/date"
259
260 STATUS="Checking your systems current uptime and load average:"
261 catifexec "/usr/bin/uptime"
262
263 STATUS="Checking available memory:"
264 catifexec "/usr/bin/free"
265
266 STATUS="Checking free disk space:"
267 catifexec "/bin/df" "-al"
268
269 STATUS="Collecting what services run at what run level:"
270 if [ $os = "redhat" ]; then
271    catifexec "/sbin/chkconfig" "--list"
272    STATUS="Collecting information about /etc/rc.d:"
273    catiffile "/bin/ls /etc/rc.d/rc*.d/"
274
275 elif [ $os = "debian" ]; then
276    for level in 0 1 2 3 4 5 6 S; do
277       echo "Level: $level" >> $sysreportfile
278       for f in /etc/rc${level}.d/*; do
279          # Remove /etc/Knn or Snn from beginning
280          ff=$(echo $f | @SED@ 's_/etc/rc..d/[KS][0-9][0-9]__')
281          if [ $f != $ff ]; then
282             echo $ff >> $sysreportfile
283          fi
284       done
285       echo "" >> $sysreportfile
286    done
287 fi
288
289 STATUS="Getting bootloader information:"
290 catifexec "/bin/ls" "-alR /boot"
291
292 # This covers sparc, alpha, and intel (respectively)
293 # updated for grub -mpg
294 if [ -f /etc/silo.conf ]; then
295    STATUS="Collecting information about the boot process (silo):"
296    catiffile "/etc/silo.conf"
297 fi
298 if [ -f /etc/milo.conf ]; then
299    STATUS="Collecting information about the boot process (milo):"
300    catiffile "/etc/milo.conf"
301 fi
302 if [ -f /etc/lilo.conf ]; then
303    STATUS="Collecting information about the boot process (lilo):"
304    catiffile "/etc/lilo.conf"
305    catifexec "/sbin/lilo" "-q"
306 fi
307 if [ -d /boot/grub -a -f /boot/grub/grub.conf -a -f /boot/grub/device.map ]; then
308    STATUS="Collecting information about the boot process (grub.conf):"
309    catiffile "/boot/grub/grub.conf"
310    STATUS="Collecting information about the boot process (grub.map):"
311    catiffile "/boot/grub/device.map"
312 fi
313 if [ -f /etc/cluster.conf -o -f /etc/cluster.xml ] ; then
314    STATUS="Gathering information on cluster setup"
315    # 2.1 AS
316    if [ -f /etc/cluster.conf ] ; then
317       catiffile "/etc/cluster.conf"
318    fi
319    # Taroon
320    if [ -f /etc/cluster.xml ] ; then
321       catiffile "/etc/cluster.xml"
322    fi
323 fi
324
325 STATUS="Gathering sysctl information (sysctl -a):"
326 catiffile "sysctl -a 2>/dev/null"
327 STATUS="Gathering sysctl information (/etc/sysctl.conf):"
328 catiffile "/etc/sysctl.conf"
329
330 STATUS="Gathering IP information (/sbin/ifconfig):"
331 catifexec "/sbin/ifconfig" "-a"
332
333 STATUS="Gathering additional IP information (/bin/ip addr list):"
334 catifexec "/bin/ip" "addr list"
335
336 STATUS="Checking network routes:"
337 catifexec "/sbin/route" "-n"
338
339 STATUS="Collecting Name Service Switch config information:"
340 catiffile "/etc/nsswitch.conf"
341
342 STATUS="Collecting information about system authentication (pam):"
343 catiffile "/etc/pam.conf"
344 catiffile "/etc/pam.d"
345
346 echo
347 echo "Getting information about the kernel."
348 echo
349 STATUS="Getting kernel version:"
350 catifexec "/bin/uname" "-a"
351 STATUS="Checking module information:"
352 catifexec "/sbin/lsmod"
353 for x  in $(/sbin/lsmod | /bin/cut -f1 -d" " 2>/dev/null | /bin/grep -v Module 2>/dev/null
354 ) ; do
355    STATUS="Checking module information $x:"
356    catifexec "/sbin/modinfo" "$x"
357 done
358
359 STATUS="Gathering information about your filesystems:"
360 catiffile "/proc/filesystems"
361
362 STATUS="Gathering information about your system stat:"
363 catiffile "/proc/stat"
364
365 STATUS="Gathering information about your partitions:"
366 catiffile "/proc/partitions"
367
368 STATUS="Gathering information about your ksyms:"
369 catiffile "/proc/kallsyms"
370
371 STATUS="Gathering information about slabinfo:"
372 catiffile "/proc/slabinfo"
373
374 # Added support to cover for the new modules.conf layout in Red Hat 7
375 STATUS="Collecting information regarding kernel modules"
376 VER=`uname -r`
377 catiffile "/lib/modules/$VER/modules.dep"
378 if [ -f /etc/conf.modules ]; then
379    STATUS="Collecting information regarding kernel modules (conf.modules)"
380    catiffile "/etc/conf.modules"
381 fi
382 if [ -f /etc/modules.conf ]; then
383    STATUS="Collecting information regarding kernel modules (modules.conf)"
384    catiffile "/etc/modules.conf"
385 fi
386 if [ -f /etc/modprobe.conf ]; then
387    STATUS="Collecting information regarding kernel modules (modeprobe.conf)"
388    catiffile "/etc/modprobe.conf"
389 fi
390
391 # dkms status
392 if [ -x /usr/sbin/dkms ] ; then
393    STATUS="Gathering current status of modules, versions and kernels (dkms):"
394    catifexec "/usr/sbin/dkms" "status"
395 fi
396
397 if [ -f /etc/sysconfig/isdncard ] ; then
398    STATUS="Gathering information about ISDN:"
399    catiffile "/etc/sysconfig/isdncard"
400 fi
401
402 STATUS="Collecting information from the proc directory:"
403 catiffile "/proc/pci"
404
405 STATUS="Getting kernel command line"
406 catiffile "/proc/cmdline"
407
408 STATUS="Gathering information about your CPU:"
409 catiffile "/proc/cpuinfo"
410
411 STATUS="Gathering information about your Ram:"
412 catiffile "/proc/meminfo"
413
414 STATUS="Gathering information about your ioports:"
415 catiffile "/proc/ioports"
416
417 STATUS="Gathering information about your interrupts:"
418 catiffile "/proc/interrupts"
419
420 STATUS="Gathering information about your scsi devices:"
421 catiffile "/proc/scsi"
422
423 STATUS="Gathering information about your dma:"
424 catiffile "/proc/dma"
425
426 STATUS="Gathering information about your devices (/proc/devices):"
427 catiffile "/proc/devices"
428
429 STATUS="Gathering information about your rtc:"
430 catiffile "/proc/rtc"
431
432 STATUS="Gathering information about your ide drivers:"
433 catiffile "/proc/ide"
434
435 STATUS="Gathering information about your bus:"
436 catifexec "/usr/bin/lspci"
437 catiffile "/proc/bus"
438
439 echo
440 echo "Getting disk and filesystem information."
441 echo
442
443 STATUS="Collecting information from /etc/fstab:"
444 catiffile "/etc/fstab"
445
446 STATUS="Collecting disk partition information:"
447 catifexec "/sbin/fdisk" "-l"
448
449 STATUS="Checking mounted file systems (mount) "
450 catifexec "/bin/mount"
451
452 STATUS="Checking mounted file systems (/proc/mounts)"
453 catiffile "/proc/mounts"
454
455 STATUS="Collecting Software RAID information (/proc/mdstat)"
456 catiffile "/proc/mdstat"
457
458 STATUS="Collecting Software RAID information (/etc/raidtab)"
459 catiffile "/etc/raidtab"
460
461 STATUS="Collecting Software RAID information (/etc/mdadm.conf)"
462 catiffile "/etc/mdadm.conf"
463
464 STATUS="Collecting Software RAID information (/sbin/mdadm -Q)"
465 if ls /dev/md?* >/dev/null 2>&1; then
466    catifexec "/sbin/mdadm" "-Q" "--detail" '/dev/md?*'
467 fi
468
469 STATUS="Collecting Automount information (auto.master)"
470 catiffile "/etc/auto.master"
471
472 STATUS="Collecting Automount information (auto.misc)"
473 catiffile "/etc/auto.misc"
474
475 STATUS="Collecting Automount information (auto.net)"
476 catiffile "/etc/auto.net"
477
478 STATUS="Collecting LVM information:"
479 if [ $os = "redhat" ]; then
480    catifexec "/usr/sbin/vgdisplay" "-vv"
481 elif [ $os = "debian" ]; then
482    catifexec "/sbin/vgdisplay" "-vv"
483 fi
484
485 STATUS="Collecting device-mapper (dm) information:"
486 catifexec '/sbin/dmsetup' 'info'
487
488 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
489 catiffile "/etc/stinit.def"
490
491 if [ -x /sbin/lsusb ] ; then
492    STATUS="Collecting USB devices list (lsusb):"
493    catifexec "/sbin/lsusb"
494 fi
495
496 if [ -x /usr/bin/lshal ] ; then
497    STATUS="Collecting global devices list (lshal):"
498    catifexec "/usr/bin/lshal"
499 fi
500
501
502 STATUS="Gathering information on SELinux setup"
503 catifexec "/usr/bin/selinuxconfig"
504 catifexec "/usr/sbin/sestatus"
505 if [ $os = "redhat" ]; then
506    catifexec "rpm" "-q -V selinux-policy-targeted"
507    catifexec "rpm" "-q -V selinux-policy-strict"
508 fi
509
510 if [ $usevserver = yes ]; then
511    STATUS="Gathering vserver information"
512    catiffile "/proc/virtual"
513 fi
514
515 if [ "$partitions" == "yes" ]; then
516    if [ "$dosfdisk" == "yes" ]; then
517       if [ ! -x "$SFDISK" ]; then
518     warning "can't find sfdisk, skipping sfdisk report."
519     partitions="no"
520       fi
521    fi
522    if [ "$dohwinfo" == "yes" ]; then
523       if [ ! -x "$HWINFO" ]; then
524     warning "can't find hwinfo, skipping partition report."
525     partitions="no"
526       fi
527    fi
528 fi
529
530 if [ "$hardware" == "yes" ]; then
531    if [ ! -x "$HWINFO" ]; then
532       warning "can't find hwinfo, skipping hardware report."
533       hardware="no"
534    fi
535 fi
536
537 ## HARDWARE #############################
538
539 #
540 # here we use hwinfo to dump a table listing all the
541 # information we can find on the hardware of this machine
542 #
543
544 if [ "$hardware" == "yes" ]; then
545    if [ "dohwinfo" == "yes" ]; then
546       if [ -f $hardwarefile ]; then
547     rm $hardwarefile
548       fi
549       touch $hardwarefile
550       echo -e "\n\n====================== summary ======================\n" >>  $hardwarefile
551       debug "$HWINFO --short --cpu --network --disk --pci  >> $hardwarefile"
552       $HWINFO --short --cpu --network --disk --pci  >> $hardwarefile
553       for flag in cpu network bios pci; do
554     echo -e "\n\n====================== $flag ======================\n" >>  $hardwarefile
555     $HWINFO --$flag >> $hardwarefile
556       done
557    fi
558 fi
559
560 ## PARTITIONS #############################
561
562 # here we use sfdisk to dump a listing of all the partitions.
563 # these files can be used to directly partition a disk of the same size.
564
565 if [ "$partitions" == "yes" ]; then
566    if [ "$dosfdisk" == "yes" ]; then
567       devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
568    if [ "$devices" == "" ]; then
569       warning "No harddisks found"
570    fi
571    for dev in $devices; do
572       debug "$SFDISK will try to backup partition tables for device $dev"
573       [ -b $dev ] || continue
574       label=${dev#/dev/}
575       label=${label//\//-}
576       outputfile=${partitionsfile//__star__/$label}
577       debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
578       $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
579       if [ $? -ne 0 ]; then
580          warning "The partition table for $dev could not be saved."
581       fi
582    done
583    fi
584    if [ "$dohwinfo" == "yes" ]; then
585       debug "Using $HWINFO to get all available disk information"
586       echo -e "\n\n====================== $disk ======================\n" >>  $hardwarefile
587       $HWINFO --disk >> $hardwarefile
588    fi
589 fi
590
591 if [ "$luksheaders" == "yes" ]; then
592    devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
593    [ -n "$devices" ] || warning "No block device found"
594    targetdevices=""
595    for dev in $devices; do
596       [ -b $dev ] || continue
597       debug "$CRYPTSETUP isLuks $dev"
598       $CRYPTSETUP isLuks $dev
599       [ $? -eq 0 ] && targetdevices="$targetdevices $dev"
600    done
601    for dev in $targetdevices; do
602       label=${dev#/dev/}
603       label=${label//\//-}
604       outputfile=${luksheadersfile//__star__/$label}
605       # the following sizes are expressed in terms of 512-byte sectors
606       debug "Let us find out the Luks header size for $dev"
607       debug "$CRYPTSETUP luksDump \"$dev\" | grep '^Payload offset:' | @AWK@ '{print $3}'"
608       headersize=`$CRYPTSETUP luksDump "$dev" | grep '^Payload offset:' | @AWK@ '{print $3}'`
609       if [ $? -ne 0 ]; then
610          warning "Could not compute the size of Luks header, skipping device $dev"
611          continue
612       elif [ -z "$headersize" -o -n "`echo \"$headersize\" | sed 's/[0-9]*//g'`" ]; then
613          warning "The computed size of Luks header is not an integer, skipping device $dev"
614          continue
615       fi
616       debug "Let us backup the Luks header of device $dev"
617       debug "$DD if=\"${dev}\" of=\"${outputfile}\" bs=512 count=\"${headersize}\""
618       output=`$DD if="${dev}" of="${outputfile}" bs=512 count="${headersize}" 2>&1`
619       exit_code=$?
620       if [ $exit_code -eq 0 ]; then
621          debug $output
622          info "The Luks header of $dev was saved to $outputfile."
623       else
624          debug $output
625          fatal "The Luks header of $dev could not be saved."
626       fi
627    done
628 fi
629
630 ## LVM ####################################
631
632 # returns 0 on success, 1 on error, 2 if not tried
633 # outputs error message if error, reason if not tried
634 function doLvmBackup () {
635    local lvmdir="$1"
636    if [ ! -d "$lvmdir" ]; then
637       if ! mkdir "$lvmdir"; then
638          echo "could not create $lvmdir"
639          return 2
640       else
641          info "successfully created $lvmdir"
642       fi
643    fi
644    if [ ! -w "$lvmdir" ]; then
645       echo "can not write to directory $lvmdir"
646       return 2
647    fi
648    debug "Let's try to gather the list of LVM volume groups"
649    debug "$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '"
650    vgs=`$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '`
651    debug "Let's try to backup LVM metadata for detected volume groups: $vgs"
652    debug "$VGCFGBACKUP --file \"${lvmdir}\"/\'%s\' $vgs"
653    output=`$VGCFGBACKUP --file "${lvmdir}"/'%s' $vgs`
654    exit_code=$?
655    debug $output
656    case $exit_code in
657       0)
658          info "LVM metadata was saved to $lvmdir for volume groups: $vgs"
659          return 0
660          ;;
661       *)
662          echo "LVM metadata could not be saved for at least one of these volume groups: $vgs"
663          return 1
664          ;;
665    esac
666 }
667
668 if [ "$lvm" == "yes" ]; then
669    output=`doLvmBackup "${parentdir}/lvm"`
670    exit_code=$?
671    case $exit_code in
672       0) # success. info message has already been displayed
673          true
674          ;;
675       1) # error
676          fatal "$output"
677          ;;
678       2) # could not even try
679          fatal "LVM metadata backup was not tried: $output"
680          ;;
681       *) # should never happen
682          fatal "Unhandled error ($exit_code) while trying to backup LVM metadata, please report a bug"
683          ;;
684    esac
685 fi