本地备份文件,最佳实践 [英] Back up files localy, best practice

查看:64
本文介绍了本地备份文件,最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个文件道具项目,这将使我们的开发人员可以很容易地支持或回滚文件和文件夹.我在寻找一种简单的方法来本地备份文件和文件夹时遇到了一些麻烦.最初,我只是将文件和文件夹扔到备份文件夹中,以便在以后发生回滚时将其拉出.现在我知道这很愚蠢,因为如果文件或文件夹具有相同的名称,我将无法将它们保留在相同的文件夹中.

对于要备份的任何给定文件或文件夹(仅在覆盖,删除时备份),我将知道源路径和目标路径.由于我已经知道这一点,所以我认为将文件名复制到所需的唯一文件并使用某种表将其与路径关联时,可以更改文件名.因此,例如,如果两个文件具有相同的名称,但具有不同的路径:

文件路径:(以下两个文件具有不同的内容)
\\ server \ testpage \ foo.html
\\ server \ livepage \ foo.html

我可以使用二维数组列表来保存路径和与之关联的文件.保存文件时将更改文件名,以确保它们是唯一的(对于first.html和second.html) .html
2 \\ server \ livepage \ foo.html second.html

现在需要回滚时,我只需查找目标路径并找到与该路径关联的文件,更改名称并复制将文件退回.

如果有人可以想到另一种更简单的方法来执行此操作,或者告诉我我提出的方法是否是实现此目标的好方法,那将是很好的.

I am currenly working on a file prop project that will make it easy for our dev's to prop or rollback files and folders.  I am having some trouble figuring out an easy way to back up the files and folders locally.  Initially I was just throwing the files and folders into a backup folder to be pulled out later when a rollback would occur.  Now I know that was silly because if the files or folders have the same names I will not be able to keep them in the same folder.

So now I am trying to think of the best way to accomplish this.

For any given file or folder I want to back up (only backing up when I overwrite, delete) I will know the source path and the destination path.  Since I already know this, I was thinking it would be fine to change the name of the file when it is copied to anything unique that I want and using some sort of table to associate that with it's path.  So if two files have the same name but different different paths for instance:

Filepaths: (the two files below have different content)
\\server\testpage\foo.html
\\server\livepage\foo.html

I could use a 2 dimensional arraylist to save the paths and the files associated with them.  The names of the files would be changed when they are saved to be sure they are unique (to first.html and second.html)

                      1                              2
1  \\server\testpage\foo.html   first.html
2  \\server\livepage\foo.html    second.html

Now when it comes time to roll back I can just look for the destination path and find what file is associated with that path, change the name and copy the file back.

If anyone can think of another easier way to do this or tell me if the way I am proposing is a good way to accomplish this that would be great.

推荐答案

使用
use a Hashtable. set the path as the key and the name of the file as the Value. you can have two values that are the same, but you can have only one key with a name. the advantage would be the speed with which you can retrieve an element of a hashtable.


这篇关于本地备份文件,最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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