Pārlūkot izejas kodu

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

Dan Helfman 4 mēneši atpakaļ
vecāks
revīzija
f183800009

+ 1 - 0
NEWS

@@ -9,6 +9,7 @@
  * #962: Under the hood, merge all configured source directories, excludes, and patterns into a
  * #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
    unified temporary patterns file for passing to Borg. The borgmatic configuration options remain
    unchanged.
    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
  * #965: Fix a borgmatic runtime directory error when running the "spot" check with a database hook
    enabled.
    enabled.
  * Fix the "spot" check to no longer consider pipe files within an archive for file comparisons.
  * 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 ())
     candidate_patterns = set(patterns or ())
 
 
     try:
     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(
         return tuple(
             Logical_volume(device['name'], device['path'], device['mountpoint'], contained_patterns)
             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'
             if device['mountpoint'] and device['type'] == 'lvm'
             for contained_patterns in (
             for contained_patterns in (
                 borgmatic.hooks.data_source.snapshot.get_contained_patterns(
                 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
 <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.
 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
 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
 includes the snapshotted files in the paths sent to Borg. borgmatic is also responsible for cleaning
 up (deleting) these snapshots after a backup completes.
 up (deleting) these snapshots after a backup completes.