Changeset 3744


Ignore:
Timestamp:
Nov 18, 2019, 12:32:44 PM (3 months ago)
Author:
Bruno Cornec
Message:

Only handle btrfs subvol when there are some

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi/mindi

    r3740 r3744  
    14471447    LogAll "-----------------------------------"
    14481448
    1449     # Manages btrfs subvol partitions so they can be restored
    1450     # List looks like this
    1451     # ID 257 gen 20074 top level 5 path <FS_TREE>/@
    1452     # ID 260 gen 19927 top level 257 path @/home
    1453     # ID 261 gen 19927 top level 257 path @/opt
    1454     touch $MINDI_TMP/create-btrfs-subvol $MINDI_TMP/mount-btrfs-subvol $MINDI_TMP/umount-btrfs-subvol
    1455     btrfs subvolume list -a / 2>/dev/null > $MINDI_TMP/btrfssubvol.txt
    1456     LogFile "btrfs subvolumes layout is:"
    1457     LogFile "---------------------------"
    1458     cat $MINDI_TMP/btrfssubvol.txt  >> $LOGFILE
    1459     LogFile "---------------------------"
    1460     grep -E 'btrfs[     ]+subvol=' /etc/fstab > $MINDI_TMP/btrfs-extract
    1461     LogFile "btrfs subvolumes referenced in fstab:"
    1462     LogFile "-------------------------------------"
    1463     cat $MINDI_TMP/btrfs-extract >> $LOGFILE
    1464     LogFile "-------------------------------------"
    1465     # We suppose there is only one FS
    1466     sep=`btrfs subvolume list -a / | grep FS_TREE | sed 's/.*<FS_TREE>\/\(.*\)/\1/'`
    1467     echo "btrfs subvolume create /mnt/RESTORING/$sep" >> $MINDI_TMP/create-btrfs-subvol
    1468     while read dev mp type opt dum dum; do
    1469         echo $dev | grep -qE 'UUID|LABEL'
    1470         if [ $? -eq 0 ]; then
    1471             label=`echo $dev | cut -d= -f2`
    1472             device=`grep $label $mountlist | awk '{print $1}'`
    1473         else
    1474             device=$dev
    1475         fi
    1476         subvol=`echo $opt | awk -F$sep '{ print $2 }' | cut -d, -f1`
    1477         #top=`grep -E "@$subvol$" $MINDI_TMP/btrfssubvol.txt | awk '{ print $7 }'`
    1478         #btrfs=`grep -E "^ID $top " $MINDI_TMP/btrfssubvol.txt | awk '{ print $9 }' | sed 's/<FS_TREE>//' | sed 's/@$//'`
    1479         mountpoint="/mnt/RESTORING/$sep$subvol"
    1480         # If the intermediate dirs of subvol are not a subvolume, we need to create them as dir
    1481         parent=`dirname $subvol`
    1482         grep -qE "$sep$parent$" $MINDI_TMP/btrfssubvol.txt
    1483         if [ $? -ne 0 ]; then
    1484             echo "mkdir -p /mnt/RESTORING/$sep$parent" >> $MINDI_TMP/create-btrfs-subvol
    1485         fi
    1486         echo "btrfs subvolume create $mountpoint" >> $MINDI_TMP/create-btrfs-subvol
    1487         echo "mount -t btrfs -o subvol=$sep$subvol $device $mountpoint" >> $MINDI_TMP/mount-btrfs-subvol
    1488         echo "umount $mountpoint" >> $MINDI_TMP/umount-btrfs-subvol
    1489     done <  $MINDI_TMP/btrfs-extract
    1490     rm -f  $MINDI_TMP/btrfs-extract
    1491     chmod 755 $MINDI_TMP/create-btrfs-subvol $MINDI_TMP/mount-btrfs-subvol $MINDI_TMP/umount-btrfs-subvol
    1492     LogFile "Your create-btrfs-subvol file content is:"
    1493     LogFile "-----------------------------------------"
    1494     cat $MINDI_TMP/create-btrfs-subvol  >> $LOGFILE
    1495     LogFile "-----------------------------------------"
    1496     LogFile "Your mount-btrfs-subvol file content is:"
    1497     LogFile "-----------------------------------------"
    1498     cat $MINDI_TMP/mount-btrfs-subvol  >> $LOGFILE
    1499     LogFile "-----------------------------------------"
    1500     LogFile "Your umount-btrfs-subvol file content is:"
    1501     LogFile "-----------------------------------------"
    1502     cat $MINDI_TMP/umount-btrfs-subvol  >> $LOGFILE
    1503     LogFile "-----------------------------------------"
     1449    # Manages potential btrfs subvol partitions so they can be restored
     1450    grep -qE 'btrfs[    ]+subvol=' $MY_FSTAB
     1451    if [ $? -eq 0 ]; then
     1452        # List looks like this
     1453        # ID 257 gen 20074 top level 5 path <FS_TREE>/@
     1454        # ID 260 gen 19927 top level 257 path @/home
     1455        # ID 261 gen 19927 top level 257 path @/opt
     1456        touch $MINDI_TMP/create-btrfs-subvol $MINDI_TMP/mount-btrfs-subvol $MINDI_TMP/umount-btrfs-subvol
     1457        btrfs subvolume list -a / 2>/dev/null > $MINDI_TMP/btrfssubvol.txt
     1458        LogFile "btrfs subvolumes layout is:"
     1459        LogFile "---------------------------"
     1460        cat $MINDI_TMP/btrfssubvol.txt  >> $LOGFILE
     1461        LogFile "---------------------------"
     1462        grep -E 'btrfs[     ]+subvol=' $MY_FSTAB > $MINDI_TMP/btrfs-extract
     1463        LogFile "btrfs subvolumes referenced in fstab:"
     1464        LogFile "-------------------------------------"
     1465        cat $MINDI_TMP/btrfs-extract >> $LOGFILE
     1466        LogFile "-------------------------------------"
     1467        # We suppose there is only one FS
     1468        sep=`btrfs subvolume list -a / | grep FS_TREE | sed 's/.*<FS_TREE>\/\(.*\)/\1/'`
     1469        echo "btrfs subvolume create /mnt/RESTORING/$sep" >> $MINDI_TMP/create-btrfs-subvol
     1470        while read dev mp type opt dum dum; do
     1471            echo $dev | grep -qE 'UUID|LABEL'
     1472            if [ $? -eq 0 ]; then
     1473                label=`echo $dev | cut -d= -f2`
     1474                device=`grep $label $mountlist | awk '{print $1}'`
     1475            else
     1476                device=$dev
     1477            fi
     1478            subvol=`echo $opt | awk -F$sep '{ print $2 }' | cut -d, -f1`
     1479            #top=`grep -E "@$subvol$" $MINDI_TMP/btrfssubvol.txt | awk '{ print $7 }'`
     1480            #btrfs=`grep -E "^ID $top " $MINDI_TMP/btrfssubvol.txt | awk '{ print $9 }' | sed 's/<FS_TREE>//' | sed 's/@$//'`
     1481            mountpoint="/mnt/RESTORING/$sep$subvol"
     1482            # If the intermediate dirs of subvol are not a subvolume, we need to create them as dir
     1483            parent=`dirname $subvol`
     1484            grep -qE "$sep$parent$" $MINDI_TMP/btrfssubvol.txt
     1485            if [ $? -ne 0 ]; then
     1486                echo "mkdir -p /mnt/RESTORING/$sep$parent" >> $MINDI_TMP/create-btrfs-subvol
     1487            fi
     1488            echo "btrfs subvolume create $mountpoint" >> $MINDI_TMP/create-btrfs-subvol
     1489            echo "mount -t btrfs -o subvol=$sep$subvol $device $mountpoint" >> $MINDI_TMP/mount-btrfs-subvol
     1490            echo "umount $mountpoint" >> $MINDI_TMP/umount-btrfs-subvol
     1491        done <  $MINDI_TMP/btrfs-extract
     1492        rm -f  $MINDI_TMP/btrfs-extract
     1493        chmod 755 $MINDI_TMP/create-btrfs-subvol $MINDI_TMP/mount-btrfs-subvol $MINDI_TMP/umount-btrfs-subvol
     1494        LogFile "Your create-btrfs-subvol file content is:"
     1495        LogFile "-----------------------------------------"
     1496        cat $MINDI_TMP/create-btrfs-subvol  >> $LOGFILE
     1497        LogFile "-----------------------------------------"
     1498        LogFile "Your mount-btrfs-subvol file content is:"
     1499        LogFile "-----------------------------------------"
     1500        cat $MINDI_TMP/mount-btrfs-subvol  >> $LOGFILE
     1501        LogFile "-----------------------------------------"
     1502        LogFile "Your umount-btrfs-subvol file content is:"
     1503        LogFile "-----------------------------------------"
     1504        cat $MINDI_TMP/umount-btrfs-subvol  >> $LOGFILE
     1505        LogFile "-----------------------------------------"
     1506    fi
    15041507}
    15051508
Note: See TracChangeset for help on using the changeset viewer.