detect if something is modified in directory, and if so, backup - otherwise do nothing

橙三吉。 提交于 2019-12-06 09:31:03

If I understand correctly, you just want to see if any files have been modified so you can figure out whether to proceed to the rsync portion of your script?

It's a pretty simple task to figure out when the data was last synced, especially if you do this nightly. As soon as you find one file with mtime greater than the time of the last sync, you know you have to proceed to the full rsync.

find has this functionality built in:

# find all files modified in the last 24 hours
find -mtime 1

Rsync already does this. There is no on-demand solution that doesn't require checking the mtime and ctime properties of the inodes.

However you could create a daemon that uses inotify to track changes as they occur, and fire rsync at intervals, or whenever you feel sufficient events have occurred to justify calling rsync.

I would use the find command, but do it this way: When the rsync runs, touch a file, like "rsyncranflag". Then you can run

find Data -newer rsyncranflag

That will say definitively whether any files were changed since the last rsync (subject to the accuracy of mtime).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!