c#复制接口恢复单个文件

本文关键字:单个 文件 恢复 接口 复制 | 更新日期: 2023-09-27 18:05:58

我正在尝试使用Duplicati API来恢复单个文件。

关于场景:整个东西在linux上运行,所以它是用mono编译的。我的备份包含两个源文件夹,所以如果我运行Interface.ListSourceFolders(),我得到一个包含两个文件夹的数组。

期望结果:我想从备份中恢复一个文件(或文件夹)

当前结果:如果我运行下面的代码,它将恢复所有备份的文件(因此文件夹1和文件夹2)到//Comment1中的路径。

List<string> files = new List<string>();
files.Add("path");    //Comment1
Dictionary<string,string> options = new Dictionary<string,string>();
options["passphrase"] = MySettings.Password;
options["restore-time"] = date;
//Comment2
Interface i = new Interface("file:///path/to/archives", options);
string result = i.Restore(files.ToArray());

我尝试的:我试图将//Comment1的路径设置为绝对路径(/desired/file/to/restore)或使用源文件夹(0/file/to/restore)的索引,我也在//Comment2附近玩。我添加了options["restore-path"] = "/path/to/restore"之类的东西。我总是得到相同的结果。

有人看到我做错了什么吗?因为我不知道我还能尝试什么。几乎没有文档,所以我不知道去哪里搜索。如果有人知道一个好的文档链接,我也会很高兴!

c#复制接口恢复单个文件

如果有人感兴趣的话。在尝试了几个小时后,我终于找到了恢复单个文件或文件夹的方法。下面是我正在做的:

List<string> files = new List<string>();
files.Add("/restore/path");    //Comment1
Dictionary<string,string> options = new Dictionary<string,string>();
options["passphrase"] = MySettings.Password;
options["restore-time"] = date;
options["file-to-restore"] = "files";    //Comment2
Interface i = new Interface("file:///path/to/archives", options);
string result = i.Restore(files.ToArray());

//Comment1,您需要设置所需的恢复路径。在此文件夹中创建了所有备份集文件夹(来自Interface.ListSourceFolders()的文件夹)

//Comment2中,您可以以这种形式指定要恢复的文件:0/file/to/restore,其中0是源文件夹(Interface.ListSourceFolders())的索引。如果您需要恢复多个文件,您可以将它们组合成一个字符串:例如Windows: 0/file1;1/file2或Linux 0/file1:1/file2(区别是分号或冒号)

现在还有一件事:你不能用它的文件恢复文件夹。您需要将上述字符串中的所有文件和子文件组合在一起。

我希望我能帮到别人。