#3249 Issue open: Excluding LV does not work when using 'vgcfgrestore'

Labels: bug

jsmeix opened issue at 2024-06-14 07:49:

I tried out
https://github.com/rear/rear/issues/3243
with current GitHub master code.

On my original system (SLES15-SP5 with btrfs and LVM) I have

# lsblk -ipo NAME,KNAME,TYPE,FSTYPE,SIZE,MOUNTPOINTS /dev/vda
NAME                        KNAME     TYPE FSTYPE      SIZE MOUNTPOINTS
/dev/vda                    /dev/vda  disk              15G 
|-/dev/vda1                 /dev/vda1 part               8M 
`-/dev/vda2                 /dev/vda2 part LVM2_member  15G 
  |-/dev/mapper/system-root /dev/dm-0 lvm  btrfs        13G /var
  |                                                         /tmp
  |                                                         /usr/local
  |                                                         /srv
  |                                                         /root
  |                                                         /boot/grub2/i386-pc
  |                                                         /home
  |                                                         /opt
  |                                                         /boot/grub2/x86_64-efi
  |                                                         /.snapshots
  |                                                         /
  `-/dev/mapper/system-swap /dev/dm-1 lvm  swap          2G [SWAP]

After an initial "rear mkrescue" I got:

# grep -v '^#' var/lib/rear/layout/disklayout.conf
disk /dev/vda 16106127360 gpt
part /dev/vda 8388608 1048576 rear-noname bios_grub /dev/vda1
part /dev/vda 16096673280 9437184 rear-noname lvm,legacy_boot /dev/vda2
lvmdev /dev/system /dev/vda2 f0JwlP-e0Y4-FPpR-nW3M-mynv-nINi-rpRK1q 16093544448
lvmgrp /dev/system 4096 3837 15716352
lvmvol /dev/system swap 2147483648b linear 
lvmvol /dev/system root 13946060800b linear 
fs /dev/mapper/system-root / btrfs uuid=ced63b1e-0f67-44c3-920c-0dee6cf4428d label= options=rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot
btrfsdefaultsubvol /dev/mapper/system-root / 268 @/.snapshots/1/snapshot
btrfsnormalsubvol /dev/mapper/system-root / 256 @
btrfsnormalsubvol /dev/mapper/system-root / 258 @/var
btrfsnormalsubvol /dev/mapper/system-root / 259 @/usr/local
btrfsnormalsubvol /dev/mapper/system-root / 260 @/tmp
btrfsnormalsubvol /dev/mapper/system-root / 261 @/srv
btrfsnormalsubvol /dev/mapper/system-root / 262 @/root
btrfsnormalsubvol /dev/mapper/system-root / 263 @/opt
btrfsnormalsubvol /dev/mapper/system-root / 264 @/home
btrfsnormalsubvol /dev/mapper/system-root / 265 @/boot/grub2/x86_64-efi
btrfsnormalsubvol /dev/mapper/system-root / 266 @/boot/grub2/i386-pc
btrfsmountedsubvol /dev/mapper/system-root / rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot @/.snapshots/1/snapshot
btrfsmountedsubvol /dev/mapper/system-root /.snapshots rw,relatime,space_cache,subvolid=267,subvol=/@/.snapshots @/.snapshots
btrfsmountedsubvol /dev/mapper/system-root /boot/grub2/x86_64-efi rw,relatime,space_cache,subvolid=265,subvol=/@/boot/grub2/x86_64-efi @/boot/grub2/x86_64-efi
btrfsmountedsubvol /dev/mapper/system-root /opt rw,relatime,space_cache,subvolid=263,subvol=/@/opt @/opt
btrfsmountedsubvol /dev/mapper/system-root /home rw,relatime,space_cache,subvolid=264,subvol=/@/home @/home
btrfsmountedsubvol /dev/mapper/system-root /boot/grub2/i386-pc rw,relatime,space_cache,subvolid=266,subvol=/@/boot/grub2/i386-pc @/boot/grub2/i386-pc
btrfsmountedsubvol /dev/mapper/system-root /root rw,relatime,space_cache,subvolid=262,subvol=/@/root @/root
btrfsmountedsubvol /dev/mapper/system-root /srv rw,relatime,space_cache,subvolid=261,subvol=/@/srv @/srv
btrfsmountedsubvol /dev/mapper/system-root /usr/local rw,relatime,space_cache,subvolid=259,subvol=/@/usr/local @/usr/local
btrfsmountedsubvol /dev/mapper/system-root /tmp rw,relatime,space_cache,subvolid=260,subvol=/@/tmp @/tmp
btrfsmountedsubvol /dev/mapper/system-root /var rw,relatime,space_cache,subvolid=258,subvol=/@/var @/var
btrfsnocopyonwrite @/var
swap /dev/mapper/system-swap uuid=ad4aec5d-686a-4c3d-9b1c-1fc5e3cadcfd label=

# cat var/lib/rear/layout/disktodo.conf
todo /dev/vda disk
todo /dev/vda1 part
todo /dev/vda2 part
todo pv:/dev/vda2 lvmdev
todo /dev/system lvmgrp
todo /dev/mapper/system-swap lvmvol
todo /dev/mapper/system-root lvmvol
todo fs:/ fs
todo btrfsmountedsubvol:/ btrfsmountedsubvol
todo btrfsmountedsubvol:/.snapshots btrfsmountedsubvol
todo btrfsmountedsubvol:/boot/grub2/x86_64-efi btrfsmountedsubvol
todo btrfsmountedsubvol:/opt btrfsmountedsubvol
todo btrfsmountedsubvol:/home btrfsmountedsubvol
todo btrfsmountedsubvol:/boot/grub2/i386-pc btrfsmountedsubvol
todo btrfsmountedsubvol:/root btrfsmountedsubvol
todo btrfsmountedsubvol:/srv btrfsmountedsubvol
todo btrfsmountedsubvol:/usr/local btrfsmountedsubvol
todo btrfsmountedsubvol:/tmp btrfsmountedsubvol
todo btrfsmountedsubvol:/var btrfsmountedsubvol
todo swap:/dev/mapper/system-swap swap

I set

EXCLUDE_COMPONENTS+=( /dev/mapper/system-swap )

I did re-run "rear mkrescue" and got now

# grep -v '^#' var/lib/rear/layout/disklayout.conf
disk /dev/vda 16106127360 gpt
part /dev/vda 8388608 1048576 rear-noname bios_grub /dev/vda1
part /dev/vda 16096673280 9437184 rear-noname lvm,legacy_boot /dev/vda2
lvmdev /dev/system /dev/vda2 f0JwlP-e0Y4-FPpR-nW3M-mynv-nINi-rpRK1q 16093544448
lvmgrp /dev/system 4096 3837 15716352
lvmvol /dev/system root 13946060800b linear 
fs /dev/mapper/system-root / btrfs uuid=ced63b1e-0f67-44c3-920c-0dee6cf4428d label= options=rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot
btrfsdefaultsubvol /dev/mapper/system-root / 268 @/.snapshots/1/snapshot
btrfsnormalsubvol /dev/mapper/system-root / 256 @
btrfsnormalsubvol /dev/mapper/system-root / 258 @/var
btrfsnormalsubvol /dev/mapper/system-root / 259 @/usr/local
btrfsnormalsubvol /dev/mapper/system-root / 260 @/tmp
btrfsnormalsubvol /dev/mapper/system-root / 261 @/srv
btrfsnormalsubvol /dev/mapper/system-root / 262 @/root
btrfsnormalsubvol /dev/mapper/system-root / 263 @/opt
btrfsnormalsubvol /dev/mapper/system-root / 264 @/home
btrfsnormalsubvol /dev/mapper/system-root / 265 @/boot/grub2/x86_64-efi
btrfsnormalsubvol /dev/mapper/system-root / 266 @/boot/grub2/i386-pc
btrfsmountedsubvol /dev/mapper/system-root / rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot @/.snapshots/1/snapshot
btrfsmountedsubvol /dev/mapper/system-root /.snapshots rw,relatime,space_cache,subvolid=267,subvol=/@/.snapshots @/.snapshots
btrfsmountedsubvol /dev/mapper/system-root /boot/grub2/x86_64-efi rw,relatime,space_cache,subvolid=265,subvol=/@/boot/grub2/x86_64-efi @/boot/grub2/x86_64-efi
btrfsmountedsubvol /dev/mapper/system-root /opt rw,relatime,space_cache,subvolid=263,subvol=/@/opt @/opt
btrfsmountedsubvol /dev/mapper/system-root /home rw,relatime,space_cache,subvolid=264,subvol=/@/home @/home
btrfsmountedsubvol /dev/mapper/system-root /boot/grub2/i386-pc rw,relatime,space_cache,subvolid=266,subvol=/@/boot/grub2/i386-pc @/boot/grub2/i386-pc
btrfsmountedsubvol /dev/mapper/system-root /root rw,relatime,space_cache,subvolid=262,subvol=/@/root @/root
btrfsmountedsubvol /dev/mapper/system-root /srv rw,relatime,space_cache,subvolid=261,subvol=/@/srv @/srv
btrfsmountedsubvol /dev/mapper/system-root /usr/local rw,relatime,space_cache,subvolid=259,subvol=/@/usr/local @/usr/local
btrfsmountedsubvol /dev/mapper/system-root /tmp rw,relatime,space_cache,subvolid=260,subvol=/@/tmp @/tmp
btrfsmountedsubvol /dev/mapper/system-root /var rw,relatime,space_cache,subvolid=258,subvol=/@/var @/var
btrfsnocopyonwrite @/var

# cat var/lib/rear/layout/disktodo.conf
todo /dev/vda disk
todo /dev/vda1 part
todo /dev/vda2 part
todo pv:/dev/vda2 lvmdev
todo /dev/system lvmgrp
done /dev/mapper/system-swap lvmvol
todo /dev/mapper/system-root lvmvol
todo fs:/ fs
todo btrfsmountedsubvol:/ btrfsmountedsubvol
todo btrfsmountedsubvol:/.snapshots btrfsmountedsubvol
todo btrfsmountedsubvol:/boot/grub2/x86_64-efi btrfsmountedsubvol
todo btrfsmountedsubvol:/opt btrfsmountedsubvol
todo btrfsmountedsubvol:/home btrfsmountedsubvol
todo btrfsmountedsubvol:/boot/grub2/i386-pc btrfsmountedsubvol
todo btrfsmountedsubvol:/root btrfsmountedsubvol
todo btrfsmountedsubvol:/srv btrfsmountedsubvol
todo btrfsmountedsubvol:/usr/local btrfsmountedsubvol
todo btrfsmountedsubvol:/tmp btrfsmountedsubvol
todo btrfsmountedsubvol:/var btrfsmountedsubvol
done swap:/dev/mapper/system-swap swap

so the differences are in disklayout.conf

-lvmvol /dev/system swap 2147483648b linear 
+#lvmvol /dev/system swap 2147483648b linear

-swap /dev/mapper/system-swap uuid=ad4aec5d-686a-4c3d-9b1c-1fc5e3cadcfd label=
+#swap /dev/mapper/system-swap uuid=ad4aec5d-686a-4c3d-9b1c-1fc5e3cadcfd label=

and in disktodo.conf

-todo /dev/mapper/system-swap lvmvol
+done /dev/mapper/system-swap lvmvol

-todo swap:/dev/mapper/system-swap swap
+done swap:/dev/mapper/system-swap swap

But there are no changes (except timestamps) in
var/lib/rear/layout/lvm/system.cfg
so the EXCLUDE_COMPONENTS value is not applied there.

The result is, cf.
https://github.com/rear/rear/issues/3243#issuecomment-2167410191

When LVM things are recreated by using
the modern/default 'lvm vgcfgrestore' method,
then LVM things get recreated as stored in
var/lib/rear/layout/lvm/system.cfg
and there things are not excluded which are
specified via EXCLUDE_COMPONENTS.
So when LVM things get recreated via 'lvm vgcfgrestore'
LVM things are recreated during "rear recover" regardless
that some are excluded via EXCLUDE_COMPONENTS.

In contrast when LVM things get recreated by using
traditional/fallback 'vgcreate/lvcreate' commands,
then LVM things get recreated as stored in
var/lib/rear/layout/disklayout.conf
and therein what is excluded via EXCLUDE_COMPONENTS
is commented out so in this case what is excluded
via EXCLUDE_COMPONENTS will not be recreated
during "rear recover".

jsmeix commented at 2024-06-14 07:53:

I got this after "rear recover"
(in my case the modern/default 'lvm vgcfgrestore'
method was used):

RESCUE localhost:~ # lsblk -ipo NAME,KNAME,TYPE,FSTYPE,SIZE,MOUNTPOINTS /dev/vda
NAME                        KNAME     TYPE FSTYPE      SIZE MOUNTPOINTS
/dev/vda                    /dev/vda  disk              15G 
|-/dev/vda1                 /dev/vda1 part               8M 
`-/dev/vda2                 /dev/vda2 part LVM2_member  15G 
  |-/dev/mapper/system-swap /dev/dm-0 lvm                2G 
  `-/dev/mapper/system-root /dev/dm-1 lvm  btrfs        13G /mnt/local/var
                                                            /mnt/local/tmp
                                                            /mnt/local/usr/local
                                                            /mnt/local/srv
                                                            /mnt/local/root
                                                            /mnt/local/boot/grub2/i386-pc
                                                            /mnt/local/home
                                                            /mnt/local/opt
                                                            /mnt/local/boot/grub2/x86_64-efi
                                                            /mnt/local/.snapshots
                                                            /mnt/local

RESCUE localhost:~ # lvm lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root system -wi-ao---- 12.99g                                                    
  swap system -wi-a-----  2.00g

The LV /dev/mapper/system-swap was recreated
but using it as 'swap' was not recreated
because that was commented out in disklayout.conf

jsmeix commented at 2024-06-14 11:39:

There is the same kind of issue with my currently experimental
(and therefore intentionally not yet documented)
support for the SUSE tool 'barrel', see in particular
https://github.com/rear/rear/pull/2876#issuecomment-1278958908

The common generic issue behind is:

When ReaR uses a third-party tool to do something,
then entries in ReaR's own config files have
in general no effect on what a third-party tool does.

Here "third-party" means when the functionality
is not implemented in ReaR scripts but instead
ReaR "just calls" a tool to do something.

There could be limited exceptions
where users get some control, for example
entries in ReaR's own config files could specify
command line options how a third-party tool is called,
for example BACKUP_PROG_OPTIONS and several
other *_OPTIONS ReaR config variables.
But in general the user has less control
when ReaR calls a third-party tool to do something.

The huge advantage of "just calling" a third-party tool
to do something instead of implementing its functionality
(again) directly in ReaR as ReaR scripts is
that an appropriate third-party tool basically always
does its job better than a reimplementation in ReaR.

Here "better" means in particular things like:

Less bugs:
The tool is dedicated to do its particular job.
So the quality of the outcome is usually better for the user.

Much less maintenance effort in ReaR:
In a particular system (e.g. in a particular version
of some Linux distribution) the tool that is included
in that specific Linux distribution does its job
as intended by that specific Linux distribution.
So we at ReaR do not need to care or worry about
differences between different Linux distributions.


[Export of Github issue for rear/rear.]