Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ updates:
target-branch: "main"

- package-ecosystem: "nuget"
directory: "/Parallel.Desktop"
directory: "/Parallel.Gui"
schedule:
interval: "daily"
target-branch: "main"
9 changes: 7 additions & 2 deletions .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ jobs:
}

$projects = @(
@{ name="cmd"; path="Parallel.Cli/Parallel.Cli.csproj" }
@{ name="cmd"; path="Parallel.Cli/Parallel.Cli.csproj"; extra=@() },
# The desktop app ships its native Avalonia/Skia libraries inside the single file.
@{ name="desktop"; path="Parallel.Gui/Parallel.Gui.csproj"; extra=@("--self-contained", "/p:IncludeNativeLibrariesForSelfExtract=true") }
)

$distRoot = Join-Path $env:GITHUB_WORKSPACE "dist"
Expand All @@ -83,7 +85,10 @@ jobs:
$outputDir = Join-Path $env:GITHUB_WORKSPACE "dist/$($proj.name)/$os/$arch"
New-Item -ItemType Directory -Force -Path $outputDir

dotnet publish $proj.path -c Release -r $rid /p:PublishSingleFile=true /p:DebugType=None /p:DebugSymbols=false /p:PublishDir=$outputDir
dotnet publish $proj.path -c Release -r $rid /p:PublishSingleFile=true /p:DebugType=None /p:DebugSymbols=false /p:PublishDir=$outputDir @($proj.extra)

# SkiaSharp/HarfBuzz ship ~100 MB of native .pdb files next to the exe; they aren't needed to run.
Remove-Item "$outputDir/*.pdb" -ErrorAction SilentlyContinue

$repoName = $repoName = "${{ github.event.repository.name }}"
$zipName = "$repoName-$version-$($proj.name)-$osName-$arch.zip"
Expand Down
113 changes: 113 additions & 0 deletions Parallel.Cli/Commands/BackupCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright 2026 Entex Interactive

using System.ComponentModel;
using Parallel.Core.Config;
using Parallel.Cli.Infrastructure;
using Parallel.Core.Engine;
using Parallel.Core.Repository;
using Spectre.Console;
using Spectre.Console.Cli;

namespace Parallel.Cli.Commands
{
public sealed class BackupSettings : VaultSettings
{
[CommandOption("-p|--path <PATH>")]
[Description("Back up only these paths (repeatable) instead of the configured sources.")]
public string[] Paths { get; init; } = [];

[CommandOption("--rehash")]
[Description("Read every file again instead of trusting size and modification time.")]
public bool Rehash { get; init; }

[CommandOption("--no-vss")]
[Description("Windows: do not use a Volume Shadow Copy.")]
public bool NoVss { get; init; }

[CommandOption("--one-file-system")]
[Description("Do not cross into other mounted file systems.")]
public bool OneFileSystem { get; init; }

[CommandOption("--tag <TAG>")]
[Description("Label the snapshot (repeatable). A tagged backup is always saved, even if nothing changed.")]
public string[] Tags { get; init; } = [];

[CommandOption("--force")]
[Description("Save a new snapshot even if nothing changed since the last one.")]
public bool Force { get; init; }

[CommandOption("--verbose")]
[Description("List every new or changed file.")]
public bool Verbose { get; init; }
}

[Description("Backs up the folders chosen with 'parallel backup add' into a new snapshot (skipped if nothing changed).")]
public sealed class BackupCommand(AppConfig config) : AsyncCommand<BackupSettings>
{
public override async Task<int> ExecuteAsync(CommandContext context, BackupSettings s, CancellationToken ct)
{
int exitCode = 0;
foreach (VaultConfig vault in VaultAccess.Select(config, s.Vault))
{
List<string> sources = s.Paths.Length > 0 ? s.Paths.Select(PathMap.Normalize).ToList() : vault.Sources;
if (sources.Count == 0)
{
AnsiConsole.MarkupLine($"[yellow]{Markup.Escape(vault.Name)}: nothing to back up. Add folders with 'parallel backup add <path>'.[/]");
exitCode = Math.Max(exitCode, 1);
continue;
}

exitCode = Math.Max(exitCode, await RunAsync(vault, config.ExcludesFor(vault), sources, s, s.Verbose, ct));
}

return exitCode;
}

/// <summary>Runs one backup. Returns 0 on success, 3 when the snapshot was saved but some items had errors.</summary>
public static async Task<int> RunAsync(VaultConfig vault, IReadOnlyList<string> excludes, IReadOnlyList<string> sources, BackupSettings s, bool verbose, CancellationToken ct)
{
AnsiConsole.MarkupLine($"[bold]{Markup.Escape(vault.Name)}[/]: backing up {sources.Count} path(s) to {Markup.Escape(vault.Describe())}");
await using Repository repo = await VaultAccess.OpenAsync(vault, s.PasswordFile, ct);

ConsoleProgress progress = new(verbose);
BackupOptions options = new()
{
Sources = sources,
Excludes = excludes,
Rehash = s.Rehash,
OneFileSystem = s.OneFileSystem || vault.OneFileSystem,
UseVss = vault.UseVss && !s.NoVss,
Tags = s.Tags,
AlwaysSnapshot = s.Force || s.Tags.Length > 0,
Progress = progress,
};

BackupResult result = await progress.RunAsync("Backing up", () => new BackupEngine(repo, options, AppConfig.Directory).RunAsync(ct));
Print(result);
return result.Errors.Count == 0 ? 0 : 3;
}

private static void Print(BackupResult result)
{
var sum = result.Snapshot.Summary;
Grid grid = new Grid().AddColumn().AddColumn();
grid.AddRow("Snapshot", result.Skipped ? $"none (nothing changed since [bold]{result.SnapshotId[..8]}[/])" : $"[bold]{result.SnapshotId[..8]}[/]");
grid.AddRow("Files", $"{sum.Files:N0} ({sum.FilesNew:N0} new, {sum.FilesChanged:N0} changed, {sum.FilesUnchanged:N0} unchanged)");
grid.AddRow("Folders", $"{sum.Directories:N0}");
grid.AddRow("Size", Format.Bytes(sum.Bytes));
grid.AddRow("Stored", $"{Format.Bytes(sum.BytesAdded)} added to the vault");
grid.AddRow("Time", Format.Duration(TimeSpan.FromSeconds(sum.Seconds)));
AnsiConsole.Write(grid);

if (result.Errors.Count == 0)
{
AnsiConsole.MarkupLine(result.Skipped ? "[green]Nothing changed; the latest snapshot is already up to date.[/]" : "[green]Backup complete.[/]");
return;
}

AnsiConsole.MarkupLine($"[yellow]Backup saved, but {result.Errors.Count:N0} item(s) could not be read. Their previous versions (if any) were kept in this snapshot:[/]");
foreach (EngineError error in result.Errors.Take(20)) AnsiConsole.MarkupLine($" [yellow]{Markup.Escape(error.Path)}[/]: {Markup.Escape(error.Message)}");
if (result.Errors.Count > 20) AnsiConsole.MarkupLine($" ... and {result.Errors.Count - 20:N0} more (see the log in {Markup.Escape(AppConfig.LogDirectory)})");
}
}
}
125 changes: 0 additions & 125 deletions Parallel.Cli/Commands/CleanCommand.cs

This file was deleted.

47 changes: 0 additions & 47 deletions Parallel.Cli/Commands/DuplicatesCommand.cs

This file was deleted.

46 changes: 0 additions & 46 deletions Parallel.Cli/Commands/FetchCommand.cs

This file was deleted.

Loading
Loading