Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Workflow to use CLI #84

Merged
merged 5 commits into from
Apr 8, 2024
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
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ jobs:
Remove-DbaDatabase -SqlInstance localhost -Database LogShipping1,LogShipping2,LogShipping3 -Confirm:$false
Get-DbaDatabase -SqlInstance localhost -ExcludeSystem | Select-Object {$_.Name}

- name: Configure
- name: Deploy App
run: |
New-Item -Path C:\sql-log-shipping-service -ItemType Directory
New-Item -Path C:\Standby -ItemType Directory
Copy-Item -Path .\test\appsettings.json.test -Destination C:\sql-log-shipping-service\appsettings.json
Copy-Item -Path .\Build\* -Destination C:\sql-log-shipping-service -Recurse

- name: Configure
shell: cmd
run: |
"C:\sql-log-shipping-service\LogShippingService.exe" --Destination "Data Source=LOCALHOST;Integrated Security=True;Encrypt=True;Trust Server Certificate=True" --LogFilePath "C:\Backup\\LOG\{DatabaseName}" --FullFilePath "C:\\Backup\FULL\{DatabaseName}" --StandbyFileName "C:\Standby\{DatabaseName}_Standby.BAK"

- name: Run service
run: |
Expand Down
6 changes: 3 additions & 3 deletions sql-log-shipping-service/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class CommandLineOptions
[Option("Destination", Required = false, HelpText = "Target server connection string. SQL Instance to restore transaction logs to.")]
public string? Destination { get; set; }

[Option("LogFilePath", Required = false, HelpText = @"Path for transaction logs. Most include {DatabaseName} token. e.g. \\BACKUPSERVER\Backups\SERVERNAME\{DatabaseName}\FULL")]
[Option("LogFilePath", Required = false, HelpText = @"Path for transaction logs. Most include {DatabaseName} token. Don't include trailing '\'. e.g. \\BACKUPSERVER\Backups\SERVERNAME\{DatabaseName}\FULL")]
public string? LogFilePath { get; set; }

[Option("SASToken", Required = false, HelpText = "SASToken for Azure blob. Allows app to query for files in blob container.")]
Expand All @@ -31,10 +31,10 @@ internal class CommandLineOptions
[Option("MSDBPathReplace", Required = false, HelpText = "Use MSDBPathFind/MSDBPathReplace to do a find/replace on the backup paths returned from msdb history. e.g. Convert a local path to a UNC path ")]
public string? MSDBPathReplace { get; set; }

[Option("FullFilePath", Required = false, HelpText = @"Full backup file path. Used to initialize new databases. Include {DatabaseName} token in the path. e.g. \\BACKUPSERVER\Backups\SERVERNAME\{DatabaseName}\FULL")]
[Option("FullFilePath", Required = false, HelpText = @"Full backup file path. Used to initialize new databases. Include {DatabaseName} token in the path. Don't include trailing '\'. e.g. \\BACKUPSERVER\Backups\SERVERNAME\{DatabaseName}\FULL")]
public string? FullFilePath { get; set; }

[Option("DiffFilePath", Required = false, HelpText = @"Diff backup file path. Use with FullFilePath to initialize new databases. Include {DatabaseName} token in the path. e.g. \\BACKUPSERVER\Backups\SERVERNAME\{DatabaseName}\DIFF")]
[Option("DiffFilePath", Required = false, HelpText = @"Diff backup file path. Use with FullFilePath to initialize new databases. Include {DatabaseName} token in the path. Don't include trailing '\'. e.g. \\BACKUPSERVER\Backups\SERVERNAME\{DatabaseName}\DIFF")]
public string? DiffFilePath { get; set; }

[Option("ReadOnlyFilePath", Required = false, HelpText = @"Read only backup file path. Used to initialize new databases for databases with readonly filegroups & partial backups. Include {DatabaseName} token in the path. e.g. \\BACKUPSERVER\Backups\SERVERNAME\{DatabaseName}\READONLY")]
Expand Down
19 changes: 19 additions & 0 deletions sql-log-shipping-service/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Config
private const int PollForNewDatabasesFrequencyDefault = 10;
private const int KillUserConnectionsWithRollbackAfterDefault = 60;
private bool _encryptionRequired = false;
private char[] invalidPathChars => Path.GetInvalidPathChars().Concat(new[] { '"' }).ToArray();

[JsonIgnore]
public bool EncryptionRequired => _encryptionRequired;
Expand Down Expand Up @@ -100,6 +101,11 @@ public string? LogFilePath
{
throw new ArgumentException($"Missing {DatabaseToken} token from LogFilePath");
}

if (value != null && value.IndexOfAny(invalidPathChars) >= 0)
{
throw new ArgumentException($"LogFilePath contains invalid characters: {value}");
}
_logFilePath = value ?? string.Empty;
}
}
Expand Down Expand Up @@ -231,6 +237,11 @@ public string? FullFilePath
{
throw new ArgumentException($"Missing {DatabaseToken} token from FullFilePath");
}
// Check if path contains invalid characters
if (value != null && value.IndexOfAny(invalidPathChars) >=0)
{
throw new ArgumentException($"FullFilePath contains invalid characters: {value}");
}
_fullFilePath = value;
}
}
Expand All @@ -246,6 +257,10 @@ public string? DiffFilePath
{
throw new ArgumentException($"Missing {DatabaseToken} token from DiffFilePath");
}
if (value != null && value.IndexOfAny(invalidPathChars) >= 0)
{
throw new ArgumentException($"DiffFilePath contains invalid characters: {value}");
}
_diffFilePath = value;
}
}
Expand Down Expand Up @@ -625,6 +640,10 @@ public bool ApplyCommandLineOptions(string[] args)
Log.Information("Configuration updated. Restart the service.");
Environment.Exit(0);
}
else if (result.Errors.Any(ex => ex is HelpRequestedError or VersionRequestedError))
{
Environment.Exit(0);
}
else
{
Log.Error("Configuration not updated. Please check the command line options.");
Expand Down
40 changes: 0 additions & 40 deletions test/appsettings.json.test

This file was deleted.