Blame SOURCES/rear-bz2131946.patch

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