Blame SOURCES/rear-bz2131946.patch

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