<# --------------------------------------------------------------------------- Module......: BackupJobs.psm1 Projekt.....: Veeam Enterprise Installer Version.....: 2.0.0 Beschreibung: Verwaltung von Veeam Backup Jobs. Ziel: Veeam Backup & Replication 13 Funktionen: - Job Definition - Zeitplanung - Retention - Guest Processing - Job Prüfung ---------------------------------------------------------------------------#> Set-StrictMode -Version Latest #region Variablen $Script:BackupJobsVersion = "2.0.0" #endregion ############################################################ # New-BackupJobDefinition ############################################################ function New-BackupJobDefinition { <# .SYNOPSIS Erstellt Backup Job Definition. #> param( [Parameter(Mandatory)] [string]$Name, [Parameter(Mandatory)] [string]$Repository, [int]$RetentionDays = 14 ) [PSCustomObject]@{ Name = $Name Repository = $Repository RetentionDays = $RetentionDays Enabled = $true Created = Get-Date } } ############################################################ # Test-BackupJobDefinition ############################################################ function Test-BackupJobDefinition { <# .SYNOPSIS Prüft Job Definition. #> param( [Parameter(Mandatory)] [PSCustomObject]$Job ) [PSCustomObject]@{ Name = $Job.Name RepositoryDefined = ( ![string]::IsNullOrWhiteSpace( $Job.Repository ) ) RetentionValid = ( $Job.RetentionDays -gt 0 ) Status = "Checked" } } #Beginn PART 2 ############################################################ # New-BackupSchedule ############################################################ function New-BackupSchedule { <# .SYNOPSIS Erstellt Backup Zeitplan. #> param( [ValidateSet( "Daily", "Weekly", "Monthly" )] [string]$Type = "Daily", [string]$Time = "22:00" ) [PSCustomObject]@{ Type = $Type Time = $Time Enabled = $true Created = Get-Date } } ############################################################ # New-FullBackupSchedule ############################################################ function New-FullBackupSchedule { <# .SYNOPSIS Erstellt Full Backup Planung. #> param( [ValidateSet( "Weekly", "Monthly" )] [string]$Type = "Weekly", [string]$Day = "Saturday" ) [PSCustomObject]@{ Type = "Full Backup" Schedule = $Type Day = $Day Enabled = $true } } ############################################################ # New-SyntheticFullConfiguration ############################################################ function New-SyntheticFullConfiguration { <# .SYNOPSIS Erstellt Synthetic Full Konfiguration. #> param( [bool]$Enabled = $true, [string]$Day = "Saturday" ) [PSCustomObject]@{ Enabled = $Enabled Day = $Day Type = "Synthetic Full" } } ############################################################ # Get-BackupJobOptions ############################################################ function Get-BackupJobOptions { <# .SYNOPSIS Standard Job Optionen. #> [PSCustomObject]@{ Compression = "Optimal" StorageOptimization = "LocalTarget" Encryption = $true ChangedBlockTracking = $true } } #Beginn PART 3 ############################################################ # New-ApplicationAwareConfiguration ############################################################ function New-ApplicationAwareConfiguration { <# .SYNOPSIS Erstellt Application Aware Processing. #> param( [bool]$Enabled = $true, [bool]$RequireSuccessfulBackup = $true ) [PSCustomObject]@{ Enabled = $Enabled RequireSuccessfulBackup = $RequireSuccessfulBackup VSS = $true SQLProcessing = $true ExchangeProcessing = $true } } ############################################################ # New-GuestProcessingConfiguration ############################################################ function New-GuestProcessingConfiguration { <# .SYNOPSIS Erstellt Guest Processing Einstellungen. #> param( [string]$CredentialAccount, [bool]$EnableGuestIndexing = $false ) [PSCustomObject]@{ Enabled = $true Credential = $CredentialAccount GuestIndexing = $EnableGuestIndexing FileSystemIndexing = $false } } ############################################################ # New-BackupCredentialReference ############################################################ function New-BackupCredentialReference { <# .SYNOPSIS Erstellt Credential Referenz. #> param( [Parameter(Mandatory)] [string]$Account ) [PSCustomObject]@{ Account = $Account Protected = $true Created = Get-Date } } ############################################################ # Deploy-BackupJobDefinition ############################################################ function Deploy-BackupJobDefinition { <# .SYNOPSIS Bereitet Backup Job Deployment vor. #> param( [Parameter(Mandatory)] [PSCustomObject]$Job ) $Validation = Test-BackupJobDefinition ` -Job $Job [PSCustomObject]@{ Job = $Job Validation = $Validation DeploymentReady = ( $Validation.RepositoryDefined ` -and $Validation.RetentionValid ) Time = Get-Date } } #Beginn PART 4 ############################################################ # New-BackupJobDefinitionFile ############################################################ function New-BackupJobDefinitionFile { <# .SYNOPSIS Speichert Job Definition. #> param( [Parameter(Mandatory)] [PSCustomObject]$Job, [string]$Path = "C:\ProgramData\VeeamInstaller\Jobs" ) if(!(Test-Path $Path)) { New-Item ` -Path $Path ` -ItemType Directory ` -Force | Out-Null } $File = Join-Path ` $Path ` ( $Job.Name + ".json" ) $Job | ConvertTo-Json ` -Depth 8 | Out-File ` -FilePath $File ` -Encoding UTF8 return $File } ############################################################ # Get-BackupJobDefinitions ############################################################ function Get-BackupJobDefinitions { <# .SYNOPSIS Lädt Job Definitionen. #> param( [string]$Path = "C:\ProgramData\VeeamInstaller\Jobs" ) if(!(Test-Path $Path)) { return $null } Get-ChildItem ` -Path $Path ` -Filter "*.json" | ForEach-Object { Get-Content $_.FullName | ConvertFrom-Json } } ############################################################ # Test-BackupJobHealth ############################################################ function Test-BackupJobHealth { <# .SYNOPSIS Prüft Backup Job Status. #> param( [Parameter(Mandatory)] [PSCustomObject]$Job ) [PSCustomObject]@{ Name = $Job.Name Enabled = $Job.Enabled Repository = $Job.Repository Retention = $Job.RetentionDays Status = "Ready" Checked = Get-Date } } ############################################################ # Get-BackupJobReport ############################################################ function Get-BackupJobReport { <# .SYNOPSIS Erstellt Job Report. #> param( [Parameter(Mandatory)] [PSCustomObject]$Job ) [PSCustomObject]@{ Job = $Job Health = Test-BackupJobHealth ` -Job $Job Options = Get-BackupJobOptions Time = Get-Date } } #Beginn PART 5 ############################################################ # Deploy-BackupEnvironment ############################################################ function Deploy-BackupEnvironment { <# .SYNOPSIS Bereitet komplette Backup Umgebung vor. #> param( [Parameter(Mandatory)] [array]$Jobs ) $Results = @() foreach($Job in $Jobs) { $Results += Deploy-BackupJobDefinition ` -Job $Job } return $Results } ############################################################ # Test-BackupEnvironment ############################################################ function Test-BackupEnvironment { <# .SYNOPSIS Prüft Backup Umgebung. #> param( [Parameter(Mandatory)] [array]$Jobs ) $Report = @() foreach($Job in $Jobs) { $Report += Test-BackupJobHealth ` -Job $Job } return $Report } ############################################################ # Get-BackupConfigurationSummary ############################################################ function Get-BackupConfigurationSummary { <# .SYNOPSIS Erstellt Zusammenfassung. #> param( [Parameter(Mandatory)] [array]$Jobs ) [PSCustomObject]@{ JobCount = $Jobs.Count EnabledJobs = ( $Jobs | Where-Object { $_.Enabled } ).Count Repositories = ( $Jobs.Repository | Sort-Object | Select-Object -Unique ) Created = Get-Date } } ############################################################ # Remove-BackupJobDefinition ############################################################ function Remove-BackupJobDefinition { <# .SYNOPSIS Entfernt gespeicherte Job Definition. #> param( [Parameter(Mandatory)] [string]$Name, [string]$Path = "C:\ProgramData\VeeamInstaller\Jobs" ) $File = Join-Path ` $Path ` ( $Name + ".json" ) if(Test-Path $File) { Remove-Item ` -Path $File ` -Force return $true } return $false } #Beginn PART 6 ############################################################ # Get-BackupJobConfigurationReport ############################################################ function Get-BackupJobConfigurationReport { <# .SYNOPSIS Erstellt vollständigen Job Bericht. #> param( [Parameter(Mandatory)] [array]$Jobs ) [PSCustomObject]@{ Summary = Get-BackupConfigurationSummary ` -Jobs $Jobs Health = Test-BackupEnvironment ` -Jobs $Jobs Jobs = $Jobs Generated = Get-Date } } ############################################################ # Test-BackupConfiguration ############################################################ function Test-BackupConfiguration { <# .SYNOPSIS Vollständige Backup Prüfung. #> param( [Parameter(Mandatory)] [array]$Jobs ) $Report = Get-BackupJobConfigurationReport ` -Jobs $Jobs [PSCustomObject]@{ Valid = ( $Report.Health.Status -notcontains "ERROR" ) Report = $Report Time = Get-Date } } ############################################################ # Get-BackupJobsModuleInformation ############################################################ function Get-BackupJobsModuleInformation { <# .SYNOPSIS Liefert Modulstatus. #> [PSCustomObject]@{ Module = "BackupJobs.psm1" Version = $Script:BackupJobsVersion Loaded = $true } } #Beginn PART 7 ############################################################ # Export Module Functions ############################################################ Export-ModuleMember ` -Function ` New-BackupJobDefinition, Test-BackupJobDefinition, New-BackupSchedule, New-FullBackupSchedule, New-SyntheticFullConfiguration, Get-BackupJobOptions, New-ApplicationAwareConfiguration, New-GuestProcessingConfiguration, New-BackupCredentialReference, Deploy-BackupJobDefinition, New-BackupJobDefinitionFile, Get-BackupJobDefinitions, Test-BackupJobHealth, Get-BackupJobReport, Deploy-BackupEnvironment, Test-BackupEnvironment, Get-BackupConfigurationSummary, Remove-BackupJobDefinition, Get-BackupJobConfigurationReport, Test-BackupConfiguration, Get-BackupJobsModuleInformation ############################################################ # Ende BackupJobs.psm1 ############################################################