#!/bin/bash
# Creating Shadow Copies
# The snapshot name used in the mount path
SNAP=Snap1
# removing symlinks
for link in $( find /export/share -maxdepth 2 -type l ); do
if [[ `readlink $link` =~ "^/export/snaps/${SNAP}.*" ]]; then
rm $link
fi
done
# remove My Documents links
for link in $( find /export/homes -maxdepth 3 -type l ); do
if [[ `readlink $link` =~ "^/export/snaps/${SNAP}.*" ]]; then
rm $link
fi
done
echo "symlinks deleted..."
# end of deleting links
#### This is where your code would go for removing the old snapshot and creating a new one
#### I use a proprietary app called admsnap to do this, so this part of my script would
#### not do most people any good unless they owned an EMC Clariion CX300.
SHADOWNAME=`date -u +%Y.%m.%d-%H.%M.%S`
echo "creating the plethora of symlinks..."
# "share" nested mappings
for directory in $( find /export/share -maxdepth 1 -type d ); do
TARGET=`echo $directory | sed "s/^\/export\/share/\/export\/snaps\/${SNAP}\/share/"`
ln -s $TARGET ${directory}/@GMT-$SHADOWNAME
done
# the redirected My Documents directories
for directory in $( find /export/homes -maxdepth 2 -type d ); do
TARGET=`echo $directory | sed "s/^\/export\/homes/\/export\/snaps\/${SNAP}\/homes/"`
ln -s $TARGET ${directory}/@GMT-$SHADOWNAME
done
echo "links created..."
echo "done."