1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Duplicati.Library.Interface;
using Duplicati.Library.Main;
using NUnit.Framework;
namespace Duplicati.UnitTest
{
[TestFixture]
public class RecoveryToolTests : BasicSetupHelper
{
private string originalCurrentDirectory;
[SetUp]
public override void SetUp()
{
base.SetUp();
this.originalCurrentDirectory = Directory.GetCurrentDirectory();
}
[TearDown]
public override void TearDown()
{
// Since the RecoveryTool changes the current directory, we will reset it so that
// the teardown methods do not complain about the paths being used by another process.
if (this.originalCurrentDirectory != null)
{
Directory.SetCurrentDirectory(this.originalCurrentDirectory);
}
base.TearDown();
}
[Test]
[Category("RecoveryTool")]
[TestCase("false")]
[TestCase("true")]
public void Recover(string buildIndexWithFiles)
{
// Files to create in MB.
int[] fileSizes = {10, 20, 30};
foreach (int size in fileSizes)
{
byte[] data = new byte[size * 1024 * 1024];
Random rng = new Random();
rng.NextBytes(data);
File.WriteAllBytes(Path.Combine(this.DATAFOLDER, size + "MB"), data);
}
const string subdirectoryName = "subdirectory";
string subdirectoryPath = Path.Combine(this.DATAFOLDER, subdirectoryName);
Directory.CreateDirectory(subdirectoryPath);
foreach (int size in fileSizes)
{
byte[] data = new byte[size * 1024 * 1024];
Random rng = new Random();
rng.NextBytes(data);
File.WriteAllBytes(Path.Combine(subdirectoryPath, size + "MB"), data);
}
// Run a backup.
Dictionary<string, string> options = new Dictionary<string, string>(this.TestOptions);
string backendURL = "file://" + this.TARGETFOLDER;
using (Controller c = new Controller(backendURL, options, null))
{
IBackupResults backupResults = c.Backup(new[] {this.DATAFOLDER});
Assert.AreEqual(0, backupResults.Errors.Count());
Assert.AreEqual(0, backupResults.Warnings.Count());
}
// Download the backend files.
string downloadFolder = Path.Combine(this.RESTOREFOLDER, "downloadedFiles");
Directory.CreateDirectory(downloadFolder);
int status = CommandLine.RecoveryTool.Program.RealMain(new[] {"download", $"{backendURL}", $"{downloadFolder}", $"--passphrase={options["passphrase"]}"});
Assert.AreEqual(0, status);
// Create the index.
status = CommandLine.RecoveryTool.Program.RealMain(new[] {"index", $"{downloadFolder}", $"--build-index-with-files={buildIndexWithFiles}"});
Assert.AreEqual(0, status);
// Restore to a different folder.
string restoreFolder = Path.Combine(this.RESTOREFOLDER, "restoredFiles");
Directory.CreateDirectory(restoreFolder);
status = CommandLine.RecoveryTool.Program.RealMain(new[] {"restore", $"{downloadFolder}", $"--targetpath={restoreFolder}"});
Assert.AreEqual(0, status);
// Since this.DATAFOLDER is a folder, Path.GetFileName will return the name of the
// last folder in the path.
string baseFolder = Path.GetFileName(this.DATAFOLDER);
TestUtils.AssertDirectoryTreesAreEquivalent(this.DATAFOLDER, Path.Combine(restoreFolder, baseFolder), false, "Verifying restore using RecoveryTool.");
}
}
}
|