我正在尝试编写一个备份解决scheme,它将使用硬链接和rsync来抓取文件夹的快照,每隔一小时它就会运行一次,并拍摄快照。 我已经大部分已经sorting,这只是我错过的小细节。
我已经在计划一个系统,根据它们之间的距离,以及它们在指数回退时期的年龄来清除旧的备份。 因此,它不会占用大量的磁盘空间来保持每小时的备份。 (每个备份的年龄被后面的备份分割…)
然而,我将在一台经常没有备份变化的机器上运行(一夜之间,当人们正在度假等),因此,我想考虑这一点。 如果只是为了省电的目的。
有没有办法告诉整个/ home /目录的最后修改时间是什么时候?
最好没有完全遍历目录,因为这有点击败了这一点。
有没有更好的方法来做到这一点?
Rsync可以用-u or --update标志来完成这个function。
从rsync手册页:
-u, --update This forces rsync to skip any files which exist on the destinaâ tion and have a modified time that is newer than the source file. (If an existing destination file has a modify time equal to the source fileâs, it will be updated if the sizes are different.) In the current implementation of --update, a difference of file format between the sender and receiver is always considered to be important enough for an update, no matter what date is on the objects. In other words, if the source has a directory or a symlink where the destination has a file, the transfer would occur regardless of the timestamps. This might change in the future (feel free to comment on this on the mailing list if you have an opinion).
如果你不想使用rsync,我可以想出另外两种方法来获取这个信息。 但是,这两种方式都需要您深入了解文件系统。
首先是丑陋的方式:
使用stat stat --format=%y <file>并parsing输出的时间。 你将不得不做一些相当丑陋的事情来获得这个工作的权利。
第二种方式是:
使用find <path> -mtime -<number_of_days>来获取在number_of_days之前的窗口中修改的文件列表。
Re:省电
这需要一些黑客攻击,而且不会100%可靠 – 从某种意义上说,你可能会错过一些需要备份的东西。 但是你可以做如下的事情,而不是在某些窗口中针对家庭驱动器运行:
if [ `date +%k` -lt 22] && [`date +%k` -gt 8] && [ `date +%u` -le 5 ] then #Set some flags for run control. fi
第一次datetesting,检查是否在晚上10点之前,第二天晚上8点,最后一次检查星期几是否小于或等于5( date +%u从1-7输出星期几,一天星期一,星期六和星期天是6和7)
至于节假日,我真正想到的唯一的事情就是保留一个文件,每个节假日的年份的天数然后匹配date +%j