Added preliminary unittest for the remote synchronization tool

This commit is contained in:
Carl Johnsen
2025-01-22 06:10:43 +01:00
parent a2b13b1805
commit af69436a1e
3 changed files with 73 additions and 55 deletions
+2 -52
View File
@@ -19,7 +19,6 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using Duplicati.Library.Main;
using Duplicati.Library.Common.IO;
using Duplicati.Library.Interface;
using System;
@@ -31,40 +30,12 @@ using System.Threading;
namespace RemoteSynchronization
{
class Program
public class Program
{
static void Main(string[] args)
public static void Main(string[] args)
{
// TODO testing start
var home = Environment.GetEnvironmentVariable("HOME");
var base_path = $"{home}/git/duplicati-carl/rsync";
var l1 = $"{base_path}/l1";
var l2 = $"{base_path}/l2";
var l1r = $"{base_path}/l1_restore";
var l2r = $"{base_path}/l2_restore";
var backup_path = $"{home}/tmp/adaptivecpp";
Dictionary<string, string> options = new (){
["passphrase"] = "1234"
};
// Create the directories if they do not exist
foreach (var p in new string[] { base_path, l1, l2, l1r, l2r })
{
if (!SystemIO.IO_OS.DirectoryExists(p))
SystemIO.IO_OS.DirectoryCreate(p);
}
// Backup the first level
using (var c = new Controller($"file://{l1}", options, null))
{
var results = c.Backup([backup_path]);
Console.WriteLine($"Backed up {results.AddedFiles} files to {l1}");
}
// TODO testing end
// Sync the first level to the second level
using (var b1 = Duplicati.Library.DynamicLoader.BackendLoader.GetBackend($"file://{l1}", options))
{
var b1s = b1 as IStreamingBackend;
@@ -80,29 +51,8 @@ namespace RemoteSynchronization
Console.WriteLine($"Copied {copied} files from {l1} to {l2}");
}
}
// TODO testing start
// Try to restore the first level
options["restore-path"] = l1r;
using (var c = new Controller($"file://{l1}", options, null))
{
var results = c.Restore([Path.Combine(backup_path, "*")]);
Console.WriteLine($"Restored {results.RestoredFiles} files to {options["restore-path"]}");
}
// Try to restore the second level
options["restore-path"] = l2r;
using (var c = new Controller($"file://{l2}", options, null))
{
var results = c.Restore([]);
Console.WriteLine($"Restored {results.RestoredFiles} files to {options["restore-path"]}");
}
// TODO testing end
}
// TODO check whether a backend is empty
// TODO check whether the backend files are consistent: src.files.count >= dst.files.count
// TODO handle files deleted from src, which should also be deleted in dst
// TODO maximum retention?: don't delete files, only rename old ones.
// TODO have concurrency parameters: uploaders, downloaders
// TODO low memory mode, where things aren't kept in memory. Maybe utilize SQLite?