检测是否某物在目录修改,并且如果是这样,备份 - 否则什么都不做 [英] detect if something is modified in directory, and if so, backup - otherwise do nothing

查看:120
本文介绍了检测是否某物在目录修改,并且如果是这样,备份 - 否则什么都不做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据目录,即通过我一个shell脚本定期Rsync在远程NAS。

I have a "Data" directory, that I rsync to a remote NAS periodically via a shell script.

不过,我想使这个更高效。我想,如果事情已经运行的rsync之前,数据改为检测。这是这样,我不醒来的NAS驱动器不必要的。

However, I'd like to make this more efficient. I'd like to detect if something has changed in "Data" before running rsync. This is so that I don't wake up the drives on the NAS unnecessarily.

我想修改shell脚本来获得数据文件的最新修改的时间(用递归查找),并写了每一次的数据rsynced的文件。

I was thinking of modifying the shell script to get the latest modified time of the files in Data (by using a recursive find), and write that to a file every time Data is rsynced.

每一个同步之前,shell脚本可以使用previous时间戳记数据被同步时间比较数据的当前时间戳。如果当前时间戳更新,那么rsync的,否则什么也不做。

Before every sync, the shell script can compare the current timestamp of "Data" with the previous timestamp when "Data" was sync'd. If the current timestamp is newer, then rsync, otherwise do nothing.

我的问题是,有没有搞清楚,如果自上次rsync的数据目录中被修改,一个更有效的方法?请注意,数据子目录的很多很多,层。

My question is, is there a more efficient way to figure out if the "Data" directory is modified since the last rsync? Note that Data has many, many, layers of sub-directories.

推荐答案

如果我理解正确的话,你只是想看看是否有任何文件已被修改,所以你可以找出是否继续执行脚本的rsync的部分?

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?

这是一个pretty简单的任务,找出当数据的最后同步的,特别是如果你这样做晚间。只要你找到一个文件,修改时间比上次同步的时间时,你知道你必须进行充分的rsync。

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

这篇关于检测是否某物在目录修改,并且如果是这样,备份 - 否则什么都不做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆