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"