Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically include mounted btrfs subvolumes in NETFS backups #3175

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lzaoral
Copy link
Contributor

@lzaoral lzaoral commented Mar 7, 2024

Pull Request Details:
  • Type: Enhancement

  • Impact: High

  • Reference to related issue (URL): NETFS tar backup no btrfs subvolumes by default #2928

  • How was this pull request tested? rear savelayout and manual inspection of generated files and backup/restore of a Fedora Rawhide machine

  • Description of the changes in this pull request:

    • automatically include mounted btrfs subvolumes in NETFS backups
    • improve generation of $RESTORE_EXCLUDE_FILE

@jsmeix jsmeix self-requested a review March 7, 2024 12:57
@jsmeix jsmeix added the enhancement Adaptions and new features label Mar 7, 2024
@jsmeix jsmeix added this to the ReaR v2.8 milestone Mar 7, 2024
@jsmeix
Copy link
Member

jsmeix commented Mar 7, 2024

@lzaoral
thank you for this enhancement!

I will test how it behaves on SLES systems
with their rather complicated default btrfs structure.

Offhandedly I think the main problem is
possibly mounted btrfs snapshot subvolumes, see
"When btrfs is used with snapshots ...
then usual backup and restore cannot work." in
https://en.opensuse.org/SDB:Disaster_Recovery#btrfs

I.e. when there are mounted btrfs "thingies"
listed as 'btrfsmountedsubvol' in disklayout.conf
that are also listed as '#btrfssnapshotsubvol'.

For example a disklayout.conf on SLES15-SP5 (excerpts)

btrfsdefaultsubvol /dev/sda2 / 268 @/.snapshots/1/snapshot
...
#btrfssnapshotsubvol /dev/sda2 / 272 @/.snapshots/2/snapshot
#btrfssnapshotsubvol /dev/sda2 / 273 @/.snapshots/3/snapshot
#btrfssnapshotsubvol /dev/sda2 / 274 @/.snapshots/4/snapshot
...
btrfsmountedsubvol /dev/sda2 / rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot @/.snapshots/1/snapshot
btrfsmountedsubvol /dev/sda2 /.snapshots rw,relatime,space_cache,subvolid=267,subvol=/@/.snapshots @/.snapshots
btrfsmountedsubvol /dev/sda2 /boot/grub2/x86_64-efi rw,relatime,space_cache,subvolid=265,subvol=/@/boot/grub2/x86_64-efi @/boot/grub2/x86_64-efi
btrfsmountedsubvol /dev/sda2 /root rw,relatime,space_cache,subvolid=262,subvol=/@/root @/root
btrfsmountedsubvol /dev/sda2 /opt rw,relatime,space_cache,subvolid=263,subvol=/@/opt @/opt
btrfsmountedsubvol /dev/sda2 /home rw,relatime,space_cache,subvolid=264,subvol=/@/home @/home
btrfsmountedsubvol /dev/sda2 /boot/grub2/i386-pc rw,relatime,space_cache,subvolid=266,subvol=/@/boot/grub2/i386-pc @/boot/grub2/i386-pc
btrfsmountedsubvol /dev/sda2 /srv rw,relatime,space_cache,subvolid=261,subvol=/@/srv @/srv
btrfsmountedsubvol /dev/sda2 /tmp rw,relatime,space_cache,subvolid=260,subvol=/@/tmp @/tmp
btrfsmountedsubvol /dev/sda2 /usr/local rw,relatime,space_cache,subvolid=259,subvol=/@/usr/local @/usr/local
btrfsmountedsubvol /dev/sda2 /var rw,relatime,space_cache,subvolid=258,subvol=/@/var @/var

For example assume in addition to @/.snapshots/1/snapshot
that is the current system snapshot which is mounted at /
also
some other snapshots of the system like
@/.snapshots/2/snapshot and @/.snapshots/4/snapshot
are mounted e.g. at /snapshot2 and /snapshot4

Then a 'tar' backup would contain the system files
basically three times:

  1. the files of what is mounted at /
  2. the files of what is mounted at /snapshot2
  3. the files of what is mounted at /snapshot4

So the backup would be basically about three times
as big as if only what is mounted at / was backed up.

But during 'tar' restore there is no deduplication
so the restore would basically need about three times
the disk space as the original system needed.

@pcahyna
Copy link
Member

pcahyna commented Mar 7, 2024

I think the main problem is
possibly mounted btrfs snapshot subvolumes

I am not a btrfs expert at all, but is it possible to distinguish snapshot subvolumes from "normal" (non-snapshot) subvolumes? Then we could save this subvolume metadata (snapshot yes/no) and do something based on the information when recreating and restoring. First we would probably just skip snapshots, later we could do something more intelligent if possible.
It is definitely possible to distinguish snapshots from regular filesystems (filessytems are equivalent to btrfs subvolumes) in ZFS. It is also possible to recognize snapshots from regular volumes in LVM.

@jsmeix
Copy link
Member

jsmeix commented Mar 7, 2024

Only an offhanded thought:

I fear btrfs normal subvolumes versus btrfs snapshot subvolumes
is only one example of a very generic problem when by default
every mounted "thingy" is included in the 'tar' backup:

I think it is in general possible that one same
"mountable thingy" can be mounted at the same time
at different mount points e.g. at '/here' and '/there'.

When '/here' and '/there' are included in a 'tar' backup
things may get restored twice as distinct sets of files
and not as one same set of files that is mounted two times
under the mountpoint directories '/here' and '/there'.

Tomorrow I will experiment a bit with that.

@jsmeix
Copy link
Member

jsmeix commented Mar 7, 2024

Perhaps we can by default have every mounted "thingy"
included in the 'tar' backup
BUT
we may need some check for duplicates in the 'tar' backup
i.e. something that detects when one same "mountable thingy"
will become included in the 'tar' backup more than once.

@jsmeix
Copy link
Member

jsmeix commented Mar 8, 2024

Currently I am exploring how 'tar' behaves in general
when exact same files are provided as 'tar' arguments
to be archived.

It seems 'tar' behaves well forgiving in this case:

# mkdir test

# cd test

# echo foo >foo

# tar -cvvvf test.tar foo foo
-rw-r--r-- root/root         4 2024-03-08 09:41 foo
hrw-r--r-- root/root         0 2024-03-08 09:41 foo link to foo

# tar -tvvvf test.tar
-rw-r--r-- root/root         4 2024-03-08 09:41 foo
hrw-r--r-- root/root         0 2024-03-08 09:41 foo link to foo

# mkdir untartest

# cd untartest/

# tar -xvvvf ../test.tar
-rw-r--r-- root/root         4 2024-03-08 09:41 foo
hrw-r--r-- root/root         0 2024-03-08 09:41 foo link to foo

# ls -l
total 4
-rw-r--r-- 1 root root 4 Mar  8 09:41 foo

So perhaps only mounted btrfs snapshot subvolumes
added to 'tar' arcives cause real problems in practice.
In this case btrfs snapshot subvolumes should be excluded
by default from being added to what 'tar' should archive.

I think it is OK if a user mounts the same stuff
at different mount points and ReaR includes those
mount points by default in the 'tar' backup
then it is up to the user to manually exclude things
as needed from his backup.

@pcahyna
Copy link
Member

pcahyna commented Mar 8, 2024

@jsmeix

I fear btrfs normal subvolumes versus btrfs snapshot subvolumes is only one example of a very generic problem when by default every mounted "thingy" is included in the 'tar' backup:

I think it is in general possible that one same "mountable thingy" can be mounted at the same time at different mount points

I disagree that it is an example of this problem. Snapshots are not the same thing mounted at different places. They are different things mounted at different places - snapshots exist because their content is (at least in principle) different.

One filesystem mounted at more places can occur as well, and it will result in an explosion of backup data, but it restoring it twice then should not result in an increase of the size of the restored system, only in a slower restore, because you keep restoring to the same filesystem.

I would not try to solve these two problems in the same way (cf. RFC 1925 item 5).

@pcahyna
Copy link
Member

pcahyna commented Mar 8, 2024

It seems 'tar' behaves well forgiving in this case:

# mkdir test

# cd test

# echo foo >foo

# tar -cvvvf test.tar foo foo
-rw-r--r-- root/root         4 2024-03-08 09:41 foo
hrw-r--r-- root/root         0 2024-03-08 09:41 foo link to foo

# tar -tvvvf test.tar
-rw-r--r-- root/root         4 2024-03-08 09:41 foo
hrw-r--r-- root/root         0 2024-03-08 09:41 foo link to foo

# mkdir untartest

# cd untartest/

# tar -xvvvf ../test.tar
-rw-r--r-- root/root         4 2024-03-08 09:41 foo
hrw-r--r-- root/root         0 2024-03-08 09:41 foo link to foo

# ls -l
total 4
-rw-r--r-- 1 root root 4 Mar  8 09:41 foo

It thinks that the doubled file names are different names for the same files (i.e. hardlinks), which is not entirely correct - not sure if it can have some unwanted consequences or not.

@jsmeix
Copy link
Member

jsmeix commented Mar 8, 2024

Yes.

The whole point of my experiments with 'tar' here
is to find out if my "fear" above is true or not and
in general to better understand what we have to deal with.

If it is actually only one root problem
then this root problem should be solved
(instead of solving each of its instances).

If it is actually several separated problems then
each separated problem should be solved separately.

#3175 (comment)
indicates that it is several separated problems
(but this is only my very first test in this area).

From my experiments with 'tar' in the past I know that
'tar' behaves deterministically (i.e. as programmed and
documented when reading the whole 'tar' manual carefully)
but that could appear rather often 'unexpectedly'
(i.e. different than what one may expect offhandedly), e.g.
#2911 (comment)

@pcahyna
Copy link
Member

pcahyna commented Mar 8, 2024

If it is actually only one root problem then this root problem should be solved (instead of solving each of its instances).

If it is actually several separated problems then each separated problem should be solved separatedly.

That's an interesting idea. For multiple identical arguments to tar, tar duplicates the backup and considers the secondary copy as a hardlink to the first copy. I checked that the same happens when there is a filesystem mounted multiple times:

# mkdir /mnt/mount1
# mkdir /mnt/mount2
# mount /dev/vdb /mnt/mount1
# mount /dev/vdb /mnt/mount2
# touch /mnt/mount1/foo
# ls -l /mnt/mount2/foo
-rwxr-xr-x. 1 root root 0 Mar  8 07:36 /mnt/mount2/foo
# tar cvvf /dev/null /mnt/mount1 /mnt/mount2
tar: Removing leading `/' from member names
drwxr-xr-x root/root         0 1969-12-31 19:00 /mnt/mount1/
-rwxr-xr-x root/root         0 2024-03-08 07:36 /mnt/mount1/foo
tar: Removing leading `/' from hard link targets
drwxr-xr-x root/root         0 1969-12-31 19:00 /mnt/mount2/
hrwxr-xr-x root/root         0 2024-03-08 07:36 /mnt/mount2/foo link to mnt/mount1/foo

Is the same happening with different btrfs snapshots mounted at different mountpoints? I.e. does tar consider files in different snapshots (originally same, but possibly different when they have been modified since the snapshot was taken) as hardlinks to the same file?

@lzaoral
Copy link
Contributor Author

lzaoral commented Mar 8, 2024

Thank you for the feedback, @jsmeix! I'll amend the code to skip backup of all mounted btrfs snapshot subvolumes.

The duplication of files in backup when a filesystem/btrfs subvolume is mounted more than once is a different (though related) issue, therefore, I suggest to resolve it separately.

jsmeix added a commit that referenced this pull request Mar 8, 2024
In backup/NETFS/default/500_make_backup.sh use
without_subsequent_duplicates $TMP_DIR/backup-include.txt
to ignore duplicate arguments provided
to 'tar' and 'rsync' what should be archived
to avoid that 'tar' and 'rsync' archive
exact same things multiple times
which needlessly increases backup time and
in case of 'tar' the backup archive size and
storage space and backup restore time, cf.
#3175 (comment)
@jsmeix
Copy link
Member

jsmeix commented Mar 8, 2024

I tested it with SLES15-SP5
with the default btrfs structure
on a QEMU/KVM test VM:

# lsblk -ipo NAME,TRAN,TYPE,FSTYPE,SIZE,MOUNTPOINTS
NAME        TRAN TYPE FSTYPE   SIZE MOUNTPOINTS
/dev/sda    ata  disk           15G 
|-/dev/sda1      part            8M 
|-/dev/sda2      part btrfs     13G /var
|                                   /usr/local
|                                   /root
|                                   /tmp
|                                   /srv
|                                   /boot/grub2/i386-pc
|                                   /opt
|                                   /home
|                                   /boot/grub2/x86_64-efi
|                                   /.snapshots
|                                   /
`-/dev/sda3      part swap       2G [SWAP]

I was in particular interested how things behave
with the "well known" (to SLES users) SUSE specific

BACKUP_PROG_INCLUDE=( $( findmnt -n -r -o TARGET -t btrfs | grep -v '^/$' | egrep -v 'snapshots|crash' ) )

manual setting in etc/rear/local.conf
cf. conf/examples/SLE12-SP2-btrfs-example.conf
so I have

OUTPUT=ISO
BACKUP=NETFS
BACKUP_OPTIONS="nfsvers=3,nolock"
BACKUP_URL=nfs://192.168.178.66/nfs
REQUIRED_PROGS+=( snapper chattr )
PROGS+=( lsattr )
COPY_AS_IS+=( /usr/lib/snapper/installation-helper /etc/snapper/config-templates/default )
BACKUP_PROG_INCLUDE=( /boot/grub2/i386-pc /boot/grub2/x86_64-efi /home /opt /root /srv /tmp /usr/local /var )

With that I got duplicated things in the backup.tar.gz

To make ReaR behave backward compatible for SLES users
and because it seems to be "the right thing" in general
I implemented
#3177

With this additional changes I get no longer
duplicated things in the backup.tar.gz
BUT
I did not yet test "rear recover".
This will be done next week.

@lzaoral @pcahyna @rear/contributors
I wish you a relaxed and recovering weekend!

@pcahyna
Copy link
Member

pcahyna commented Mar 8, 2024

@jsmeix if you have snapshots, can you please test #3175 (comment) : "does tar consider files in different snapshots (originally same, but possibly different when they have been modified since the snapshot was taken) as hardlinks to the same file?" ?

@pcahyna
Copy link
Member

pcahyna commented Mar 10, 2024

I was in particular interested how things behave with the "well known" (to SLES users) SUSE specific

BACKUP_PROG_INCLUDE=( $( findmnt -n -r -o TARGET -t btrfs | grep -v '^/$' | egrep -v 'snapshots|crash' ) )

manual setting in etc/rear/local.conf cf. conf/examples/SLE12-SP2-btrfs-example.conf so I have

OUTPUT=ISO
BACKUP=NETFS
BACKUP_OPTIONS="nfsvers=3,nolock"
BACKUP_URL=nfs://192.168.178.66/nfs
REQUIRED_PROGS+=( snapper chattr )
PROGS+=( lsattr )
COPY_AS_IS+=( /usr/lib/snapper/installation-helper /etc/snapper/config-templates/default )
BACKUP_PROG_INCLUDE=( /boot/grub2/i386-pc /boot/grub2/x86_64-efi /home /opt /root /srv /tmp /usr/local /var )

With that I got duplicated things in the backup.tar.gz

Is it a regression with this PR, or did you get duplicated entries in backup.tar.gz even before? What are the duplicated entries? Aren't you missing BACKUP_ONLY_INCLUDE="yes"? (but then you should probably add /boot to BACKUP_PROG_INCLUDE unless on SLES you have /boot as part of /).

@pcahyna
Copy link
Member

pcahyna commented Mar 11, 2024

@jsmeix if you have snapshots, can you please test #3175 (comment) : "does tar consider files in different snapshots (originally same, but possibly different when they have been modified since the snapshot was taken) as hardlinks to the same file?" ?

I tested ZFS and the same files in a snapshot and in the original filesystem do not show up as hardlinks to the same file in the tar output. Of course, although Btrfs is in many ways analogous to ZFS, it can behave differently in details like that.

@pcahyna
Copy link
Member

pcahyna commented Mar 26, 2024

Hi all, reviewing what needs to be done there.

@pcahyna
Copy link
Member

pcahyna commented Apr 9, 2024

Hi @jsmeix can you please have a look? I believe the first four items in the checklist above are for you (the second only partially, you implement uniq_unsorted in #3177 and then @lzaoral will use it here). Is the task list ok?

@jsmeix
Copy link
Member

jsmeix commented Apr 9, 2024

@pcahyna
I will have a look.

First I would like to implement uniq_unsorted
or perhaps even better named unique_unsorted cf.
#3177 (comment)
so that @lzaoral could use it here.

jsmeix added a commit that referenced this pull request Apr 12, 2024
In lib/global-functions.sh added a
new unique_unsorted() function
that outputs lines in a file or from STDIN
without subsequent duplicate lines
which keeps the ordering of the lines, see
#3177
In backup/NETFS/default/500_make_backup.sh use
unique_unsorted $TMP_DIR/backup-include.txt
to ignore duplicate arguments provided
to 'tar' and 'rsync' what should be archived
to avoid that 'tar' and 'rsync' archive
exact same things multiple times
which needlessly increases backup time and
in case of 'tar' the backup archive size and
storage space and backup restore time, cf.
#3175 (comment)
@lzaoral
Copy link
Contributor Author

lzaoral commented Apr 29, 2024

@jsmeix Thank you for implementing unique_unsorted! Hopefully, I'll get to the exclusion of snapshot volumes this week.

lzaoral added a commit to lzaoral/rear that referenced this pull request May 14, 2024
@lzaoral lzaoral force-pushed the backup-mounted-btrfs-subvolumes branch from fbfc80b to 3690ead Compare May 14, 2024 07:56
@lzaoral
Copy link
Contributor Author

lzaoral commented May 14, 2024

@jsmeix @pcahyna The automatic exclusion of snapshots from backups is implemented in 027785f.

lzaoral added a commit to lzaoral/rear that referenced this pull request May 14, 2024
@lzaoral lzaoral force-pushed the backup-mounted-btrfs-subvolumes branch from 3690ead to e693831 Compare May 14, 2024 08:01
@jsmeix
Copy link
Member

jsmeix commented May 14, 2024

@lzaoral
see my
4742906#r141983908
which I copy here to be safe that it is not lost because
027785f
shows

This commit does not belong to any branch on this repository,
and may belong to a fork outside of the repository.

Copy of my
4742906#r141983908
follows here:

                    echo "Mounted btrfs snapshot subvolumes are autoexcluded.

Here you must use

echo "# ..."

because here STDOUT gets written into disklayout.conf
because that code is within the

# Begin of group command that appends its stdout to DISKLAYOUT_FILE:
{

...

} 1>>$DISKLAYOUT_FILE
# End of group command that appends its stdout to DISKLAYOUT_FILE

Yes - I know - that is horrible coding style
which needs to be cleaned up - at some time -
as time permits - i.e. "never in practice" :-(

@lzaoral lzaoral force-pushed the backup-mounted-btrfs-subvolumes branch from e693831 to 3fe88cc Compare May 14, 2024 08:20
@jsmeix
Copy link
Member

jsmeix commented May 14, 2024

The automatic exclusion of snapshots from backups
with fixed echo "# ..." is implemented in
018c528

Copy link
Member

@jsmeix jsmeix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From plain looking at the code I think it is OK
so I approve it "bona fide".
I will test it later on SLES as time permits
(i.e. that could happen after it was merged).

jsmeix added a commit that referenced this pull request May 14, 2024
Overhauled 400_create_include_exclude_files.sh

Now do first backup the mounted filesystems
to backup '/' first so the basic system files get stored
first in the backup and then backup what is specified in BACKUP_PROG_INCLUDE
see #3177 (comment)
and #3217 (comment)

Report suspicious cases as LogPrintError to have the user at least informed.

Remove duplicates but keep the ordering.
to avoid possibly unwanted and unexpected subtle consequences
see #3175 (comment)

Verify that at least '/' is in backup-include.txt
see #3217

Redirect stdout into files exactly at the command where needed
instead of more global redirections,
cf. "horrible coding style"
in #3175 (comment)
@jsmeix
Copy link
Member

jsmeix commented May 14, 2024

@lzaoral
if time permits please have a look at my
#3221
if it fits together with your changes here
in particular regarding your changed
layout/save/default/340_generate_mountpoint_device.sh

@jsmeix
Copy link
Member

jsmeix commented May 15, 2024

I tested "rear -D mkbackup"
for this pull request here
together with my changes in my
#3221
on my SLES15 SP5 tests VM with the
SUSE default btrfs structure
and as far as I see up to now
all looks perfectly well
except one possible issue that I described
near the end of my "Details" at "BUT".

Details:

Disk layout:

# lsblk -ipo NAME,KNAME,PKNAME,TRAN,TYPE,FSTYPE,SIZE,MOUNTPOINTS /dev/sda

NAME        KNAME     PKNAME   TRAN TYPE FSTYPE SIZE MOUNTPOINTS
/dev/sda    /dev/sda           ata  disk         15G 
|-/dev/sda1 /dev/sda1 /dev/sda      part          8M 
|-/dev/sda2 /dev/sda2 /dev/sda      part btrfs   13G /var
|                                                    /usr/local
|                                                    /root
|                                                    /tmp
|                                                    /boot/grub2/i386-pc
|                                                    /srv
|                                                    /boot/grub2/x86_64-efi
|                                                    /opt
|                                                    /home
|                                                    /.snapshots
|                                                    /
`-/dev/sda3 /dev/sda3 /dev/sda      part swap     2G [SWAP]

SUSE default btrfs structure:

# findmnt -t btrfs

TARGET                   SOURCE                              FSTYPE OPTIONS
/                        /dev/sda2[/@/.snapshots/1/snapshot] btrfs  rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot
├─/home                  /dev/sda2[/@/home]                  btrfs  rw,relatime,space_cache,subvolid=264,subvol=/@/home
├─/tmp                   /dev/sda2[/@/tmp]                   btrfs  rw,relatime,space_cache,subvolid=260,subvol=/@/tmp
├─/root                  /dev/sda2[/@/root]                  btrfs  rw,relatime,space_cache,subvolid=262,subvol=/@/root
├─/opt                   /dev/sda2[/@/opt]                   btrfs  rw,relatime,space_cache,subvolid=263,subvol=/@/opt
├─/boot/grub2/x86_64-efi /dev/sda2[/@/boot/grub2/x86_64-efi] btrfs  rw,relatime,space_cache,subvolid=265,subvol=/@/boot/grub2/x86_64-efi
├─/var                   /dev/sda2[/@/var]                   btrfs  rw,relatime,space_cache,subvolid=258,subvol=/@/var
├─/.snapshots            /dev/sda2[/@/.snapshots]            btrfs  rw,relatime,space_cache,subvolid=267,subvol=/@/.snapshots
├─/boot/grub2/i386-pc    /dev/sda2[/@/boot/grub2/i386-pc]    btrfs  rw,relatime,space_cache,subvolid=266,subvol=/@/boot/grub2/i386-pc
├─/srv                   /dev/sda2[/@/srv]                   btrfs  rw,relatime,space_cache,subvolid=261,subvol=/@/srv
└─/usr/local             /dev/sda2[/@/usr/local]             btrfs  rw,relatime,space_cache,subvolid=259,subvol=/@/usr/local

etc/rear/local.conf

# grep -v '^#' etc/rear/local.conf 

OUTPUT=ISO
BACKUP=NETFS
BACKUP_OPTIONS="nfsvers=3,nolock"
BACKUP_URL=nfs://192.168.178.66/nfs
REQUIRED_PROGS+=( snapper chattr )
PROGS+=( lsattr su )
COPY_AS_IS+=( /usr/lib/snapper/installation-helper /etc/snapper/config-templates/default )
BACKUP_PROG_INCLUDE=( /boot/grub2/i386-pc
                      /boot/grub2/x86_64-efi
                      /home
                      /opt
                      /root
                      /srv
                      /tmp
                      /usr/local
                      /var
                      /
                      /boot/grub2/i386-pc
                      /boot/grub2/x86_64-efi
                      /boot/grub2/i386-pc
                      /home
                      /
                      /opt )
BACKUP_PROG_EXCLUDE=( /var/tmp
                      /qqq
                      /var/tmp
                      /tmp )
POST_RECOVERY_SCRIPT=( 'if snapper --no-dbus -r $TARGET_FS_ROOT get-config | grep -q "^QGROUP.*[0-9]/[0-9]" ; then snapper --no-dbus -r $TARGET_FS_ROOT set-config QGROUP= ; snapper --no-dbus -r $TARGET_FS_ROOT setup-quota && echo snapper setup-quota done || echo snapper setup-quota failed ; else echo snapper setup-quota not used ; fi' )
SSH_ROOT_PASSWORD='rear'
USE_DHCLIENT="yes"
PROGRESS_MODE="plain"
PROGRESS_WAIT_SECONDS="5"
MODULES=( loaded_modules )
FIRMWARE_FILES=( no )

The duplicates in BACKUP_PROG_INCLUDE and BACKUP_PROG_EXCLUDE
are intentional to test that subsequent duplicates are ignored.

disklayout.conf

# grep -v '^#' var/lib/rear/layout/disklayout.conf 
disk /dev/sda 16106127360 gpt
part /dev/sda 8388608 1048576 rear-noname bios_grub /dev/sda1
part /dev/sda 13949206528 9437184 rear-noname legacy_boot /dev/sda2
part /dev/sda 2147466752 13958643712 rear-noname swap /dev/sda3
fs /dev/sda2 / btrfs uuid=bdec53c2-1ee8-4268-90f9-5ec523774035 label= options=rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot
btrfsdefaultsubvol /dev/sda2 / 268 @/.snapshots/1/snapshot
btrfsnormalsubvol /dev/sda2 / 256 @
btrfsnormalsubvol /dev/sda2 / 258 @/var
btrfsnormalsubvol /dev/sda2 / 259 @/usr/local
btrfsnormalsubvol /dev/sda2 / 260 @/tmp
btrfsnormalsubvol /dev/sda2 / 261 @/srv
btrfsnormalsubvol /dev/sda2 / 262 @/root
btrfsnormalsubvol /dev/sda2 / 263 @/opt
btrfsnormalsubvol /dev/sda2 / 264 @/home
btrfsnormalsubvol /dev/sda2 / 265 @/boot/grub2/x86_64-efi
btrfsnormalsubvol /dev/sda2 / 266 @/boot/grub2/i386-pc
btrfsmountedsubvol /dev/sda2 / rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot @/.snapshots/1/snapshot
btrfsmountedsubvol /dev/sda2 /.snapshots rw,relatime,space_cache,subvolid=267,subvol=/@/.snapshots @/.snapshots
btrfsmountedsubvol /dev/sda2 /home rw,relatime,space_cache,subvolid=264,subvol=/@/home @/home
btrfsmountedsubvol /dev/sda2 /opt rw,relatime,space_cache,subvolid=263,subvol=/@/opt @/opt
btrfsmountedsubvol /dev/sda2 /boot/grub2/x86_64-efi rw,relatime,space_cache,subvolid=265,subvol=/@/boot/grub2/x86_64-efi @/boot/grub2/x86_64-efi
btrfsmountedsubvol /dev/sda2 /srv rw,relatime,space_cache,subvolid=261,subvol=/@/srv @/srv
btrfsmountedsubvol /dev/sda2 /boot/grub2/i386-pc rw,relatime,space_cache,subvolid=266,subvol=/@/boot/grub2/i386-pc @/boot/grub2/i386-pc
btrfsmountedsubvol /dev/sda2 /tmp rw,relatime,space_cache,subvolid=260,subvol=/@/tmp @/tmp
btrfsmountedsubvol /dev/sda2 /root rw,relatime,space_cache,subvolid=262,subvol=/@/root @/root
btrfsmountedsubvol /dev/sda2 /usr/local rw,relatime,space_cache,subvolid=259,subvol=/@/usr/local @/usr/local
btrfsmountedsubvol /dev/sda2 /var rw,relatime,space_cache,subvolid=258,subvol=/@/var @/var
btrfsnocopyonwrite @/var
swap /dev/sda3 uuid=921157bc-e4d6-4869-8796-7e09207e49a9 label=

What I get in the backup included and excluded

# grep '^2024-05-15 08:42:44.4' var/log/rear/rear-localhost.log

2024-05-15 08:42:44.431801741 Including backup/NETFS/default/500_make_backup.sh
2024-05-15 08:42:44.433571019 Entering debugscript mode via 'set -x'.
2024-05-15 08:42:44.441702528 Making backup (using backup method NETFS)
2024-05-15 08:42:44.444339934 Backup include list (backup-include.txt contents without subsequent duplicates):
2024-05-15 08:42:44.446633014   /
2024-05-15 08:42:44.448576168   /.snapshots
2024-05-15 08:42:44.450386272   /home
2024-05-15 08:42:44.452304609   /opt
2024-05-15 08:42:44.454133219   /boot/grub2/x86_64-efi
2024-05-15 08:42:44.455978840   /srv
2024-05-15 08:42:44.457852313   /boot/grub2/i386-pc
2024-05-15 08:42:44.459744581   /tmp
2024-05-15 08:42:44.462067798   /root
2024-05-15 08:42:44.464037722   /usr/local
2024-05-15 08:42:44.466416713   /var
2024-05-15 08:42:44.468387840 Backup exclude list (backup-exclude.txt contents):
2024-05-15 08:42:44.470268486   /var/tmp
2024-05-15 08:42:44.472209757   /qqq
2024-05-15 08:42:44.474048124   /tmp
2024-05-15 08:42:44.476293264 Creating tar archive '/var/tmp/rear.cxFuYt1rYYpLGtB/outputfs/localhost/backup.tar.gz'
2024-05-15 08:42:44.485411273 tar --warning=no-xdev --sparse --block-number --totals --verbose --no-wildcards-match-slash --one-file-system --ignore-failed-read --anchored --xattrs --xattrs-include=security.capability --xattrs-include=security.selinux --acls --gzip -X /var/tmp/rear.cxFuYt1rYYpLGtB/tmp/backup-exclude.txt -C / -c -f - / /.snapshots /home /opt /boot/grub2/x86_64-efi /srv /boot/grub2/i386-pc /tmp /root /usr/local /var /root/rear.lzaoral-backup-mounted-btrfs-subvolumes/var/log/rear/rear-localhost.log | dd of=/var/tmp/rear.cxFuYt1rYYpLGtB/outputfs/localhost/backup.tar.gz bs=1M

The only thing that worried me is /.snapshots
so I had a closer look what it means
when /.snapshots gets included in the backup:

# find /.snapshots | wc -l
304850

looks scaring - more than 300 thousand files
but intentionally we use

tar ... --one-file-system ...

so what actually matters is

# find /.snapshots -xdev
/.snapshots
/.snapshots/1
/.snapshots/1/snapshot
/.snapshots/1/info.xml
/.snapshots/2
/.snapshots/2/snapshot
/.snapshots/2/info.xml
/.snapshots/2/grub-snapshot.cfg
/.snapshots/3
/.snapshots/3/snapshot
/.snapshots/3/grub-snapshot.cfg
/.snapshots/3/info.xml
/.snapshots/4
/.snapshots/4/snapshot
/.snapshots/4/info.xml
/.snapshots/4/grub-snapshot.cfg
/.snapshots/4/filelist-3.txt
/.snapshots/grub-snapshot.cfg

# du -hs --one-file-system /.snapshots
40K     /.snapshots

which looks much better
so I verfied what I got actually in the backup

NFS-server # tar -tvzf /nfs/localhost/backup.tar.gz | grep snapshots
drwxr-x--- root/root    0 2024-02-14 13:17 .snapshots/
drwxr-x--- root/root    0 2024-02-14 13:17 .snapshots/
drwxr-xr-x root/root    0 2024-02-14 13:03 .snapshots/1/
drwxr-xr-x root/root    0 2024-03-19 12:41 .snapshots/1/snapshot/
-rw------- root/root  168 2024-02-14 13:03 .snapshots/1/info.xml
drwxr-xr-x root/root    0 2024-02-14 13:07 .snapshots/2/
drwxr-xr-x root/root    0 2024-02-14 13:04 .snapshots/2/snapshot/
-rw------- root/root  268 2024-02-14 13:07 .snapshots/2/info.xml
-rw-r--r-- root/root  504 2024-02-14 13:17 .snapshots/2/grub-snapshot.cfg
drwxr-xr-x root/root    0 2024-02-14 13:17 .snapshots/3/
drwxr-xr-x root/root    0 2024-02-14 13:04 .snapshots/3/snapshot/
-rw-r----- root/root  502 2024-02-14 13:17 .snapshots/3/grub-snapshot.cfg
-rw------- root/root  258 2024-02-14 13:17 .snapshots/3/info.xml
drwxr-xr-x root/root    0 2024-02-14 13:17 .snapshots/4/
drwxr-xr-x root/root    0 2024-02-14 13:04 .snapshots/4/snapshot/
-rw------- root/root  240 2024-02-14 13:17 .snapshots/4/info.xml
-rw-r----- root/root  503 2024-02-14 13:17 .snapshots/4/grub-snapshot.cfg
-rw------- root/root 4939 2024-02-14 13:17 .snapshots/4/filelist-3.txt
-rw-r----- root/root  508 2024-02-14 13:17 .snapshots/grub-snapshot.cfg

so when /.snapshots gets included in the backup
it does not matter regarding the backup size.

BUT
when /.snapshots gets restored from the backup
during "rear recover" those old files likely mess up
the snapshot configuration of the recreated system
because during "rear recover" the whole
SUSE btrfs structure with its snapshot stuff
gets recreated anew from scratch so I assume
when that is recreated from scratch at least

/.snapshots
/.snapshots/1
/.snapshots/1/snapshot
/.snapshots/1/info.xml

got recreated during disk layout recreation
so that later during backup restore
those snapshot configuration files
must not be overwritten by outdated files
from the backup e.g. like

# cat /.snapshots/1/info.xml
<?xml version="1.0"?>
<snapshot>
  <type>single</type>
  <num>1</num>
  <date>2024-02-14 12:03:57</date>
  <description>first root filesystem</description>
</snapshot>

I will test what happens when I do "rear recover"
with that backup here which has /.snapshots included...

@lzaoral
Copy link
Contributor Author

lzaoral commented May 15, 2024

Thank you for the feedback, @jsmeix! In that case, it might be a good idea to autoexclude snapper_base_subvolume (@/.snapshots) from the backup as well so that it is still recreated but not restored so that we do not overwrite its metadata by stale information from the backup.

edit: The snapper btfrs subvolume is handled here:

snapper_base_subvolume="@/.snapshots"

@jsmeix
Copy link
Member

jsmeix commented May 15, 2024

Test what happens when I do "rear recover"
with that backup here which has /.snapshots included:

RESCUE localhost:~ # export MIGRATION_MODE='true'

RESCUE localhost:~ # rear -D recover
...
Start system layout restoration.
Disk '/dev/sda': creating 'gpt' partition table
Disk '/dev/sda': creating partition number 1 with name ''sda1''
Disk '/dev/sda': creating partition number 2 with name ''sda2''
Disk '/dev/sda': creating partition number 3 with name ''sda3''
Creating filesystem of type btrfs with mount point / on /dev/sda2.
Mounting filesystem /
Running snapper/installation-helper
Creating swap on /dev/sda3
Disk layout created.
Recreated storage layout:
NAME        KNAME     TRAN TYPE FSTYPE  LABEL     SIZE MOUNTPOINTS
/dev/sda    /dev/sda  ata  disk                    15G 
|-/dev/sda1 /dev/sda1      part                     8M 
|-/dev/sda2 /dev/sda2      part btrfs              13G /mnt/local/var
|                                                      /mnt/local/usr/local
|                                                      /mnt/local/root
|                                                      /mnt/local/tmp
|                                                      /mnt/local/boot/grub2/i386-pc
|                                                      /mnt/local/srv
|                                                      /mnt/local/boot/grub2/x86_64-efi
|                                                      /mnt/local/opt
|                                                      /mnt/local/home
|                                                      /mnt/local/.snapshots
|                                                      /mnt/local
`-/dev/sda3 /dev/sda3      part swap                2G 
/dev/sr0    /dev/sr0  ata  rom  iso9660 REAR-ISO 77.7M 
UserInput -I LAYOUT_MIGRATED_CONFIRMATION needed in /usr/share/rear/layout/recreate/default/200_run_layout_code.sh line 168
Confirm the recreated disk layout or go back one step
1) Confirm recreated disk layout and continue 'rear recover'
2) Go back one step to redo disk layout recreation
3) Use Relax-and-Recover shell and return back to here
4) Abort 'rear recover'
(default '1' timeout 300 seconds)
3
UserInput: Valid choice number result 'Use Relax-and-Recover shell and return back to here'

Welcome to Relax-and-Recover.

rear> find /mnt/local/.snapshots
/mnt/local/.snapshots
/mnt/local/.snapshots/1
/mnt/local/.snapshots/1/snapshot
/mnt/local/.snapshots/1/snapshot/etc
/mnt/local/.snapshots/1/snapshot/etc/snapper
/mnt/local/.snapshots/1/snapshot/etc/snapper/configs
/mnt/local/.snapshots/1/snapshot/etc/snapper/configs/root
/mnt/local/.snapshots/1/snapshot/.snapshots
/mnt/local/.snapshots/1/snapshot/home
/mnt/local/.snapshots/1/snapshot/opt
/mnt/local/.snapshots/1/snapshot/boot
/mnt/local/.snapshots/1/snapshot/boot/grub2
/mnt/local/.snapshots/1/snapshot/boot/grub2/x86_64-efi
/mnt/local/.snapshots/1/snapshot/boot/grub2/i386-pc
/mnt/local/.snapshots/1/snapshot/srv
/mnt/local/.snapshots/1/snapshot/tmp
/mnt/local/.snapshots/1/snapshot/root
/mnt/local/.snapshots/1/snapshot/usr
/mnt/local/.snapshots/1/snapshot/usr/local
/mnt/local/.snapshots/1/snapshot/var
/mnt/local/.snapshots/1/info.xml

rear> mv /mnt/local/.snapshots/1 /mnt/local/.snapshots/1.recreated

rear> exit
...
Running 'restore' stage ======================
Restoring from '/var/tmp/rear.tKYATuV8uCkXC3G/outputfs/localhost/backup.tar.gz' (restore log in /var/lib/rear/restore/recover.backup.tar.gz.760.restore.log) ...
Backup restore program 'tar' started in subshell (PID=5671)
Restored 467 MiB [avg. 95775 KiB/sec] 
Restored 933 MiB [avg. 95617 KiB/sec] 
Restored 1481 MiB [avg. 101156 KiB/sec] 
Restored 1917 MiB [avg. 98151 KiB/sec] 
Restored 2314 MiB [avg. 94792 KiB/sec] 
Restored 2665 MiB [avg. 90992 KiB/sec] 
Restored 3021 MiB [avg. 88389 KiB/sec] 
Restored 3416 MiB [avg. 87452 KiB/sec] 
OK
...

RESCUE localhost:~ # find /mnt/local/.snapshots -xdev -ls
 256 0 drwxr-x--- 1 root root   64 Feb 14 13:17 /mnt/local/.snapshots
 257 0 drwxr-xr-x 1 root root   32 May 15 14:57 /mnt/local/.snapshots/1.recreated
 256 0 drwxr-xr-x 1 root root  188 May 15 15:00 /mnt/local/.snapshots/1.recreated/snapshot
 258 4 -rw------- 1 root root  168 May 15 14:57 /mnt/local/.snapshots/1.recreated/info.xml
 259 0 drwxr-xr-x 1 root root   32 Feb 14 13:03 /mnt/local/.snapshots/1
 260 0 drwxr-xr-x 1 root root    0 Mar 19 12:41 /mnt/local/.snapshots/1/snapshot
 261 4 -rw------- 1 root root  168 Feb 14 13:03 /mnt/local/.snapshots/1/info.xml
 262 0 drwxr-xr-x 1 root root   66 Feb 14 13:07 /mnt/local/.snapshots/2
 263 0 drwxr-xr-x 1 root root    0 Feb 14 13:04 /mnt/local/.snapshots/2/snapshot
 264 4 -rw------- 1 root root  268 Feb 14 13:07 /mnt/local/.snapshots/2/info.xml
 265 4 -rw-r--r-- 1 root root  504 Feb 14 13:17 /mnt/local/.snapshots/2/grub-snapshot.cfg
 266 0 drwxr-xr-x 1 root root   66 Feb 14 13:17 /mnt/local/.snapshots/3
 267 0 drwxr-xr-x 1 root root    0 Feb 14 13:04 /mnt/local/.snapshots/3/snapshot
 268 4 -rw-r----- 1 root root  502 Feb 14 13:17 /mnt/local/.snapshots/3/grub-snapshot.cfg
 269 4 -rw------- 1 root root  258 Feb 14 13:17 /mnt/local/.snapshots/3/info.xml
 270 0 drwxr-xr-x 1 root root   94 Feb 14 13:17 /mnt/local/.snapshots/4
 271 0 drwxr-xr-x 1 root root    0 Feb 14 13:04 /mnt/local/.snapshots/4/snapshot
 272 4 -rw------- 1 root root  240 Feb 14 13:17 /mnt/local/.snapshots/4/info.xml
 273 4 -rw-r----- 1 root root  503 Feb 14 13:17 /mnt/local/.snapshots/4/grub-snapshot.cfg
 274 8 -rw------- 1 root root 4939 Feb 14 13:17 /mnt/local/.snapshots/4/filelist-3.txt
 275 4 -rw-r----- 1 root root  508 Feb 14 13:17 /mnt/local/.snapshots/grub-snapshot.cfg

So /.snapshots must be excluded from the backup restore
to avoid that after "rear recover" one has /.snapshots
messed up with old files - in particular the new created
and only correct one .snapshots/1 would get overwritten
with old files from the backup.

@lzaoral
That /.snapshots must be excluded from the backup restore
is a separated task for me so you could merge this one
and then I will care about /.snapshots via a separated
issue and/or pull request.

@jsmeix
Copy link
Member

jsmeix commented May 15, 2024

Mainly for my own information here
an addendum that is unrelated to this pull request
only because I noticed it here during my above
#3175 (comment)

Excerpts from /var/log/rear/rear-localhost.log

2024-05-15 14:56:33.854911738 Relax-and-Recover 2.7 / Git
2024-05-15 14:56:33.857055807 Running rear recover (PID 760 date 2024-05-15 14:56:33)
2024-05-15 14:56:33.859021352 Command line options: /bin/rear -D recover
2024-05-15 14:56:33.861149993 Using log file: /var/log/rear/rear-localhost.log
2024-05-15 14:56:33.863542518 Using build area: /var/tmp/rear.tKYATuV8uCkXC3G
2024-05-15 14:56:33.866203857 Setting TMPDIR to '/var/tmp' (was unset when ReaR was launched)
...
2024-05-15 15:02:33.797818313 Recreating initrd with /usr/bin/dracut...
++ chroot /mnt/local /bin/bash -c 'PATH=/sbin:/usr/sbin:/usr/bin:/bin /usr/bin/dracut --force'
realpath: /var/tmp: No such file or directory
dracut: Invalid tmpdir '/var/tmp'.
++ LogPrintError 'Warning:
Failed to recreate initrd with /usr/bin/dracut.
Check '\''/var/log/rear/rear-localhost.log'\'' why /usr/bin/dracut failed
and decide if the recreated system will boot
with the initrd '\''as is'\'' from the backup restore.
'

Indeed there is no var/tmp in the recreated system

RESCUE localhost:~ # ls -l /mnt/local/var
total 16
drwxr-xr-x 1 root root 106 Feb 14 13:08 adm
lrwxrwxrwx 1 root root  11 Jan  9  2023 agentx -> /run/agentx
drwxr-xr-x 1 root root  86 Feb 14 13:06 cache
drwxr-xr-x 1 root root   0 Mar 15  2022 crash
drwxr-xr-x 1 root root 402 May 15 15:00 lib
lrwxrwxrwx 1 root root   9 Feb 14 13:04 lock -> /run/lock
drwxr-xr-x 1 root root 716 May 15 15:02 log
lrwxrwxrwx 1 root root  10 Mar 15  2022 mail -> spool/mail
drwxr-xr-x 1 root root   0 Mar 15  2022 opt
lrwxrwxrwx 1 root root   4 Feb 14 13:04 run -> /run
drwxr-xr-x 1 root root 108 Feb 14 13:06 spool

RESCUE localhost:~ # ls -ld /mnt/local/tmp
drwxr-xr-x 1 root root 0 May 15 15:02 /mnt/local/tmp

My current guess is that there is no var/tmp
in the recreated system because I have

BACKUP_PROG_EXCLUDE=( /var/tmp
                      /qqq
                      /var/tmp
                      /tmp )

but what is a real bug is that

Setting TMPDIR to '/var/tmp' (was unset when ReaR was launched)

because during "rear recover" TMPDIR should not be set at all
so I added 'set -x' to /bin/rear to see what goes on

RESCUE localhost:~ # rear -D recover
...
+ readonly TMPDIR_ORIG=
+ TMPDIR_ORIG=
+ source /usr/share/rear/conf/default.conf
++ export TMPDIR=/var/tmp
++ TMPDIR=/var/tmp
...
+ test -e /etc/rear-release
+ RECOVERY_MODE=y
+ readonly RECOVERY_MODE
+ test recover '!=' help
++ readlink -e /var/tmp
+ export TMPDIR=/var/tmp
+ TMPDIR=/var/tmp
+ test -d /var/tmp
++ mktemp -d -t rear.XXXXXXXXXXXXXXX
+ BUILD_DIR=/var/tmp/rear.awoCzxeHag4tpr9
+ QuietAddExitTask cleanup_build_area_and_end_program
+ EXIT_TASKS=("$*" "${EXIT_TASKS[@]}")
+ ROOTFS_DIR=/var/tmp/rear.awoCzxeHag4tpr9/rootfs
+ mkdir -p /var/tmp/rear.awoCzxeHag4tpr9/rootfs
+ TMP_DIR=/var/tmp/rear.awoCzxeHag4tpr9/tmp
+ mkdir -p /var/tmp/rear.awoCzxeHag4tpr9/tmp
+ [[ -n y ]]
+ test ''
+ tmpdir_debug_info='Setting TMPDIR to '\''/var/tmp'\'' (was unset when ReaR was launched)'
+ mkdir -p /var/tmp/rear.awoCzxeHag4tpr9/rootfs/var/tmp
+ BACKUP_PROG_EXCLUDE+=("$BUILD_DIR")
+ saved_tmpdir=/var/tmp

I think I found the root cause why there is no var/tmp
in the recreated system
(excerpt from /var/log/rear/rear-localhost.log)

+ source /usr/share/rear/restore/default/900_create_missing_directories.sh
++ local directories_permissions_owner_group_file=/var/lib/rear/recovery/directories_permissions_owner_group
++ test ''
++ pushd /mnt/local
/mnt/local ~
++ test -f /var/lib/rear/recovery/directories_permissions_owner_group
++ popd
~
+ source_return_code=0

i.e. restore/default/900_create_missing_directories.sh
that should recreate var/tmp in the recreated system
if it is missing does noting in my case because
in my case there is no
/var/lib/rear/recovery/directories_permissions_owner_group
because during "rear -D mkbackup" I had
(except from var/log/rear/rear-localhost.log
in a git clone directory)

2024-05-15 08:42:19.453890604 Including prep/default/400_save_directories.sh
2024-05-15 08:42:19.455467932 Entering debugscript mode via 'set -x'.
+ source /root/rear.lzaoral-backup-mounted-btrfs-subvolumes/usr/share/rear/prep/default/400_save_directories.sh
++ local directories_permissions_owner_group_file=/root/rear.lzaoral-backup-mounted-btrfs-subvolumes/var/lib/rear/recovery/directories_permissions_owner_group
++ :
/root/rear.lzaoral-backup-mounted-btrfs-subvolumes/usr/share/rear/prep/default/400_save_directories.sh: line 12: /root/rear.lzaoral-backup-mounted-btrfs-subvolumes/var/
lib/rear/recovery/directories_permissions_owner_group: No such file or directory

which is true at that point in time
when "rear mkrescue/mkbackup" is run for the first time
because $VAR_DIR/recovery/ is not yet created
when prep/default/400_save_directories.sh runs
because $VAR_DIR/recovery/ gets created later in
layout/save/GNU/Linux/100_create_layout_file.sh
(the 'prep' stage runs before the 'layout/save' stage).

@jsmeix
Copy link
Member

jsmeix commented May 15, 2024

I re-did "rear -D mkbackup"
but now additionally with the change in
#3223
and additionally with /.snapshots in BACKUP_PROG_EXCLUDE

BACKUP_PROG_EXCLUDE=( /var/tmp /qqq /var/tmp /tmp /.snapshots )

I also did

# rm -rf var/lib/rear/*

to verify that the change in
#3223
works.

After "rear -D mkbackup" I got in particular

# cat /var/tmp/rear.ml6GAML0RZ4F8e4/rootfs/root/rear.lzaoral-backup-mounted-btrfs-subvolumes/var/lib/rear/recovery/directories_permissions_owner_group
/.snapshots 750 root root
/boot/grub2/x86_64-efi 755 root root
/boot/grub2/i386-pc 755 root root
/home 755 root root
/opt 755 root root
/srv 755 root root
/tmp 1777 root root
/usr/local 755 root root
/root 700 root root
/var 755 root root
/bin 755 root root
/boot 755 root root
/dev 755 root root
/etc 755 root root
/etc/opt 755 root root
/etc/X11 755 root root
/lib 755 root root
/lib64 755 root root
/mnt 755 root root
/proc 555 root root
/run 755 root root
/sbin 755 root root
/sys 555 root root
/usr 755 root root
/usr/bin 755 root root
/usr/include 755 root root
/usr/lib 755 root root
/usr/lib64 755 root root
/usr/libexec 755 root root
/usr/sbin 755 root root
/usr/share 755 root root
/usr/src 755 root root
/var/cache 755 root root
/var/lib 755 root root
/var/lock -> /run/lock
/var/log 755 root root
/var/mail -> spool/mail
/var/opt 755 root root
/var/run -> /run
/var/spool 755 root root
/var/spool/mail 1777 root root
/var/tmp 1777 root root

note therein /.snapshots (because it is a mountpoint)
and /tmp and /var/tmp (because they are FHS directories).

With that I re-did "rear -D recover"

RESCUE localhost:~ # rear -D recover
Relax-and-Recover 2.7 / Git
Running rear recover (PID 758 date 2024-05-15 17:04:53)
Command line options: /bin/rear -D recover
Using log file: /var/log/rear/rear-localhost.log
Using build area: /var/tmp/rear.OAs2m4kG2emMuph
Setting TMPDIR to '/var/tmp' (was unset when ReaR was launched)
...
Recreating initrd with /usr/bin/dracut...
Recreated initrd with /usr/bin/dracut
...
Finished 'recover'. The target system is mounted at '/mnt/local'.

In the recreated sytem I got in particular

RESCUE localhost:~ # find /mnt/local/.snapshots/ -xdev -ls
 256 0 drwxr-x--- 1 root root   2 May 15 17:05 /mnt/local/.snapshots/
 257 0 drwxr-xr-x 1 root root  32 May 15 17:05 /mnt/local/.snapshots/1
 256 0 drwxr-xr-x 1 root root 188 May 15 17:05 /mnt/local/.snapshots/1/snapshot
 258 4 -rw------- 1 root root 168 May 15 17:05 /mnt/local/.snapshots/1/info.xml

which looks perfectly right now.

I rebooted the recreated system
and things look OK as far as I currently see

localhost:~ # snapper ls
 # | Type   | Pre # | Date                             | User | Used Space | Cleanup | Description           | Userdata
---+--------+-------+----------------------------------+------+------------+---------+-----------------------+---------
0  | single |       |                                  | root |            |         | current               |         
1* | single |       | Wed 15 May 2024 05:05:03 PM CEST | root |   2.26 GiB |         | first root filesystem |         

# cat /.snapshots/1/info.xml 
<?xml version="1.0"?>
<snapshot>
  <type>single</type>
  <num>1</num>
  <date>2024-05-15 15:05:03</date>
  <description>first root filesystem</description>
</snapshot>

(15:05:03 UTC equals 05:05:03 PM CEST)

@jsmeix
Copy link
Member

jsmeix commented May 15, 2024

@lzaoral
I think you cannot merge it yourself,
so perhaps @pcahyna could merge it for you?

Therefore I also assigned this pull request to him
so he could have another look and
merge it if it looks OK to him.

I could also merge it but I already reviewed it and
I would prefer when another ReaR upstream maintainer
gets also involved when a pull request gets merged.
Perhaps @pcahyna may spot something?

jsmeix added a commit that referenced this pull request May 15, 2024
Overhauled backup/NETFS/default/400_create_include_exclude_files.sh
* Now do first backup the mounted filesystems to backup '/' first
so the basic system files get stored first in the backup and
then backup what is specified in BACKUP_PROG_INCLUDE
see #3177 (comment)
and #3217 (comment)
* Report suspicious cases as LogPrintError to have the user at least informed.
* Remove duplicates in backup-[in/ex]clude.txt but keep the ordering
to avoid possibly unwanted and unexpected subtle consequences
see #3175 (comment)
* Verify that at least '/' is in backup-include.txt
see #3217
* Redirect stdout into files exactly at the command where needed
instead of more global redirections, cf. "horrible coding style"
in #3175 (comment)

Update backup/NETFS/default/500_make_backup.sh
* In backup/NETFS/default/500_make_backup.sh
unique_unsorted is no longer needed because
backup-include.txt is already without duplicates
because unique_unsorted is now called in
backup/NETFS/default/400_create_include_exclude_files.sh
@jsmeix
Copy link
Member

jsmeix commented May 15, 2024

Oops!
I forgot to test when one has other snapshot subvolumes mounted
(i.e. snapshot subvolumes that are not mounted at '/').
I will test that tomorrow.

@jsmeix
Copy link
Member

jsmeix commented May 16, 2024

Test when one has other snapshot subvolumes mounted
(i.e. snapshot subvolumes that are not mounted at '/')
on the same SLES15 SP5 tests VM as above in
#3175 (comment)

I mount btrfs snapshot 2 at /snapshot2 and
snapshot 3 two times at /snapshot3 and /snapshot3again

# btrfs subvolume list -a / | grep snapshots
ID 267 gen 3472 top level 256 path <FS_TREE>/@/.snapshots
ID 268 gen 3485 top level 267 path <FS_TREE>/@/.snapshots/1/snapshot
ID 272 gen 43 top level 267 path <FS_TREE>/@/.snapshots/2/snapshot
ID 273 gen 64 top level 267 path <FS_TREE>/@/.snapshots/3/snapshot
ID 274 gen 65 top level 267 path <FS_TREE>/@/.snapshots/4/snapshot

# mkdir /snapshot2
# mkdir /snapshot3
# mkdir /snapshot3again

# mount -t btrfs -o subvolid=272 /dev/sda2 /snapshot2
# mount -t btrfs -o subvolid=273 /dev/sda2 /snapshot3
# mount -t btrfs -o subvolid=273 /dev/sda2 /snapshot3again

# findmnt -at btrfs
TARGET                   SOURCE                              FSTYPE OPTIONS
/                        /dev/sda2[/@/.snapshots/1/snapshot] btrfs  rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot
|-/boot/grub2/x86_64-efi /dev/sda2[/@/boot/grub2/x86_64-efi] btrfs  rw,relatime,space_cache,subvolid=265,subvol=/@/boot/grub2/x86_64-efi
|-/srv                   /dev/sda2[/@/srv]                   btrfs  rw,relatime,space_cache,subvolid=261,subvol=/@/srv
|-/root                  /dev/sda2[/@/root]                  btrfs  rw,relatime,space_cache,subvolid=262,subvol=/@/root
|-/home                  /dev/sda2[/@/home]                  btrfs  rw,relatime,space_cache,subvolid=264,subvol=/@/home
|-/boot/grub2/i386-pc    /dev/sda2[/@/boot/grub2/i386-pc]    btrfs  rw,relatime,space_cache,subvolid=266,subvol=/@/boot/grub2/i386-pc
|-/.snapshots            /dev/sda2[/@/.snapshots]            btrfs  rw,relatime,space_cache,subvolid=267,subvol=/@/.snapshots
|-/var                   /dev/sda2[/@/var]                   btrfs  rw,relatime,space_cache,subvolid=258,subvol=/@/var
|-/opt                   /dev/sda2[/@/opt]                   btrfs  rw,relatime,space_cache,subvolid=263,subvol=/@/opt
|-/tmp                   /dev/sda2[/@/tmp]                   btrfs  rw,relatime,space_cache,subvolid=260,subvol=/@/tmp
|-/usr/local             /dev/sda2[/@/usr/local]             btrfs  rw,relatime,space_cache,subvolid=259,subvol=/@/usr/local
|-/snapshot2             /dev/sda2[/@/.snapshots/2/snapshot] btrfs  rw,relatime,space_cache,subvolid=272,subvol=/@/.snapshots/2/snapshot
|-/snapshot3             /dev/sda2[/@/.snapshots/3/snapshot] btrfs  rw,relatime,space_cache,subvolid=273,subvol=/@/.snapshots/3/snapshot
`-/snapshot3again        /dev/sda2[/@/.snapshots/3/snapshot] btrfs  rw,relatime,space_cache,subvolid=273,subvol=/@/.snapshots/3/snapshot

Did again "rear -D mkbackup" as before in
#3175 (comment)
in particular as before with

BACKUP_PROG_EXCLUDE=( /var/tmp /qqq /var/tmp /tmp /.snapshots )

i.e. without explicitly excluding the mounted btrfs snapshots.

backup.tar.gz size from before in
#3175 (comment)
was 2.1G and is now the same

disklayout.conf is now

# grep -v '^#' var/lib/rear/layout/disklayout.conf 
disk /dev/sda 16106127360 gpt
part /dev/sda 8388608 1048576 rear-noname bios_grub /dev/sda1
part /dev/sda 13949206528 9437184 rear-noname legacy_boot /dev/sda2
part /dev/sda 2147466752 13958643712 rear-noname swap /dev/sda3
fs /dev/sda2 / btrfs uuid=bdec53c2-1ee8-4268-90f9-5ec523774035 label= options=rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot
btrfsdefaultsubvol /dev/sda2 / 268 @/.snapshots/1/snapshot
btrfsnormalsubvol /dev/sda2 / 256 @
btrfsnormalsubvol /dev/sda2 / 258 @/var
btrfsnormalsubvol /dev/sda2 / 259 @/usr/local
btrfsnormalsubvol /dev/sda2 / 260 @/tmp
btrfsnormalsubvol /dev/sda2 / 261 @/srv
btrfsnormalsubvol /dev/sda2 / 262 @/root
btrfsnormalsubvol /dev/sda2 / 263 @/opt
btrfsnormalsubvol /dev/sda2 / 264 @/home
btrfsnormalsubvol /dev/sda2 / 265 @/boot/grub2/x86_64-efi
btrfsnormalsubvol /dev/sda2 / 266 @/boot/grub2/i386-pc
btrfsmountedsubvol /dev/sda2 / rw,relatime,space_cache,subvolid=268,subvol=/@/.snapshots/1/snapshot @/.snapshots/1/snapshot
btrfsmountedsubvol /dev/sda2 /.snapshots rw,relatime,space_cache,subvolid=267,subvol=/@/.snapshots @/.snapshots
btrfsmountedsubvol /dev/sda2 /boot/grub2/x86_64-efi rw,relatime,space_cache,subvolid=265,subvol=/@/boot/grub2/x86_64-efi @/boot/grub2/x86_64-efi
btrfsmountedsubvol /dev/sda2 /home rw,relatime,space_cache,subvolid=264,subvol=/@/home @/home
btrfsmountedsubvol /dev/sda2 /opt rw,relatime,space_cache,subvolid=263,subvol=/@/opt @/opt
btrfsmountedsubvol /dev/sda2 /boot/grub2/i386-pc rw,relatime,space_cache,subvolid=266,subvol=/@/boot/grub2/i386-pc @/boot/grub2/i386-pc
btrfsmountedsubvol /dev/sda2 /srv rw,relatime,space_cache,subvolid=261,subvol=/@/srv @/srv
btrfsmountedsubvol /dev/sda2 /root rw,relatime,space_cache,subvolid=262,subvol=/@/root @/root
btrfsmountedsubvol /dev/sda2 /tmp rw,relatime,space_cache,subvolid=260,subvol=/@/tmp @/tmp
btrfsmountedsubvol /dev/sda2 /usr/local rw,relatime,space_cache,subvolid=259,subvol=/@/usr/local @/usr/local
btrfsmountedsubvol /dev/sda2 /var rw,relatime,space_cache,subvolid=258,subvol=/@/var @/var
btrfsnocopyonwrite @/var
swap /dev/sda3 uuid=921157bc-e4d6-4869-8796-7e09207e49a9 label=

in particular the disabled btrfs entries

# grep '^#btrfs' var/lib/rear/layout/disklayout.conf 
#btrfssnapshotsubvol /dev/sda2 / 272 @/.snapshots/2/snapshot
#btrfssnapshotsubvol /dev/sda2 / 273 @/.snapshots/3/snapshot
#btrfssnapshotsubvol /dev/sda2 / 274 @/.snapshots/4/snapshot
#btrfsnormalsubvol /dev/sda2 / 267 @/.snapshots
#btrfsnormalsubvol /dev/sda2 / 268 @/.snapshots/1/snapshot
#btrfsmountedsubvol /dev/sda2 /snapshot2 rw,relatime,space_cache,subvolid=272,subvol=/@/.snapshots/2/snapshot @/.snapshots/2/snapshot
#btrfsmountedsubvol /dev/sda2 /snapshot3 rw,relatime,space_cache,subvolid=273,subvol=/@/.snapshots/3/snapshot @/.snapshots/3/snapshot
#btrfsmountedsubvol /dev/sda2 /snapshot3again rw,relatime,space_cache,subvolid=273,subvol=/@/.snapshots/3/snapshot @/.snapshots/3/snapshot

The only things that backup.tar.gz contains
regarding btrfs snapshots is (on the NFS server)

# tar -tvzf /nfs/localhost/backup.tar.gz
...
drwxr-xr-x root/root ... snapshot2/
drwxr-xr-x root/root ... snapshot3/
drwxr-xr-x root/root ... snapshot3again/

After "rear -D recover"
all looks well in particular

RESCUE localhost:~ # find /mnt/local/snapshot*      
/mnt/local/snapshot2
/mnt/local/snapshot3
/mnt/local/snapshot3again

Also 'df -h' looks well

RESCUE localhost:~ # df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.0M  8.0K  4.0M   1% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           783M  8.5M  775M   2% /run
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local/.snapshots
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local/boot/grub2/x86_64-efi
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local/home
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local/opt
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local/boot/grub2/i386-pc
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local/srv
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local/root
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local/tmp
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local/usr/local
/dev/sda2        13G  3.7G  9.1G  29% /mnt/local/var

for comparison on the original system

# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.0M     0  4.0M   0% /dev
tmpfs           983M  4.0K  983M   1% /dev/shm
tmpfs           394M  5.9M  388M   2% /run
tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
/dev/sda2        13G  4.5G  7.9G  37% /
/dev/sda2        13G  4.5G  7.9G  37% /.snapshots
/dev/sda2        13G  4.5G  7.9G  37% /boot/grub2/x86_64-efi
/dev/sda2        13G  4.5G  7.9G  37% /home
/dev/sda2        13G  4.5G  7.9G  37% /opt
/dev/sda2        13G  4.5G  7.9G  37% /boot/grub2/i386-pc
/dev/sda2        13G  4.5G  7.9G  37% /srv
/dev/sda2        13G  4.5G  7.9G  37% /root
/dev/sda2        13G  4.5G  7.9G  37% /tmp
/dev/sda2        13G  4.5G  7.9G  37% /usr/local
/dev/sda2        13G  4.5G  7.9G  37% /var
tmpfs           197M  4.0K  197M   1% /run/user/0
/dev/sda2        13G  4.5G  7.9G  37% /snapshot2
/dev/sda2        13G  4.5G  7.9G  37% /snapshot3

@jsmeix
Copy link
Member

jsmeix commented May 16, 2024

Mainly for my own information here
an addendum that is unrelated to this pull request
only because I noticed it here during my above
#3175 (comment)

In the recreated system '/tmp/' has wrong permissions
but '/var/tmp/' has right permissions

RESCUE localhost:~ # ls -ld /mnt/local/tmp/ /mnt/local/var/tmp/
drwxr-xr-x 1 root root 0 May 16 10:08 /mnt/local/tmp/
drwxrwxrwt 1 root root 0 May 16 10:09 /mnt/local/var/tmp/

for comparison on the original system

# ls -ld /tmp /var/tmp
drwxrwxrwt 1 root root 254 May 16 10:21 /tmp
drwxrwxrwt 1 root root 236 May 16 09:19 /var/tmp

Excepts from the "rear -D recover" log file

+ source /usr/share/rear/restore/default/900_create_missing_directories.sh
...
++ read directory mode owner group junk
++ test /tmp
++ directory=tmp
++ test '->' = 1777
++ test -e tmp
++ continue
...
++ read directory mode owner group junk
++ test /var/tmp
++ directory=var/tmp
++ test '->' = 1777
++ test -e var/tmp
++ test -L var/tmp
++ mkdir -v -p var/tmp
mkdir: created directory 'var/tmp'
++ test 1777
++ chmod -v 1777 var/tmp
mode of 'var/tmp' changed from 0755 (rwxr-xr-x) to 1777 (rwxrwxrwt)
++ test root
++ test root
++ chroot /mnt/local /bin/bash --login -c 'chown -v root:root var/tmp'
ownership of 'var/tmp' retained as root:root

In backup.tar.gz there is neither 'tmp' nor 'var/tmp'
so those directories are not restored from the backup
nevertheless /mnt/local/tmp/ gets somehow created
during "rear recover" but /mnt/local/var/tmp/ is not
created during "rear recover" so that
restore/default/900_create_missing_directories.sh
skips to create /mnt/local/tmp/
but creates /mnt/local/var/tmp/

I think I found the root cause why /mnt/local/tmp
is created during "rear recover"
(excerpts from /var/log/rear/rear-localhost.log)

++ for snapshot_subvolume_device_and_path in $snapshot_subvolumes_devices_and_paths
++ snapshot_subvolume_device=/dev/sda2
++ snapshot_subvolume_path=@/.snapshots/4/snapshot
++ test /dev/sda2 = /dev/sda2 -a @/tmp = @/.snapshots/4/snapshot
++ target_system_mountpoint=/mnt/local/tmp
++ test / = /tmp
++ Log 'Mounting btrfs normal subvolume @/tmp on /dev/sda2 at /tmp (if not something is already mounted there).'
2024-05-16 10:08:32.542234436 Mounting btrfs normal subvolume @/tmp on /dev/sda2 at /tmp (if not something is already mounted there).
++ echo '# Mounting btrfs normal subvolume @/tmp on /dev/sda2 at /mnt/local/tmp (if not something is already mounted there):'
++ echo 'if ! mount -t btrfs | tr -s '\''[:blank:]'\'' '\'' '\'' | grep -q '\'' on /mnt/local/tmp '\'' ; then'
++ echo '    if ! test -d /mnt/local/tmp ; then'
++ echo '        mkdir -p /mnt/local/tmp'
++ echo '    fi'
++ echo '    mount -t btrfs -o rw,relatime,space_cache -o subvol=@/tmp /dev/sda2 /mnt/local/tmp'
++ echo fi

so in .../var/lib/rear/layout/diskrestore.sh there is

# Mounting btrfs normal subvolume @/tmp on /dev/sda2 at /mnt/local/tmp (if not something is already mounted there):
if ! mount -t btrfs | tr -s '[:blank:]' ' ' | grep -q ' on /mnt/local/tmp ' ; then
    if ! test -d /mnt/local/tmp ; then
        mkdir -p /mnt/local/tmp
    fi
    mount -t btrfs -o rw,relatime,space_cache -o subvol=@/tmp /dev/sda2 /mnt/local/tmp
fi

This happens because on the original system there is

# findmnt -at btrfs
TARGET                   SOURCE                              FSTYPE OPTIONS
...
|-/tmp                   /dev/sda2[/@/tmp]                   btrfs  rw,relatime,space_cache,subvolid=260,subvol=/@/tmp

The cause is my

BACKUP_PROG_EXCLUDE=( /var/tmp /qqq /var/tmp /tmp /.snapshots )

and the root cause is my ignorance
to not read our fine documentation
in default.conf (excerpt)

# In /etc/rear/local.conf use BACKUP_PROG_EXCLUDE+=( '/this/*' '/that/*' )
# to specify your particular items that should be excluded from the backup in addition to what
# gets excluded from the backup by default here (see also BACKUP_ONLY_EXCLUDE below):
BACKUP_PROG_EXCLUDE=( '/tmp/*' '/dev/shm/*' "$VAR_DIR/output/*" )

so with

BACKUP_PROG_EXCLUDE+=( '/var/tmp/rear.*' /.snapshots )

all works reasonably well
and after "rear recover" I have

RESCUE localhost:~ # ls -ld /mnt/local/tmp/ /mnt/local/var/tmp/
drwxrwxrwt 1 root root   0 May 16 11:07 /mnt/local/tmp/
drwxrwxrwt 1 root root 156 May 16 11:15 /mnt/local/var/tmp/

because now in my backup.tar.gz there is

# tar -tvzf /nfs/localhost/backup.tar.gz | grep '[0-9] tmp'
drwxrwxrwt root/root           0 2024-05-16 11:07 tmp/
drwxrwxrwt root/root           0 2024-05-16 11:07 tmp/

# tar -tvzf /nfs/localhost/backup.tar.gz | grep '[0-9] var/tmp'
drwxrwxrwt root/root           0 2024-05-16 11:06 var/tmp/
drwx------ root/root           0 2024-05-16 08:31 var/tmp/systemd-private-c8620fb31f694e2ebf200b321b40aa8f-systemd-logind.service-9xVRrj/
drwxrwxrwt root/root           0 2024-05-16 08:31 var/tmp/systemd-private-c8620fb31f694e2ebf200b321b40aa8f-systemd-logind.service-9xVRrj/tmp/

so /tmp/ and /var/tmp/ get restored
with right permissions from the backup
and restore/default/900_create_missing_directories.sh
skips both /tmp/ and /var/tmp/

But because of this I found out that /var/tmp/rear.*
should be added to BACKUP_PROG_EXCLUDE in default.conf
because since ReaR uses /var/tmp/rear.* as BUILD_DIR
one gets at least the whole BUILD_DIR of the current
"rear mkbackup" run in the backup by default.

Via
#3224
'/var/tmp/rear.*' will be added to BACKUP_PROG_EXCLUDE
in default.conf

jsmeix added a commit that referenced this pull request May 16, 2024
In default.conf add '/var/tmp/rear.*' to BACKUP_PROG_EXCLUDE
because since ReaR uses /var/tmp/rear.* as BUILD_DIR
one would get at least the whole BUILD_DIR
of the current "rear mkbackup" run
in the backup by default,
see at the end of
#3175 (comment)
jsmeix added a commit that referenced this pull request May 16, 2024
In default.conf add '/var/tmp/rear.*' to BACKUP_PROG_EXCLUDE
because since ReaR uses /var/tmp/rear.* as BUILD_DIR
one would get at least the whole BUILD_DIR
of the current "rear mkbackup" run
in the backup by default,
see at the end of
#3175 (comment)
Additionally describe why ReaR's VAR_DIR/output is excluded.
Also describe why the '/directory/*' form is used.
@lzaoral
Copy link
Contributor Author

lzaoral commented May 17, 2024

@jsmeix No worries, the exclusion of snapper base subvolume is quite simple. Could you please test the following patch on SLES? Thank you!

diff --git a/usr/share/rear/layout/save/GNU/Linux/230_filesystem_layout.sh b/usr/share/rear/layout/save/GNU/Linux/230_filesystem_layout.sh
index cdeca6de..d34a4881 100644
--- a/usr/share/rear/layout/save/GNU/Linux/230_filesystem_layout.sh
+++ b/usr/share/rear/layout/save/GNU/Linux/230_filesystem_layout.sh
@@ -467,12 +467,14 @@ fi
                 # see https://btrfs.wiki.kernel.org/index.php/Mount_options
                 test "/" != "$btrfs_subvolume_path" && btrfs_subvolume_path=${btrfs_subvolume_path#/}

+                # Automatically exclude all mounted snapper and snapshot subvolumes from the backup.
+                # See https://github.com/rear/rear/pull/3175#issuecomment-1983498175 and
+                # https://github.com/rear/rear/pull/3175#issuecomment-2111776529
+                if test "$snapper_base_subvolume" = "$btrfs_subvolume_path" || btrfs_snapshot_subvolume_exists "$subvolume_mountpoint" "$btrfs_subvolume_path"; then
+                    echo "#btrfsmountedsubvol $device $subvolume_mountpoint $mount_options $btrfs_subvolume_path"
                 # Finally, test whether the btrfs subvolume listed as mounted actually exists. A running docker
                 # daemon apparently can convince the system to list a non-existing btrfs volume as mounted.
                 # See https://github.com/rear/rear/issues/1496
-                if btrfs_snapshot_subvolume_exists "$subvolume_mountpoint" "$btrfs_subvolume_path"; then
-                    # Exclude mounted snapshot subvolumes
-                    echo "#btrfsmountedsubvol $device $subvolume_mountpoint $mount_options $btrfs_subvolume_path"
                 elif btrfs_subvolume_exists "$subvolume_mountpoint" "$btrfs_subvolume_path"; then
                     echo "btrfsmountedsubvol $device $subvolume_mountpoint $mount_options $btrfs_subvolume_path"
                 else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adaptions and new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants