Skip to content

Commit

Permalink
reorganized folders
Browse files Browse the repository at this point in the history
  • Loading branch information
EitanBlumin committed Apr 25, 2024
1 parent 866efe9 commit 95362a5
Show file tree
Hide file tree
Showing 189 changed files with 126 additions and 52 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
Declare @Archive Int=0,
@ArchivesSQL Int,
@ArchivesAgent Int;

Declare @xp_enumerrorlogs As Table
(Archive Int,
[Date] SmallDateTime,
LogFileSizeBytes BigInt);

IF Object_ID('tempdb..#Log','U') Is Not Null
Drop Table #Log;
Create Table #Log
(ID Int Identity Primary Key Clustered,
Log Varchar(10),
DT DateTime,
ProcessInfo Varchar(10),
Text Varchar(Max));

Alter Table #Log Add Constraint Df_#Log_Log Default 'SQL Server' For [Log];

Insert
Into @xp_enumerrorlogs(Archive,[Date],LogFileSizeBytes)
EXEC xp_enumerrorlogs 1;
Set @ArchivesSQL=@@ROWCOUNT;
While @Archive<@ArchivesSQL
Begin
Insert
Into #Log(DT,ProcessInfo,Text)
Exec xp_readerrorlog @Archive,1;

Set @Archive+=1;
End

Alter Table #Log Drop Constraint Df_#Log_Log;
Alter Table #Log Add Constraint Df_#Log_Log Default 'Agent' For [Log];
Set @Archive=0;

Insert
Into @xp_enumerrorlogs(Archive,[Date],LogFileSizeBytes)
EXEC xp_enumerrorlogs 2;
Set @ArchivesAgent=@@ROWCOUNT;
While @Archive<@ArchivesAgent
Begin
Insert
Into #Log(DT,ProcessInfo,Text)
Exec xp_readerrorlog @Archive,2;

Set @Archive+=1;
End

Select *
From #Log
Declare @Archive Int=0,
@ArchivesSQL Int,
@ArchivesAgent Int;

Declare @xp_enumerrorlogs As Table
(Archive Int,
[Date] SmallDateTime,
LogFileSizeBytes BigInt);

IF Object_ID('tempdb..#Log','U') Is Not Null
Drop Table #Log;
Create Table #Log
(ID Int Identity Primary Key Clustered,
Log Varchar(10),
DT DateTime,
ProcessInfo Varchar(10),
Text Varchar(Max));

Alter Table #Log Add Constraint Df_#Log_Log Default 'SQL Server' For [Log];

Insert
Into @xp_enumerrorlogs(Archive,[Date],LogFileSizeBytes)
EXEC xp_enumerrorlogs 1;
Set @ArchivesSQL=@@ROWCOUNT;
While @Archive<@ArchivesSQL
Begin
Insert
Into #Log(DT,ProcessInfo,Text)
Exec xp_readerrorlog @Archive,1;

Set @Archive+=1;
End

Alter Table #Log Drop Constraint Df_#Log_Log;
Alter Table #Log Add Constraint Df_#Log_Log Default 'Agent' For [Log];
Set @Archive=0;

Insert
Into @xp_enumerrorlogs(Archive,[Date],LogFileSizeBytes)
EXEC xp_enumerrorlogs 2;
Set @ArchivesAgent=@@ROWCOUNT;
While @Archive<@ArchivesAgent
Begin
Insert
Into #Log(DT,ProcessInfo,Text)
Exec xp_readerrorlog @Archive,2;

Set @Archive+=1;
End

Select *
From #Log
Order By DT;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
74 changes: 74 additions & 0 deletions High Availability/Compare-AGReplicaJobs/automated_sample.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Param
(
[string]$ComputerName = "ACMESQL",
[string]$outputFolder = "",
[string]$emailFrom = "[email protected]",
[string]$emailTo = @("[email protected]", "[email protected]"),
[string]$emailServerAddress = "ACMESMTP",
[string]$logFileFolderPath = "C:\Madeira\log",
[string]$logFilePrefix = "ag_job_compare_",
[string]$logFileDateFormat = "yyyyMMdd",
[int]$logFileRetentionDays = 30
)
Process {
#region initialization
function Get-TimeStamp {
Param(
[switch]$NoWrap,
[switch]$Utc
)
$dt = Get-Date
if ($Utc -eq $true) {
$dt = $dt.ToUniversalTime()
}
$str = "{0:MM/dd/yy} {0:HH:mm:ss}" -f $dt

if ($NoWrap -ne $true) {
$str = "[$str]"
}
return $str
}

if ($logFileFolderPath -ne "")
{
if (!(Test-Path -PathType Container -Path $logFileFolderPath)) {
Write-Output "$(Get-TimeStamp) Creating directory $logFileFolderPath" | Out-Null
New-Item -ItemType Directory -Force -Path $logFileFolderPath | Out-Null
} else {
$DatetoDelete = $(Get-Date).AddDays(-$logFileRetentionDays)
Get-ChildItem $logFileFolderPath | Where-Object { $_.Name -like "*$logFilePrefix*" -and $_.LastWriteTime -lt $DatetoDelete } | Remove-Item | Out-Null
}

$logFilePath = $logFileFolderPath + "\$logFilePrefix" + (Get-Date -Format $logFileDateFormat) + ".LOG"

try
{
Start-Transcript -Path $logFilePath -Append
}
catch [Exception]
{
Write-Warning "$(Get-TimeStamp) Unable to start Transcript: $($_.Exception.Message)"
$logFileFolderPath = ""
}
}
#endregion initialization


Import-Module C:\Madeira\Compare-AGReplicaJobs.psd1;

Compare-AGReplicaJobs -From $emailFrom -To $emailTo -EmailServer $emailServerAddress -ComputerName $ComputerName -outputFolder $outputFolder -Verbose

Remove-Module Compare-AGReplicaJobs


if ($outputFolder -eq "" -or -not (Test-Path $outputFolder)) {
$outputFolder = [System.IO.Path]::GetTempPath()
$DatetoDelete = $(Get-Date).AddDays(-$logFileRetentionDays)
Get-ChildItem $outputFolder | Where-Object { $_.Name -like "*_align_jobs_*.sql" -and $_.LastWriteTime -lt $DatetoDelete } | Remove-Item | Out-Null
Get-ChildItem $outputFolder | Where-Object { $_.Name -like "*jobs_comparison_report_*.html" -and $_.LastWriteTime -lt $DatetoDelete } | Remove-Item | Out-Null
}



if ($logFileFolderPath -ne "") { Stop-Transcript }
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 95362a5

Please sign in to comment.