check that mount point is an NFS export before copying to it
I am copying some backup files to a NAS by connecting an NFS export on the NAS to a mount point on my linus box. I then copy the files to it with a cron job that runs nightly.
I have mounted the NAS to /mnt/nas. How can I test that the mount point is active before I copy to it? I wouldn't want to copy to /mnt/nas unless it was actually connected to the NAS. (I presume that would copy to the root partition??) Thanks, -dog |
You could put a file on the NAS called nas_is_mounted
Then test to see if it exists at your mountpoint. If it doesn't then the NAS is not mounted. Otherwise, you could check the output of mount with and without the NAS being mounted and spot the difference. |
You can test that easily with a combination of mount and grep. The code
Code:
mount | grep /mnt/nas |
thanks
I ended up with this:
Code:
"$(df -P /mnt/nas |tail -1 |awk '{print $NF}')" = "/mnt/nas" |
thanks
Hi,
I'm trying to do exactly the same thing : copying some files from a debian to a nas synology mounted as nfs to /mnt/nas. I then copy the files to it with a cron job that runs nightly a script. in the /etc/fstab : Code:
192.168.1.102:/volume1/test /mnt/nas/ nfs user,noauto 0 0 Quote:
Could you explain me more about and how to use it : Code:
"$(df -P /mnt/nas |tail -1 |awk '{print $NF}')" = "/mnt/nas" |
Code:
if [ "`mount | tr -s ' ' | cut -f 3 -d ' ' | grep '^/mnt/nas'`" != "" ] ; then |
Thanks for your answer
In first it seemes to work but if i turn off the nas and execute the script again : Code:
building file list ... done Code:
# Script to backup personal files to the external NAS drive as NFS. |
finally
Finally i made another script that seems to be ok if i turn off the nas server or turn off his ethernet cable
If someone nice could read it and tell me my error it will be wonderful :) This is the script (my first one) to make a synchronisation each day of different directories to a NAS server : Code:
#!/bin/bash But if I cron it, i have the error : rsync: failed to open exclude file exclude_prive.txt: No such file or directory (2) and i don't understannd why ? |
cron doesn't login as your user, therefore exclude_prive.txt is not in your pwd (ie current dir).
For cron jobs you need to ensure all cmds and files have the complete pathname attached, OR at the start, cd into the relevant dir and source whatever setup cmds you need. Another thing; you attempt to mount the NAS and echo "Server NAS mounted successfully." WITHOUT checking to see if it has... Either check $? immediately, or grep the entry from /etc/mnttab. Incidentally, if you add Code:
set -xv |
thanks chrism01 :)
So i write the entire path to exclude_file. and test the result of mount The script now : Code:
#!/bin/bash |
All times are GMT -5. The time now is 10:59 PM. |