Browse Source

For the LVM hook, add support for nested logical volumes (#962).

Dan Helfman 4 months ago
parent
commit
f183800009
3 changed files with 11 additions and 3 deletions
  1. 1 0
      NEWS
  2. 8 1
      borgmatic/hooks/data_source/lvm.py
  3. 2 2
      docs/how-to/snapshot-your-filesystems.md

+ 1 - 0
NEWS

@@ -9,6 +9,7 @@
  * #962: Under the hood, merge all configured source directories, excludes, and patterns into a
    unified temporary patterns file for passing to Borg. The borgmatic configuration options remain
    unchanged.
+ * #962: For the LVM hook, add support for nested logical volumes.
  * #965: Fix a borgmatic runtime directory error when running the "spot" check with a database hook
    enabled.
  * Fix the "spot" check to no longer consider pipe files within an archive for file comparisons.

+ 8 - 1
borgmatic/hooks/data_source/lvm.py

@@ -56,9 +56,16 @@ def get_logical_volumes(lsblk_command, patterns=None):
     candidate_patterns = set(patterns or ())
 
     try:
+        # Sort from longest to shortest mount points, so longer mount points get a whack at the
+        # candidate pattern piñata before their parents do. (Patterns are consumed below, so no two
+        # logical volumes end up with the same contained patterns.)
         return tuple(
             Logical_volume(device['name'], device['path'], device['mountpoint'], contained_patterns)
-            for device in devices_info['blockdevices']
+            for device in sorted(
+                devices_info['blockdevices'],
+                key=lambda device: device['mountpoint'] or '',
+                reverse=True,
+            )
             if device['mountpoint'] and device['type'] == 'lvm'
             for contained_patterns in (
                 borgmatic.hooks.data_source.snapshot.get_contained_patterns(

+ 2 - 2
docs/how-to/snapshot-your-filesystems.md

@@ -254,8 +254,8 @@ borgmatic's `source_directories` option.
 <span class="minilink minilink-addedin">New in version 1.9.6</span> Or include
 the mount point with borgmatic's `patterns` or `patterns_from` options.
 
-During a backup, borgmatic automatically snapshots these discovered logical volumes, temporarily
-mounts the snapshots within its [runtime
+During a backup, borgmatic automatically snapshots these discovered logical volumes
+(non-recursively), temporarily mounts the snapshots within its [runtime
 directory](https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#runtime-directory), and
 includes the snapshotted files in the paths sent to Borg. borgmatic is also responsible for cleaning
 up (deleting) these snapshots after a backup completes.