[Samba] script for VFS module shadow_copy

James A. Dinkel jdinkel at bucoks.com
Fri Nov 17 14:34:29 GMT 2006

Here's my script for rotating shadow copy snapshots.  Just submitting it
for other's benefit.  I use the admsnap command because this is attached
to am EMC Clarion CX300 and I wanted to use the snapshot abilities on
the CX300 instead of lvm snapshots, but it can probably be easily
adapted to use the lvm snapshot commands instead.

A little info on the script:  In order to do addition snapshots, I copy
this file and change the Snap#, Session#, and /dev/sdX.  The first time
the script is run, it will give some errors about destroying the old
stuff, but it still creates the new stuff fine and subsequent runs go
without errors.  Also be sure you've created the mount folder
beforehand.  I had to use symlinks because the share is not the root of
the volume.  I didn't want to use the root of the volume because I have
multiple shares that I want stored on this volume (/export is the root
of this volume, by the way).  To keep track of what symlink needs to be
destroyed, a variable is written to a file and then read from the file
next time as the old name.
# Creating Shadow Copies

# remove the old shadow copy
umount -f /dev/sdc1
/usr/admsnap/admsnap deactivate -s Session1
/usr/admsnap/admsnap stop -s Session1 -o /dev/sdb

# remove the old symlink
read OLDSHADOW </etc/samba/SnapScripts/.Session1Name
rm -f /export/share/@GMT-$OLDSHADOW

# create a new shadow copy
SHADOWNAME=`date -u +%Y.%m.%d-%H.%M.%S`
/usr/admsnap/admsnap flush -o /dev/sdb
/usr/admsnap/admsnap start -s Session1 -o /dev/sdb -p
/usr/admsnap/admsnap activate -s Session1 -o /dev/sdc
mount /dev/sdc1 /export/snaps/Snap1 -o ro,acl,user_xattr
ln -s /export/snaps/Snap1/share /export/share/@GMT-$SHADOWNAME

# store the new shadowname in a file
echo $SHADOWNAME > /etc/samba/SnapScripts/.Session1Name

Some improvements that could be made:  I should use variables for the
Snap and Session number and for the /dev name.  I could then define the
variables at the beginning which would make this easy to duplicate, or
have the variables passed to the script at the commandline (don't
especially like this though, since I'm limited to only 8 snapshots on a
CX300 anyway).  Putting in these variables would be easy, I just haven't
done it and tested it yet.

I would also like to put the $SHADOWNAME into the mount location, so IF
an old symlink gets left behind, it won't point to a valid mount point
(there-by reporting a previous version to the client with a wrong date).
Putting this in the script would be easy, but I have entries in fstab to
mount the snapshots on boot (in the unlikely event it is ever rebooted).
One solution to this would probably be to use awk and sed (no idea how
to use these) to dynamically add and remove the fstab entries.

James Dinkel

More information about the samba mailing list