Was going to use Ubuntu 6.06 for our file server... decided on Debian

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Ok, here is my script so far:
#!/bin/bash
# Creating Shadow Copies

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

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

Admsnap is the EMC Clarion utility that creates snapshots from the the SAN. As you can see I umount, deactivate, and stop the previous snapshot (if any, if not is gives an error but continues fine). Then create a new one and create the appropriate symlink so Samba will use it for the Shadow Copy service.

My only problem is that I need to also delete the previous symlink. I have 2 ideas for how this would be possible:

1. Since this will be run from cron daily, assume the previous $SHADOWNAME is exactly one day ago. However this does not account for if I happen to decide to run the script manually, and also what if the script is off by a second or more from the previous day.

2. Have something like "Session1: $SHADOWNAME" written to a text file. Every time the script is run it reads the $SHADOWNAME from the text file and deletes that symlink, then replaces that with the new $SHADOWNAME. The problem with this is, I have no idea how to do this.

Is there a better way, or could someone help me set up this idea?
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
I donno. How about something like:

ls -d @GMT*|grep -v $SHADOWNAME|xargs rm

That'll delete anything that has @GMT but doesn't have the $SHADOWNAME string in it.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
unfortunately, that's no good. I'm going to have 4 or 5 of these scripts with corresponding snapshots and symlinks that would get deleted. Otherwise, I could just do "rm -f @GMT*" before I created the new symlink.
 

drag

Elite Member
Jul 4, 2002
8,708
0
0
Do they have to follow this naming conviention? Could you stick in a "A", "B" or whatnot at the end of the symbolic link and have it still work?


edit:

otherwise the simpliest way would probably just to echo the name into a .filename in the same directory as the symbolic links so you can keep track of it when you need to replace it.

Otherwise it's looking like you may need something a bit more sophisticated then what simple bash scripts can do. You'd probably want error checking and such, which is difficult in bash sometimes. I couldn't imagine it would be fun to have one peice of the script fail for whatever reason and the rest of the commands just blindly being executed.
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Originally posted by: drag
Do they have to follow this naming conviention? Could you stick in a "A", "B" or whatnot at the end of the symbolic link and have it still work?

No, it has to be in the form of @GMT-'date -u +%Y.%m.%d-%H.%M.%S`in order for Samba to use it for the Shadow Copy service.

I'm thinking maybe what I'll do is have a file created in the directory with the script called Session1Name and have the name of the link echo'd into that file. That way I can have one file for each session and hardcode the file name into the script for that session. The only thing in the file would be the link name, so it should be easy to just read the entire file into a variable, right?

 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Here is what I got now:
#!/bin/bash
# Creating Shadow Copies

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

# 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
/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 old shadowname in a file
echo $SHADOWNAME > .Session1Name

Now I just need to figure out how to read that file into a variable.

edit: Would is just be something like "OLDSHADOWNAME < .Session1Name" ?
edit: figure it out, it's "read MYVARIABLE <filename"
 

Brazen

Diamond Member
Jul 14, 2000
4,259
0
0
Ok, here is my (what I think will be final) script:
#!/bin/bash
# Creating Shadow Copies

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

# remove the old symlink
read OLDSHADOW <.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
/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 > .Session1Name

It works so far, I ran it a couple times and it gets rid of the old symlink and does everything else like it should. Now I will just create a few more of these with different Session names and change the admsnap lines accordingly. I'll run them from cron on various schedules, so we'll have something like a daily, a bi-daily, a weekly, and a monthly.