0

So I have this script running, using inotifywait. One server puts images into a NFS folder on the host server at /var/nfs/device_images. (chmod is 777 on working folders) The host server then moves it into a working directory of a python script.

inotifywait -m /var/nfs/device_images -e create -e moved_to | while read path action file; do cp /var/nfs/drvie_images/$file /home/samuel/programname/images/$file; done

It works, kinda. The file itself transfers, but it's corrupt. It seems inotifywait tries to send the photo before it's totally transferred? Anyone have a solution?

  • See https://stackoverflow.com/questions/4231243/inotify-with-nfs. You may be experiencing a problem unrelated to NFS, though, in that the producer might still be writing to the file after it is first created, meaning you are copying a file that changes during the copy. Typically, you need the producer to make sure the file doesn't appear under its "expected" name until it has written the entire file, with something like `write_to_file tmpname && mv tmpname realname`. That way, you know that `realname` is complete as soon as it is created. – chepner Jul 02 '18 at 16:54

1 Answers1

0

create event would be triggered as soon as a file gets created even before it gets fully written, making it look like the images are corrupt

One way to solve this is by making inotifywait to listen for only move event and forcing the server that populates /var/nfs/device_images to create the files in a temp directory and move that to /var/nfs/device_images on completion.

You can specify temp directory for most utilities that are used to grab the files like rsync / wget

Prem Anand
  • 2,469
  • 16
  • 16
  • Do you know if there any way to specify a tmp dir when using the built in nfs (the config applied with exports -a)? But thanks, good information, I have it waiting for 5 seconds before copying but I dont like doing that. – Samuel Archibald Jul 02 '18 at 17:33
  • You obviously can't do much from the nfs client. If you can't control on how nfs server populates images on the nfs directory, thenmy suggestion would be to play with inotofywait's `close_write` event and check if that helps you – Prem Anand Jul 03 '18 at 09:55