Blame SOURCES/rear-bz2131946.patch

c31218
diff --git a/usr/share/rear/layout/prepare/GNU/Linux/131_include_filesystem_code.sh b/usr/share/rear/layout/prepare/GNU/Linux/131_include_filesystem_code.sh
c31218
index 172ac032..9cff63a0 100644
c31218
--- a/usr/share/rear/layout/prepare/GNU/Linux/131_include_filesystem_code.sh
c31218
+++ b/usr/share/rear/layout/prepare/GNU/Linux/131_include_filesystem_code.sh
c31218
@@ -143,9 +143,9 @@ function create_fs () {
c31218
             # unless the user has explicitly specified XFS filesystem options:
c31218
             local xfs_opts
c31218
             local xfs_device_basename="$( basename $device )"
c31218
-            local xfs_info_filename="$LAYOUT_XFS_OPT_DIR/$xfs_device_basename.xfs"
c31218
+            local xfs_info_filename="$LAYOUT_XFS_OPT_DIR_RESTORE/$xfs_device_basename.xfs"
c31218
             # Only uppercase letters and digits are used to ensure mkfs_xfs_options_variable_name is a valid bash variable name
c31218
-            # even in case of complicated device nodes e.g. things like /dev/mapper/SIBM_2810XIV_78033E7012F-part3 
c31218
+            # even in case of complicated device nodes e.g. things like /dev/mapper/SIBM_2810XIV_78033E7012F-part3
c31218
             # cf. current_orig_device_basename_alnum_uppercase in layout/prepare/default/300_map_disks.sh
c31218
             local xfs_device_basename_alnum_uppercase="$( echo $xfs_device_basename | tr -d -c '[:alnum:]' | tr '[:lower:]' '[:upper:]' )"
c31218
             # cf. predefined_input_variable_name in the function UserInput in lib/_input-output-functions.sh
c31218
diff --git a/usr/share/rear/layout/prepare/default/010_prepare_files.sh b/usr/share/rear/layout/prepare/default/010_prepare_files.sh
c31218
index 85964712..7a980e63 100644
c31218
--- a/usr/share/rear/layout/prepare/default/010_prepare_files.sh
c31218
+++ b/usr/share/rear/layout/prepare/default/010_prepare_files.sh
c31218
@@ -5,6 +5,7 @@ LAYOUT_DEPS="$VAR_DIR/layout/diskdeps.conf"
c31218
 LAYOUT_TODO="$VAR_DIR/layout/disktodo.conf"
c31218
 LAYOUT_CODE="$VAR_DIR/layout/diskrestore.sh"
c31218
 LAYOUT_XFS_OPT_DIR="$VAR_DIR/layout/xfs"
c31218
+LAYOUT_XFS_OPT_DIR_RESTORE="$LAYOUT_XFS_OPT_DIR/restore"
c31218
 
c31218
 FS_UUID_MAP="$VAR_DIR/layout/fs_uuid_mapping"
c31218
 LUN_WWID_MAP="$VAR_DIR/layout/lun_wwid_mapping"
c31218
diff --git a/usr/share/rear/layout/prepare/default/319_rename_xfs_configs.sh b/usr/share/rear/layout/prepare/default/319_rename_xfs_configs.sh
c31218
new file mode 100644
c31218
index 00000000..406afa61
c31218
--- /dev/null
c31218
+++ b/usr/share/rear/layout/prepare/default/319_rename_xfs_configs.sh
c31218
@@ -0,0 +1,83 @@
c31218
+# Cleanup directory which hold XFS configuration file for `rear recover'.
c31218
+# This will avoid possible mess in LAYOUT_XFS_OPT_DIR_RESTORE if `rear recover'
c31218
+# would be launched multiple times, where user will choose different disk
c31218
+# mapping each time.
c31218
+# Removing and creating LAYOUT_XFS_OPT_DIR_RESTORE will ensure that ReaR will
c31218
+# have only current files available during current session.
c31218
+rm -rf "$LAYOUT_XFS_OPT_DIR_RESTORE"
c31218
+mkdir -p "$LAYOUT_XFS_OPT_DIR_RESTORE"
c31218
+
c31218
+local excluded_configs=()
c31218
+
c31218
+# Read $MAPPING_FILE (disk_mappings) to discover final disk mapping.
c31218
+# Once mapping is known, configuration files can be renamed.
c31218
+# (e.g. sds2.xfs to sdb2.xfs, ...)
c31218
+while read source target junk ; do
c31218
+    # Disks in MAPPING_FILE are listed with full device path. Since XFS config
c31218
+    # files are created in format e.g. sda2.xfs strip prefixed path to have
c31218
+    # only short device name available.
c31218
+    base_source=$(basename "$source")
c31218
+    base_target=$(basename "$target")
c31218
+
c31218
+    # Check if XFS configuration file for whole device (unpartitioned)
c31218
+    # is available (sda, sdb, ...). If so, rename and copy it to
c31218
+    # LAYOUT_XFS_OPT_DIR_RESTORE.
c31218
+    if [ -e "$LAYOUT_XFS_OPT_DIR/$base_source.xfs" ]; then
c31218
+        Log "Migrating XFS configuration file $base_source.xfs to $base_target.xfs"
c31218
+        cp "$v" "$LAYOUT_XFS_OPT_DIR/$base_source.xfs" \
c31218
+         "$LAYOUT_XFS_OPT_DIR_RESTORE/$base_target.xfs"
c31218
+
c31218
+        # Replace old device name in meta-data= option in XFS
c31218
+        # configuration file as well.
c31218
+        sed -i s#"meta-data=${source}\(\s\)"#"meta-data=${target}\1"# \
c31218
+          "$LAYOUT_XFS_OPT_DIR_RESTORE/$base_target.xfs"
c31218
+
c31218
+        # Mark XFS config file as processed to avoid copying it again later.
c31218
+        # More details on why are configs excluded can be found near the
c31218
+        # end of this script (near `tar' command).
c31218
+        excluded_configs+=("--exclude=$base_source.xfs")
c31218
+    fi
c31218
+
c31218
+    # Find corresponding partitions to source disk in LAYOUT_FILE
c31218
+    # and migrate/rename them too if necessary.
c31218
+    while read _ layout_device _ _ _ _ layout_partition; do
c31218
+        if [[ "$source" = "$layout_device" ]]; then
c31218
+            base_src_layout_partition=$(basename "$layout_partition")
c31218
+            base_dst_layout_partition=${base_src_layout_partition//$base_source/$base_target}
c31218
+            dst_layout_partition=${layout_partition//$base_source/$base_target}
c31218
+
c31218
+            if [ -e "$LAYOUT_XFS_OPT_DIR/$base_src_layout_partition.xfs" ]; then
c31218
+                Log "Migrating XFS configuration $base_src_layout_partition.xfs to $base_dst_layout_partition.xfs"
c31218
+                cp "$v" "$LAYOUT_XFS_OPT_DIR/$base_src_layout_partition.xfs" \
c31218
+                 "$LAYOUT_XFS_OPT_DIR_RESTORE/$base_dst_layout_partition.xfs"
c31218
+
c31218
+                # Replace old device name in meta-data= option in XFS
c31218
+                # configuration file as well.
c31218
+                sed -i s#"meta-data=${layout_partition}\(\s\)"#"meta-data=${dst_layout_partition}\1"# \
c31218
+                  "$LAYOUT_XFS_OPT_DIR_RESTORE/$base_dst_layout_partition.xfs"
c31218
+
c31218
+                # Mark XFS config file as processed to avoid copying it again later.
c31218
+                # More details on why are configs excluded can be found near the
c31218
+                # end of this script (near `tar' command).
c31218
+                excluded_configs+=("--exclude=$base_src_layout_partition.xfs")
c31218
+            fi
c31218
+        fi
c31218
+    done < <( grep -E "^part " "$LAYOUT_FILE" )
c31218
+done < <( grep -v '^#' "$MAPPING_FILE" )
c31218
+
c31218
+pushd "$LAYOUT_XFS_OPT_DIR" >/dev/null
c31218
+# Copy remaining files
c31218
+# We need to copy remaining files into LAYOUT_XFS_OPT_DIR_RESTORE which will
c31218
+# serve as base dictionary where ReaR will look for XFS config files.
c31218
+# It is necessary to copy only files that were not previously processed,
c31218
+# because in LAYOUT_XFS_OPT_DIR they are still listed with
c31218
+# original name and copy to LAYOUT_XFS_OPT_DIR_RESTORE could overwrite
c31218
+# XFS configs already migrated.
c31218
+# e.g. with following disk mapping situation:
c31218
+# /dev/sda2 => /dev/sdb2
c31218
+# /dev/sdb2 => /dev/sda2
c31218
+# Files in LAYOUT_XFS_OPT_DIR_RESTORE would be overwritten by XFS configs with
c31218
+# wrong names.
c31218
+# tar is used to take advantage of its exclude feature.
c31218
+tar cf - --exclude=restore "${excluded_configs[@]}" . | tar xfp - -C "$LAYOUT_XFS_OPT_DIR_RESTORE"
c31218
+popd >/dev/null
c31218
diff --git a/usr/share/rear/layout/save/GNU/Linux/100_create_layout_file.sh b/usr/share/rear/layout/save/GNU/Linux/100_create_layout_file.sh
c31218
index 7895e4ee..fc0fa8fc 100644
c31218
--- a/usr/share/rear/layout/save/GNU/Linux/100_create_layout_file.sh
c31218
+++ b/usr/share/rear/layout/save/GNU/Linux/100_create_layout_file.sh
c31218
@@ -10,6 +10,7 @@ mkdir -p $v $VAR_DIR/layout/config
c31218
 # We need directory for XFS options only if XFS is in use:
c31218
 if test "$( mount -t xfs )" ; then
c31218
     LAYOUT_XFS_OPT_DIR="$VAR_DIR/layout/xfs"
c31218
+    rm -rf $LAYOUT_XFS_OPT_DIR
c31218
     mkdir -p $v $LAYOUT_XFS_OPT_DIR
c31218
 fi
c31218