Linux‎ > ‎

mount or umount a group filesystem in a SAN environment

Thank you for visiting this page, this page has been update in another link mount or umount a group filesystem in a SAN environment
In a large SAN setup environment, it's quicker and safer to have a script to manage a node filesystem. For sure, each node has its own auto mount entry in /etc/fstab, but for backup purpose, you have backup node ready to mount/umount its peer's a set of file systems for emergency situation

Here is what I do.
One each node, get a file called /etc/fstab.dcs, where it has 3 columns.

<node> </dev/mapper/device> <fs_mount_point>

#!/bin/bash

doit="false"
while [ $1 ] ; do
  case $1 in
    '-doit') doit="true";;
       '-p') shift;nodename=$1;;
       '-h') echo "$0 [-doit] [-p <nodename>] [-h]";;
          *) ;;
  esac
  shift
done

if [ "$nodename" != "" ] ; then
  for fs in `grep $nodename /etc/fstab.dcs | awk '{print $3}'`
  {
    grep -q $fs /etc/fstab
    if [ $? -eq 0 ] ; then
      grep -q $fs /etc/mtab
      if [ $? -ne 0 ] ; then
        if [ "$doit" = "true" ] ; then
          echo mount $fs on `/bin/hostname`
          mount $fs
        else
          echo DEBUG: would mount $fs
        fi
      fi
    fi
  }
else
  echo "mounting"
  for fs in `grep xfs /etc/fstab|grep -v noauto |awk '{print $2}'`
  {
    if [ "$fs" != "" ] ; then
      grep -q $fs /etc/mtab
      if [ $? -ne 0 ] ; then
        if [ "$doit" = "true" ] ; then
          echo mount $fs on `/bin/hostname`
          mount $fs
        else
          echo DEBUG: would mount $fs
        fi
      fi
    fi
  }
fi



Here is one for umounting.

#!/bin/bash

doit="false"
while [ $1 ] ; do
  case $1 in
    '-doit') doit="true";;
       '-p') shift;nodename=$1;;
       '-h') echo "$0 [-doit] [-p <nodename>] [-h]";;
          *) ;;
  esac
  shift
done
echo "nodename:"$nodename
if [ "$nodename" != "" ] ; then
  for fs in `grep $nodename /etc/fstab.dcs | awk '{print $3}'`
  {
    grep -q $fs /etc/fstab
    if [ $? -eq 0 ] ; then
      grep -q $fs /etc/mtab
      if [ $? -eq 0 ] ; then
        if [ "$doit" = "true" ] ; then
          echo umount $fs on `/bin/hostname`
          umount $fs
        else
          echo DEBUG: would umount $fs
        fi
      fi
    fi
  }
else
  echo "umounting"
  for fs in `grep xfs /etc/fstab|grep -v noauto |awk '{print $2}'`
  {
    if [ "$fs" != "" ] ; then
      grep -q $fs /etc/mtab
      if [ $? -eq 0 ] ; then
        if [ "$doit" = "true" ] ; then
          echo umount $fs on `/bin/hostname`
          umount $fs
        else
          echo DEBUG: would umount $fs
        fi
      fi
    fi
  }
fi




Comments