You are not logged in.

#1 2009-09-17 22:12:42

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,677
Website

bash script help - backup script of sorts

I'd like to have a bash script that simply uses rsync to mirror a samba share from a windows machine that isn't on all the time.  I figured I can have cron kick off the script every 30 or 60 min.  What I don't know how to do is have it attempt to mount the samba share if it isn't mounted.  Another scenario would be that the mount is live, then the windows box goes down thereby leaving the mounted samba partition dead.  I'm not sure how to deal with that either.  Should I keep an empty file in the root of the mount and use an if then statement to check if that file exists or...?

Suggested code is appreciated smile

The Arch box has this line in the /etc/fstab

//windows/share /media/share cifs credentials=/root/.winshare,r,user,noauto 0 0

Here is the partial script:

#!/bin/bash

# section to check that the thing is mounted

rsync -avxu  /media/share/ /home/user/docs

Last edited by graysky (2009-09-17 22:15:25)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#2 2009-09-17 22:30:34

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: bash script help - backup script of sorts

graysky wrote:

Should I keep an empty file in the root of the mount and use an if then statement to check if that file exists

this sounds like the best option to me.  that and if mount | grep -q '/media/share' ; then... are really the only two ways to check, but if the box goes down unexpectedly or whatever, it'd likely still be listed by mount.  checking for a file's existence is probably the most sure fire way.  if that check passes you know you're good to back up.

Offline

#3 2009-09-17 22:56:24

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Re: bash script help - backup script of sorts

Do you get an error if you try to ls the samba mount when it dies?
You can do something like

mounted=cat /etc/mtab | grep /media/share

if [ $mounted ]; then
   alive=ls /media/share | grep error
   if [ $alive ]; then
      echo "Error..."
      #maybe try to remount?
      exit
   else
       rsync
   fi
fi

although pseudo with some tweaking you should be able to get you're desired results


Website - Blog - arch-home
Arch User since March 2005

Offline

Board footer

Powered by FluxBB