0

I have forward remote nfs port in local machine through ssh tunnel(forwarding 2 ports), using autossh for make persistent connection:

[email protected]:~#autossh -v -M 0 -q -f -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 2049:localhost:2049 [email protected] [email protected]:~#autossh -v -M 0 -q -f -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -R 2059:localhost:2059 [email protected] 

Now i have in local.machine remote nfs ports listen to local.machine:

[email protected]:~# netstat -ntpl Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:2049 0.0.0.0:* LISTEN 27882/sshd: tunnel tcp 0 0 127.0.0.1:2059 0.0.0.0:* LISTEN 27881/sshd: tunnel 

Configure my remote nfs mountpoint with this configuration in /etc/fstab:

localhost:/var/pub /mnt/remote.machine nfs tcp,rsize=8192,wsize=8192,rw,bg,intr,noatime,nosuid,noauto,vers=3,port=2049,mountport=2059 0 0 

And mount it in /mnt/remote.machine/:

[email protected]:~# mount /mnt/remote.machine [email protected]:~# mount -lt nfs localhost:/var/pub on /mnt/remote.machine/ type nfs (rw,nosuid,noatime,tcp,rsize=8192,wsize=8192,bg,intr,vers=3,port=2049,mountport=2059,addr=127.0.0.1) 

Well now remote nfs filesystem is accessible as a local directory...

THE PROBLEM:

When in remote.machine nfs service is stopped and/or ssh tunnel is broken, how test this condition from local.machine??? I'm using this system for automatize(with crond) backups from local.machine to remote.machine

I thought of run simple test:
[email protected]:~# [ -d /mnt/remote.machine/remote/backups ] && ./run-backups.sh

But when I run it, command freeze while remote.machine back online!! and automation fails!!

If anyone has a better idea, for example using rsync or other, propose please. The condition is that the backup must be execute from local.machine to remote.machine(which has a dynamic ip) for safety reasons and permissions problems.

Edit: Mounting with options: retrans=1,timeo=1,soft,fg,retry=1,tcp,vers=3 or: retrans=1,timeo=1,soft,bg,retry=1,tcp,vers=3 The problem persist and freeze any filesystem command(example: ls, test -d) and after 2min:50sec print "Input/output error"

2 Answers 2

3

You need to add the soft mount option, otherwise the NFS client retries requests forever.

It will still take timeo * retrans for the attempt to timeout, which by default is 3min.

3
  • hi @mgorven, im using hard beacause im read on NFS man thits note: "NB: A so-called soft timeout can cause silent data corruption in certain cases. As such, use the soft option only when client responsiveness is more important than data integrity." And Data Integry is very important in my case because it's a backup operation Commented Feb 7, 2013 at 18:59
  • @StefanoCudini Then any operations on the mountpoint will hang until the server comes back. It's your choice ;-) Commented Feb 7, 2013 at 19:02
  • Using this options: soft,timeo=50,fg,retry=1,tcp,... freeze anyway, and after 2,5min print io error message, but remain freeze, and command, im try ls command but dont return error value! Commented Feb 7, 2013 at 23:36
0

You can check before the backup process if the mountpoint is visible like

timeout 10 ls /mountpoint >& /dev/null && /backup/script 

like this it won't hang it the mountpoint is stale.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.