我创建了基于 inotify-tools 的简单脚本,但最后当我决定监控 /remotepath 时,它是通过命令 mount.cifs 从 NAS 挂载的,它不起作用。
因此,经过一番调查,我发现了 inotify-tools 不支持远程文件夹的信息。
你们中是否有人对简单的工具有任何经验,这将使我有机会观看远程文件夹,如果有什么变化,那么将运行 rsync。
也许我应该只使用 rsync 并将远程文件夹与新文件同步?
感谢您的任何想法。
同时,我创建了一些简单的 bash 脚本来执行我想要的操作,但是我遇到了一个问题,如果从目标文件夹中删除某些内容并且我不想再次同步这个已删除的文件会发生什么。知道如何解决这个问题吗?
#!/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