0

I`ve created simple script which is based on inotify-tools, but finally after when i decided to monitor /remotepath, which was mounted from NAS by command mount.cifs, it wasnt work.

So after some investigation i found information, that inotify-tools has not support for remote folder.

Does any one of You have any expirience with simple tool which will give me a chance, to watch remote folder, and if something will change, then will run rsync.

Maybe i should go only with rsync and sync remote folder with new files only ?

Thanks for any ideas.

In the mean time i created some simple bash script which doing this what i want, but i fighting with a problem, what will happend if something will be deleted from destination folder and i dont want to synchronize this deleted file again. Any idea how to fix this problem ?

#!/bin/bash

### Logs path
path="/var/log/compare"
log="compare.log"
listing1="listing1.log"
listing2="listing2.log"
### Path which will be monitored
destination="/path/to/destination/"
source="/path/to/remote/folder"


## Watching for content in source folder
ls -lh $source > $path/$listing1
### I`m checking if something was changed
        echo "$(date)" 'INFO' 'I will compare listing files' >> "$path/$log"
        if cmp -s "$path/$listing1" "$path/$listing2"
### Files are the same
        then
        echo "$(date)" 'INFO' 'Listings are the same' >> "$path/$log"
### Files are different
        else
        rsync -art $source $destination
        echo "$(date)" 'INFO' 'Finished synchronization' >> "$path/$log"
fi
cp $path/$listing1 $path/$listing2
itnoob
  • 13
  • 7

1 Answers1

0

inotify is indeed the wrong tool for the job; it works by intercepting filesystem activity in the kernel, so remote activity will be totally missed.

An ideal solution would be to run inotify on the NAS box. This is certainly possible with some devices, but you don't say what device you have (and if you did I probably don't have the same one).

Any other tool that exists will just do exactly what your script does (albeit maybe more prettily), so I don't think you need to pursue that avenue.

In any case, your script is entirely redundant! If you just ran rsync periodically it would do exactly the same thing (rsync -t just compares the file names, sizes, and timestamps). The only difference is that rsync will compare the remote file list against your real files, not a cached copy of the file-list. Incidentally, -a implies both -r and -t, so rsync -a is sufficient.

One thing I would look into: running rsync on the NAS device directly. Accessing the file list through CIFS is less efficient that running it locally, so if your NAS can support rsync then do it that way. (Synology NAS boxes have rsync, but I don't know about other devices.)

ams
  • 24,923
  • 4
  • 54
  • 75
  • Hello Sir, Thank you for your prompt answer. Regarding to your question, i`m using Synology solution connected with Linux Servers, on the Linux site there is no problem with inotify or rsync or any other tool. In case of Synology it can be a complicated due to closed OS and lack of packages. If the inotify tools will be possible to run on the NAS, then Yes i rather go to run it on the Synology. About rsync, I was thinking about it, but the problem is when i will delete some files on the Linux Server (which is destination), rsync will do sync with their source of Synology. – itnoob Apr 12 '16 at 21:31
  • I no longer have a Synology (I replaced it with a NUC) but I used to install packages from the nlsu2 project using `ipkg`. It works like `apt-get` etc. – ams Apr 12 '16 at 21:40
  • About the deleted files getting replaced, I don't understand how you script changes that? It just changes when it happens. In any case, the `--existing` flag tells rsync to update existing files without creating new ones. – ams Apr 12 '16 at 21:47