即使在移动/重命名后,也唯一标识NTFS中的文件/文件夹 [英] Uniquely identify files/folders in NTFS, even after move/rename

查看:99
本文介绍了即使在移动/重命名后,也唯一标识NTFS中的文件/文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有找到可以执行我想要的功能的备份(同步)程序,所以我正在考虑编写自己的备份程序.

I haven't found a backup (synchronization) program which does what I want so I'm thinking about writing my own.

我现在所要做的是:它遍历源中的数据,并且对于每个已设置存档位或在目标中不存在的文件,将其复制到目标,并覆盖可能存在的文件.完成后,它将检查目标中的所有文件(如果在源中是否存在),如果不存在,则将其删除.

What I have now does the following: It goes through the data in the source and for every file which has its archive bit set OR does not exist in the destination, copies it to the destination, overwriting a possibly existing file. When done, it checks for all files in the destination if it exists in the source, and if it doesn't, deletes it.

问题在于,如果我移动或重命名一个大文件夹,即使原则上已经存在该文件夹,它也会首先复制到目标文件夹,只是路径不同.然后,将已经存在的文件夹删除.

The problem is that if I move or rename a large folder, it first gets copied to the destination even though it is in principle already there, just has a different path. Then the folder which was already there is deleted afterwards.

除了不必要的复制外,我还经常遇到空间问题,因为备份驱动器的容量不足以容纳两次原始数据.

Apart from the unnecessary copying, I frequently run into space problems because my backup drive isn't large enough to hold the original data twice.

是否有一种方法可以通过编程的方式来标识这种移动/重命名的文件或文件夹,即通过NTFS ID或媒体上的物理位置或其他方式?有解决这个问题的方法吗?

Is there a way to programmatically identify such moved/renamed files or folders, i.e. by NTFS ID or physical location on media or something else? Are there solutions to this problem?

我不在乎编程语言,但是希望能够使用Python,C ++,C#,Java或Prolog做到这一点.

I do not care about the programming language, but hints for doing this with Python, C++, C#, Java or Prolog are appreciated.

推荐答案

您是否熟悉对象ID?这可能是您要查找的内容: http://msdn.microsoft.com/en-us/library/aa363997.aspx

Are you familiar with object IDs? This might be what you're looking for: http://msdn.microsoft.com/en-us/library/aa363997.aspx

您可能还想使用文件ID.您可以从 FILE_ID_BOTH_DIR_INFO 您的FileId字段中获取此信息通过调用 GetFileInformationByHandleEx nFileIndexLownFileIndexHigh BY_HANDLE_FILE_INFORMATION 的字段,您可以通过调用

You may also want to use file IDs. You can get this from the FileId field of FILE_ID_BOTH_DIR_INFO you get by calling GetFileInformationByHandleEx or the nFileIndexLow and nFileIndexHigh fields of BY_HANDLE_FILE_INFORMATION you get by calling GetFileInformationByHandle.

尽管需要您重新设计系统,但NTFS具有称为的功能专为这种情况而设计的变更日记.它可以跟踪更改过的每个文件,即使在重新启动后也是如此.当您的程序运行时,它将在每次中断时读取更改日志.对于每个已删除的文件,请在备份中删除该文件.对于每个已重命名的文件,请在备份中重命名该文件.对于创建或更改的每个文件,请将其复制到备份中.现在,您不必遍历两个目录树,而只需遍历实际上必须注意的文件列表.

Although it would require you to redesign your system, NTFS has a feature called a change journal that was designed for just this situation. It keeps track of every file that was changed, even across reboots. When your program runs, it would read the change journal from whenever it left off. For every file that was deleted, delete that file on your backup. For every file that was renamed, rename that file on your backup. For every file that was created or changed, copy that file to your backup. Now, instead of having to traverse both directory trees in parallel, you can simply traverse the list of files you'll actually have to pay attention to.

这篇关于即使在移动/重命名后,也唯一标识NTFS中的文件/文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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