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
13 changes: 13 additions & 0 deletions Installer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static async Task<int> Main(string[] args)
Console.WriteLine(" -h, --help Show this help message");
Console.WriteLine(" --reinstall Drop existing database and perform clean install");
Console.WriteLine(" --reset-schedule Reset collection schedule to recommended defaults");
Console.WriteLine(" --preserve-jobs Keep existing SQL Agent jobs (owner, schedule, notifications)");
Console.WriteLine(" --encrypt=<level> Connection encryption: mandatory (default), optional, strict");
Console.WriteLine(" --trust-cert Trust server certificate without validation");
Console.WriteLine();
Expand All @@ -115,6 +116,7 @@ static async Task<int> Main(string[] args)
bool automatedMode = args.Length > 0;
bool reinstallMode = args.Any(a => a.Equals("--reinstall", StringComparison.OrdinalIgnoreCase));
bool resetSchedule = args.Any(a => a.Equals("--reset-schedule", StringComparison.OrdinalIgnoreCase));
bool preserveJobs = args.Any(a => a.Equals("--preserve-jobs", StringComparison.OrdinalIgnoreCase));
bool trustCert = args.Any(a => a.Equals("--trust-cert", StringComparison.OrdinalIgnoreCase));

/*Parse encryption option (default: Mandatory)*/
Expand All @@ -135,6 +137,7 @@ static async Task<int> Main(string[] args)
var filteredArgs = args
.Where(a => !a.Equals("--reinstall", StringComparison.OrdinalIgnoreCase))
.Where(a => !a.Equals("--reset-schedule", StringComparison.OrdinalIgnoreCase))
.Where(a => !a.Equals("--preserve-jobs", StringComparison.OrdinalIgnoreCase))
.Where(a => !a.Equals("--trust-cert", StringComparison.OrdinalIgnoreCase))
.Where(a => !a.StartsWith("--encrypt=", StringComparison.OrdinalIgnoreCase))
.ToArray();
Expand Down Expand Up @@ -653,6 +656,16 @@ INSERT...WHERE NOT EXISTS re-populates with current recommended values
Console.Write("(resetting schedule) ");
}

/*
Preserve existing SQL Agent jobs if requested — flip the T-SQL
variable so existing jobs are left untouched during upgrade
*/
if (preserveJobs && fileName.StartsWith("45_", StringComparison.Ordinal))
{
sqlContent = sqlContent.Replace("@preserve_jobs bit = 0", "@preserve_jobs bit = 1");
Console.Write("(preserving existing jobs) ");
}

/*
Remove SQLCMD directives (:r includes) as we're executing files directly
*/
Expand Down
6 changes: 6 additions & 0 deletions InstallerGui/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@
Margin="0,0,0,10"
Foreground="{DynamicResource ForegroundBrush}"/>

<!-- Preserve Jobs Checkbox -->
<CheckBox x:Name="PreserveJobsCheckBox"
Content="Keep existing SQL Agent jobs (owner, schedule, notifications)"
Margin="0,0,0,10"
Foreground="{DynamicResource ForegroundBrush}"/>

<!-- Validation Checkbox -->
<CheckBox x:Name="ValidationCheckBox"
Content="Run validation after install (recommended)"
Expand Down
2 changes: 2 additions & 0 deletions InstallerGui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,13 @@ Execute installation
Community dependencies install automatically before validation (98_validate)
*/
bool resetSchedule = ResetScheduleCheckBox.IsChecked == true;
bool preserveJobs = PreserveJobsCheckBox.IsChecked == true;
_installationResult = await InstallationService.ExecuteInstallationAsync(
_connectionString,
_sqlFiles,
isCleanInstall,
resetSchedule,
preserveJobs,
progress,
preValidationAction: async () =>
{
Expand Down
12 changes: 12 additions & 0 deletions InstallerGui/Services/InstallationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ public static async Task<InstallationResult> ExecuteInstallationAsync(
List<string> sqlFiles,
bool cleanInstall,
bool resetSchedule = false,
bool preserveJobs = false,
IProgress<InstallationProgress>? progress = null,
Func<Task>? preValidationAction = null,
CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -422,6 +423,17 @@ Execute SQL files
});
}

/*Preserve existing SQL Agent jobs if requested*/
if (preserveJobs && fileName.StartsWith("45_", StringComparison.Ordinal))
{
sqlContent = sqlContent.Replace("@preserve_jobs bit = 0", "@preserve_jobs bit = 1");
progress?.Report(new InstallationProgress
{
Message = "Preserving existing SQL Agent jobs...",
Status = "Info"
});
}

/*Remove SQLCMD directives*/
sqlContent = SqlCmdDirectivePattern.Replace(sqlContent, "");

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ A GUI installer (`PerformanceMonitorInstallerGui.exe`) is also included in the r
| `USERNAME PASSWORD` | SQL Authentication credentials (positional, optional) |
| `--reinstall` | Drop existing database and perform clean install |
| `--reset-schedule` | Reset collection schedule to recommended defaults during upgrade |
| `--preserve-jobs` | Keep existing SQL Agent jobs unchanged (owner, schedule, notifications) |
| `--encrypt=optional\|mandatory\|strict` | Connection encryption level (default: mandatory) |
| `--trust-cert` | Trust server certificate without validation (default: require valid cert) |

Expand Down
Loading
Loading