LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-01-2009, 09:00 PM   #1
HighLife
Member
 
Registered: Feb 2003
Posts: 36

Rep: Reputation: 15
CIFS share & multiple entries in mtab


I have a backup script that runs every second night to shutdown a database server task - mount a CIFS network drive, backup the databases to the mounted drive and then restart the server again on completion.

I mount the drive in the script using:

mount -t cifs -o username=someuser,password=somepassword,//IP_Address/backupfolder /mnt/backupfolder

It all works fine but each time the script runs the CIFS drive still appears to be mounted but it re-mounts the drive anyway and adds another entry to the mtab, I only noticed when I tried to umount it and it didn't appear to un-mount. I checked the mtab and noticed there was half a dozen entries for the same mount so I had to umount it 6 times to get it to actually un-mount?

Doesn't the mount have a timeout period or do I need to call a umount to remove the drive? Why does mount add duplicate entries to mtab instead of realizing its already mounted?

I'm using CentOS 4.7
 
Old 10-01-2009, 09:22 PM   #2
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by HighLife View Post
I need to call a umount to remove the drive?
Umm ... yes. You do. Either that or turn off the machine. Or, you could check to see if the mount is already in place, and skip the remount. If your mount point is an empty directory, this should be an easy test.

Actually, I think the best option would be to check for files in an empty mount directory, and skip a mount that is already completed.
 
Old 10-01-2009, 09:35 PM   #3
HighLife
Member
 
Registered: Feb 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Ok, thanks, that makes sense. Just wasnt sure exactly how mount behaved.

I can probably add a line to the script to check if the drive is already mounted. But hypothetically - what happens if the machine which the remote drive is on is rebooted whilst the drive is still mounted? Will the mount still be valid when it back online? Or will I need to remount it and if so will I then end up with duplicate entries in mtab?

Sorry for all the questions - just trying to prevent any possible issues with the backup script.
 
Old 10-02-2009, 12:08 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
In your script, check the rtn code of each mount/umount cmd ie

Code:
mount blah.....
if [[ $? -eq 0 ]]
then
    # all ok; do something
else
    # not ok; something else
fi
Same for umount. Failsafe is to do a umount at the start anyway and ignore the rtn code.
You'll get a fail code iirc if the umount fails eg mount wasn't there in the first place.
 
Old 10-02-2009, 01:00 AM   #5
HighLife
Member
 
Registered: Feb 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Ok I have reviewed the script, here are my additions to make sure the network drive is available when the backup runs:

Code:
#check if the backup location is accessible - un-mount existing mount and then try and remount
umount -f /mnt/backupfolder

mount -t cifs //IP_Address/backupfolder /mnt/backupfolder -o credentials=/root/.credentials>> /var/log/backup.log 2>&1

if [[ $? -eq 0 ]]
then
    # backup location mount successful

   #stop the Server
   /etc/init.d/domino stop 1>> /var/log/backup.log 2>&1
   sleep 10

   tar -cvzf /mnt/backupfolder/$fname /data 1>> /var/log/backup.log 2>&1

   #We start Domino again
   /etc/init.d/domino start 1>> /var/log/backup.log 2>&1

   echo "`date`: The backup has finished" >> /var/log/backup.log

else
    # mount network backup location failed
   echo "`date`: Backup drive not accessible - mounting backup location failed!!" >> /var/log/backup.log
fi
I am very new to shell scripting so excuse the basic questions! See any problems with this? Should I pause between umount and mount commands?

I may also make it so an email is sent to me if the mount fails. The network folder is on a NAS device which has been known to drop off the network at times - hence the reason I'm going to all the trouble of making sure its still there before shutting down the server and doing the backup!
 
Old 10-02-2009, 02:53 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Looks ok to me.
I'd add a comment at the top explaining why you're not checking the rtn code for umount.
You could add a

sleep X # X<5 imho

after the umount; prob not needed though.
I'd add the email for failure.
Hope you defined $fname further up.
Personally, for prod code I'd check the rtn codes for service stop/start & tar cmd. You never know.
Basically, write a generic bash fn at the top of the prog and pass cmd and rtn code to it. Let fn check success/fail and email on fail.
To avoid multiple redirects to 'var/log/backup.log 2>&1', do it outside your prog thus:

mybackup.sh <params if needed> >var/log/backup.log 2>&1

If this is going in cron , use absolute full paths to all cmds and files.
cron env is minimal; also better security for your data.
 
Old 10-02-2009, 03:16 AM   #7
lutusp
Member
 
Registered: Sep 2009
Distribution: Fedora
Posts: 835

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by HighLife View Post
Ok, thanks, that makes sense. Just wasnt sure exactly how mount behaved.

I can probably add a line to the script to check if the drive is already mounted. But hypothetically - what happens if the machine which the remote drive is on is rebooted whilst the drive is still mounted? Will the mount still be valid when it back online? Or will I need to remount it and if so will I then end up with duplicate entries in mtab?

Sorry for all the questions - just trying to prevent any possible issues with the backup script.
Okay, I hadn't considered that possibility. Do this instead:

1. Mount the remote drive.

2. Perform the required activity.

3. Perform a sync to make sure all writes are committed.

4. Unmount the drive.

Always include the last step.
 
Old 10-04-2009, 09:54 PM   #8
HighLife
Member
 
Registered: Feb 2003
Posts: 36

Original Poster
Rep: Reputation: 15
Great thanks for the tips guys, my script is starting to become a lot more robust!

Yes I defined $fname earlier in the script, the name of the backup file changes dependent on which day of the week the script is run, that way I have a few copies of the backup at various points over the week.

lutusp - how would I perform the sync you mention in step 3)?
 
Old 10-05-2009, 01:43 AM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
http://linux.die.net/man/8/sync
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cifs mount & fstab entries JeffC1 Linux - Newbie 15 05-15-2009 07:51 PM
cifs remote share bobd72 Linux - Networking 2 06-04-2008 05:55 AM
Creating symlinks on a CIFS share? MasterC Linux - General 2 08-30-2007 05:34 PM
Access CIFS Share from Linux johnnybhoy67 Linux - Networking 0 11-30-2005 10:30 AM
CIFS samba share ronanio Linux - Software 1 11-06-2005 12:22 PM


All times are GMT -5. The time now is 08:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration