1

I have a program running on a Raspberry Pi 3 (Rasbian Jesse) that drops files in a directory called /mount-point. At bootup, I am mounting a windows share called /incoming to /mount-point. There is a windows program that is processing these files as they are dropped into the share.

mount -t cifs -o username=<share user>,password=<share password> //<Win-IP>/c/incoming /home/pi/mount-point

The problem occurs if the network goes down. If the network is down, the linux program continues to drop files into the /mount-point directory. When the network comes back up, the windows share is remounted and any files currently in /mount-point get mounted over and disappear.

Is there a way to "merge mount" the windows share so that any files currently in /mount-point are not hidden and appear in /incoming on windows?

0

2 Answers 2

4

There isn't a way to directly merge the contents of a mount point like this. The closest option is use a union/overly mount, but those don't work reliably with networked filesystems, and what you would have to do to get it to work at all in this case is rather non-intuitive.

Ideally, you should probably either:

  1. Teach your program to detect if the share is mounted or not and then have it cache the files if the share isn't mounted and then write them out when it is.
  2. Have your program write data to a separate location, and use a periodic task (using a cronjob or systemd timer) to copy the files into the share if it's mounted.

Both cases are more robust than a union mount, and both of them are also a lot more agnostic of the underlying storage configuration (which is a good thing for maintainability).

4
  • Thanks for your reply. Both are great suggestions, unfortunately timing is a factor with the files being processed. Commented Aug 17, 2017 at 20:23
  • 1
    I think i'll write a bash script that attempts to copy any files out of the /mount-point, reconnects the share, then attempts to copy the files back into the new /mount-point share. Thanks for the help! Commented Aug 17, 2017 at 20:32
  • @AustinHemmelgarn Are you sure AUFS won't correctly handle SMB backed union mounts - from my Googling it appears it is supposed to work fine ?
    – davidgo
    Commented Aug 18, 2017 at 9:28
  • @davidgo I was incorrect about AUFS (but not OverlayFS, which is upstream), but that also requires building and loading a third-party module, and has other issues, namely that it still requires extra tracking by something, will fail in interesting ways if one of the branches goes offline, and doesn't provide an easy way to remove the local copies from the Pi's filesystem. The last bit though brings up something I hadn't thought of, which is that it might be better to share the files from the Pi to Windows, not the other way around as is currently the case. Commented Aug 18, 2017 at 11:17
1

It's possible (yet somewhat cumbersome) to mount things in a way, so Linux sees local and remote files in the same directory. However your Windows will only see files that exist on the Windows side.

If you tell your program to move files to /mount-point/some-dir/ instead, which doesn't exist when the share is not mounted, it may or may not be smart enough to try it later. If it is smart enough, this may be the easiest workaround.

If it's not smart enough, let it move files to another directory and run a cron job to move files into the share. Make it smart enough. Simple mv will abort if the target directory doesn't exist.

1
  • 2
    Rather than creating a subdirectory in the Windows share (which will then appear under the mount point when the share is mounted), it might be good enough to chmod the underlying /mount-point directory to 555 (i.e., do this when the share is not mounted).  This will also cause the move operation to fail when the share is not mounted (unless the program is running privileged). Commented Aug 17, 2017 at 20:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .