Add a vim modeline with indentation settings.
[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 catifexec "/sbin/mdadm" "-Q" "--detail" '/dev/md?*'
466
467 STATUS="Collecting Automount information (auto.master)"
468 catiffile "/etc/auto.master"
469
470 STATUS="Collecting Automount information (auto.misc)"
471 catiffile "/etc/auto.misc"
472
473 STATUS="Collecting Automount information (auto.net)"
474 catiffile "/etc/auto.net"
475
476 STATUS="Collecting LVM information:"
477 if [ $os = "redhat" ]; then
478    catifexec "/usr/sbin/vgdisplay" "-vv"
479 elif [ $os = "debian" ]; then
480    catifexec "/sbin/vgdisplay" "-vv"
481 fi
482
483 STATUS="Collecting device-mapper (dm) information:"
484 catifexec '/sbin/dmsetup' 'info'
485
486 STATUS="Collecting SCSI Tape information (/etc/stinit.def)"
487 catiffile "/etc/stinit.def"
488
489 if [ -x /sbin/lsusb ] ; then
490    STATUS="Collecting USB devices list (lsusb):"
491    catifexec "/sbin/lsusb"
492 fi
493
494 if [ -x /usr/bin/lshal ] ; then
495    STATUS="Collecting global devices list (lshal):"
496    catifexec "/usr/bin/lshal"
497 fi
498
499
500 STATUS="Gathering information on SELinux setup"
501 catifexec "/usr/bin/selinuxconfig"
502 catifexec "/usr/sbin/sestatus"
503 if [ $os = "redhat" ]; then
504    catifexec "rpm" "-q -V selinux-policy-targeted"
505    catifexec "rpm" "-q -V selinux-policy-strict"
506 fi
507
508 if [ $usevserver = yes ]; then
509    STATUS="Gathering vserver information"
510    catiffile "/proc/virtual"
511 fi
512
513 if [ "$partitions" == "yes" ]; then
514    if [ "$dosfdisk" == "yes" ]; then
515       if [ ! -x "$SFDISK" ]; then
516     warning "can't find sfdisk, skipping sfdisk report."
517     partitions="no"
518       fi
519    fi
520    if [ "$dohwinfo" == "yes" ]; then
521       if [ ! -x "$HWINFO" ]; then
522     warning "can't find hwinfo, skipping partition report."
523     partitions="no"
524       fi
525    fi
526 fi
527
528 if [ "$hardware" == "yes" ]; then
529    if [ ! -x "$HWINFO" ]; then
530       warning "can't find hwinfo, skipping hardware report."
531       hardware="no"
532    fi
533 fi
534
535 ## HARDWARE #############################
536
537 #
538 # here we use hwinfo to dump a table listing all the
539 # information we can find on the hardware of this machine
540 #
541
542 if [ "$hardware" == "yes" ]; then
543    if [ "dohwinfo" == "yes" ]; then
544       if [ -f $hardwarefile ]; then
545     rm $hardwarefile
546       fi
547       touch $hardwarefile
548       echo -e "\n\n====================== summary ======================\n" >>  $hardwarefile
549       debug "$HWINFO --short --cpu --network --disk --pci  >> $hardwarefile"
550       $HWINFO --short --cpu --network --disk --pci  >> $hardwarefile
551       for flag in cpu network bios pci; do
552     echo -e "\n\n====================== $flag ======================\n" >>  $hardwarefile
553     $HWINFO --$flag >> $hardwarefile
554       done
555    fi
556 fi
557
558 ## PARTITIONS #############################
559
560 # here we use sfdisk to dump a listing of all the partitions.
561 # these files can be used to directly partition a disk of the same size.
562
563 if [ "$partitions" == "yes" ]; then
564    if [ "$dosfdisk" == "yes" ]; then
565       devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
566    if [ "$devices" == "" ]; then
567       warning "No harddisks found"
568    fi
569    for dev in $devices; do
570       debug "$SFDISK will try to backup partition tables for device $dev"
571       [ -b $dev ] || continue
572       label=${dev#/dev/}
573       label=${label//\//-}
574       outputfile=${partitionsfile//__star__/$label}
575       debug "$SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null"
576       $SFDISK $sfdisk_options -d $dev > $outputfile 2>/dev/null
577       if [ $? -ne 0 ]; then
578          warning "The partition table for $dev could not be saved."
579       fi
580    done
581    fi
582    if [ "$dohwinfo" == "yes" ]; then
583       debug "Using $HWINFO to get all available disk information"
584       echo -e "\n\n====================== $disk ======================\n" >>  $hardwarefile
585       $HWINFO --disk >> $hardwarefile
586    fi
587 fi
588
589 if [ "$luksheaders" == "yes" ]; then
590    devices=`LC_ALL=C $SFDISK -l 2>/dev/null | grep "^Disk /dev" | @AWK@ '{print $2}' | cut -d: -f1`
591    [ -n "$devices" ] || warning "No block device found"
592    targetdevices=""
593    for dev in $devices; do
594       [ -b $dev ] || continue
595       debug "$CRYPTSETUP isLuks $dev"
596       $CRYPTSETUP isLuks $dev
597       [ $? -eq 0 ] && targetdevices="$targetdevices $dev"
598    done
599    for dev in $targetdevices; do
600       label=${dev#/dev/}
601       label=${label//\//-}
602       outputfile=${luksheadersfile//__star__/$label}
603       # the following sizes are expressed in terms of 512-byte sectors
604       debug "Let us find out the Luks header size for $dev"
605       debug "$CRYPTSETUP luksDump \"$dev\" | grep '^Payload offset:' | @AWK@ '{print $3}'"
606       headersize=`$CRYPTSETUP luksDump "$dev" | grep '^Payload offset:' | @AWK@ '{print $3}'`
607       if [ $? -ne 0 ]; then
608          warning "Could not compute the size of Luks header, skipping device $dev"
609          continue
610       elif [ -z "$headersize" -o -n "`echo \"$headersize\" | sed 's/[0-9]*//g'`" ]; then
611          warning "The computed size of Luks header is not an integer, skipping device $dev"
612          continue
613       fi
614       debug "Let us backup the Luks header of device $dev"
615       debug "$DD if=\"${dev}\" of=\"${outputfile}\" bs=512 count=\"${headersize}\""
616       output=`$DD if="${dev}" of="${outputfile}" bs=512 count="${headersize}" 2>&1`
617       exit_code=$?
618       if [ $exit_code -eq 0 ]; then
619          debug $output
620          info "The Luks header of $dev was saved to $outputfile."
621       else
622          debug $output
623          fatal "The Luks header of $dev could not be saved."
624       fi
625    done
626 fi
627
628 ## LVM ####################################
629
630 # returns 0 on success, 1 on error, 2 if not tried
631 # outputs error message if error, reason if not tried
632 function doLvmBackup () {
633    local lvmdir="$1"
634    if [ ! -d "$lvmdir" ]; then
635       if ! mkdir "$lvmdir"; then
636          echo "could not create $lvmdir"
637          return 2
638       else
639          info "successfully created $lvmdir"
640       fi
641    fi
642    if [ ! -w "$lvmdir" ]; then
643       echo "can not write to directory $lvmdir"
644       return 2
645    fi
646    debug "Let's try to gather the list of LVM volume groups"
647    debug "$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '"
648    vgs=`$VGS --options vg_name --noheadings | @SED@ 's/^[ ]*//' | @SED@ 's/[ ]*$//' | tr '\n' ' '`
649    debug "Let's try to backup LVM metadata for detected volume groups: $vgs"
650    debug "$VGCFGBACKUP --file \"${lvmdir}\"/\'%s\' $vgs"
651    output=`$VGCFGBACKUP --file "${lvmdir}"/'%s' $vgs`
652    exit_code=$?
653    debug $output
654    case $exit_code in
655       0)
656          info "LVM metadata was saved to $lvmdir for volume groups: $vgs"
657          return 0
658          ;;
659       *)
660          echo "LVM metadata could not be saved for at least one of these volume groups: $vgs"
661          return 1
662          ;;
663    esac
664 }
665
666 if [ "$lvm" == "yes" ]; then
667    output=`doLvmBackup "${parentdir}/lvm"`
668    exit_code=$?
669    case $exit_code in
670       0) # success. info message has already been displayed
671          true
672          ;;
673       1) # error
674          fatal "$output"
675          ;;
676       2) # could not even try
677          fatal "LVM metadata backup was not tried: $output"
678          ;;
679       *) # should never happen
680          fatal "Unhandled error ($exit_code) while trying to backup LVM metadata, please report a bug"
681          ;;
682    esac
683 fi