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