mount or umount a group filesystem in a SAN cluster environment

In a large SAN cluster environment, it's quicker and safer to have a script to manage a node filesystem. In most of case, each node has its own auto mount entry in /etc/fstab. What about its parter node? In case of the node goest down for some reason, the parter node needs to be ready to mount/umount its peer's a set of file systems.

You can do it manually, or use professional tool to manage, for me I use my own script, it's simple and quicker.

Prepare the node and filesystem mapping file

One each node, get a file called /etc/fstab.dcs, where it has 3 columns.

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

Here is the script for mounting.

I named it xfs_mount.sh, rename it in your way

Usage:
  xfs_mount -doit -p <nodename> -h
     -doit  means really execute, otherwise show you commands it would execute
     -p  which nodes filesystems you need to mount on this node, default is the host itself

#!/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, the useage is same as xfs_mount.sh

I call it xfs_umount.sh

#!/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