git add .
git commit -m "Neue Skripte hinzugefügt" git push
This commit is contained in:
@@ -0,0 +1,909 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Veeam Enterprise Installer
|
||||
|
||||
.DESCRIPTION
|
||||
Automatisierte Installation und Konfiguration von:
|
||||
- Veeam Backup & Replication
|
||||
- SQL Konfiguration
|
||||
- Repository
|
||||
- Backup Jobs
|
||||
- Reporting
|
||||
- Logging
|
||||
- Dry-Run Unterstützung
|
||||
|
||||
.VERSION
|
||||
1.0.0
|
||||
#>
|
||||
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
|
||||
############################################################
|
||||
# Script Parameter
|
||||
############################################################
|
||||
|
||||
param(
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
|
||||
[string]$VeeamSourcePath =
|
||||
|
||||
"D:\Install\Veeam13",
|
||||
|
||||
|
||||
|
||||
[Parameter(Mandatory=$false)]
|
||||
|
||||
[switch]$DryRun
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Globale Variablen
|
||||
############################################################
|
||||
|
||||
$Script:InstallerRoot =
|
||||
|
||||
Split-Path `
|
||||
$PSScriptRoot `
|
||||
-Parent
|
||||
|
||||
|
||||
|
||||
$Script:ModulePath =
|
||||
|
||||
Join-Path `
|
||||
$Script:InstallerRoot `
|
||||
"Modules"
|
||||
|
||||
|
||||
|
||||
$Script:ConfigPath =
|
||||
|
||||
Join-Path `
|
||||
$Script:InstallerRoot `
|
||||
"Config\VeeamConfig.json"
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Import Installer Module
|
||||
############################################################
|
||||
|
||||
function Import-InstallerModules {
|
||||
|
||||
|
||||
$Modules = @(
|
||||
|
||||
"Core\Logging.psm1",
|
||||
|
||||
"Core\Configuration.psm1",
|
||||
|
||||
"Core\Utilities.psm1",
|
||||
|
||||
"Core\Security.psm1",
|
||||
|
||||
"Core\SQL.psm1",
|
||||
|
||||
"Core\DryRun.psm1",
|
||||
|
||||
"Veeam\VeeamInstallation.psm1",
|
||||
|
||||
"Veeam\Repository.psm1",
|
||||
|
||||
"Veeam\BackupJobs.psm1"
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
foreach($Module in $Modules)
|
||||
{
|
||||
|
||||
|
||||
$Path =
|
||||
|
||||
Join-Path `
|
||||
|
||||
$Script:ModulePath `
|
||||
|
||||
$Module
|
||||
|
||||
|
||||
|
||||
if(Test-Path $Path)
|
||||
{
|
||||
|
||||
Import-Module `
|
||||
|
||||
$Path `
|
||||
|
||||
-Force
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
throw `
|
||||
|
||||
"Modul nicht gefunden: $Path"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#Begin PART 2
|
||||
############################################################
|
||||
# Installer Initialisierung
|
||||
############################################################
|
||||
|
||||
function Initialize-Installer {
|
||||
|
||||
|
||||
Write-Host ""
|
||||
|
||||
Write-Host `
|
||||
"Initialisiere Veeam Enterprise Installer..." `
|
||||
-ForegroundColor Cyan
|
||||
|
||||
|
||||
|
||||
Test-AdministratorRights
|
||||
|
||||
|
||||
|
||||
Import-InstallerModules
|
||||
|
||||
|
||||
|
||||
Write-Host `
|
||||
"Module erfolgreich geladen." `
|
||||
-ForegroundColor Green
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Administrator Prüfung
|
||||
############################################################
|
||||
|
||||
function Test-AdministratorRights {
|
||||
|
||||
|
||||
$CurrentUser =
|
||||
|
||||
[Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
|
||||
|
||||
|
||||
$Principal =
|
||||
|
||||
New-Object `
|
||||
Security.Principal.WindowsPrincipal(
|
||||
$CurrentUser
|
||||
)
|
||||
|
||||
|
||||
|
||||
if(
|
||||
!$Principal.IsInRole(
|
||||
[Security.Principal.WindowsBuiltInRole]::Administrator
|
||||
)
|
||||
)
|
||||
{
|
||||
|
||||
throw `
|
||||
"Script muss als Administrator ausgeführt werden."
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Konfiguration laden
|
||||
############################################################
|
||||
|
||||
function Get-InstallerConfiguration {
|
||||
|
||||
|
||||
$Config =
|
||||
|
||||
Get-VeeamConfig
|
||||
|
||||
|
||||
|
||||
$Validation =
|
||||
|
||||
Test-VeeamConfig `
|
||||
|
||||
-Configuration $Config
|
||||
|
||||
|
||||
|
||||
if(!$Validation.Valid)
|
||||
{
|
||||
|
||||
throw `
|
||||
"Konfigurationsprüfung fehlgeschlagen."
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $Config
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Voraussetzungen prüfen
|
||||
############################################################
|
||||
|
||||
function Test-InstallerPrerequisites {
|
||||
|
||||
|
||||
Write-Host ""
|
||||
|
||||
Write-Host `
|
||||
"Prüfe Systemvoraussetzungen..." `
|
||||
-ForegroundColor Yellow
|
||||
|
||||
|
||||
|
||||
$Checks = @()
|
||||
|
||||
|
||||
|
||||
$Checks +=
|
||||
|
||||
[PSCustomObject]@{
|
||||
|
||||
Name =
|
||||
|
||||
"Administrator"
|
||||
|
||||
|
||||
|
||||
Result =
|
||||
|
||||
$true
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$Checks +=
|
||||
|
||||
[PSCustomObject]@{
|
||||
|
||||
Name =
|
||||
|
||||
"PowerShell"
|
||||
|
||||
|
||||
|
||||
Result =
|
||||
|
||||
(
|
||||
$PSVersionTable.PSVersion.Major -ge 5
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $Checks
|
||||
|
||||
}
|
||||
#Begin PART 3
|
||||
############################################################
|
||||
# SQL Prüfung
|
||||
############################################################
|
||||
|
||||
function Test-InstallerSQL {
|
||||
|
||||
|
||||
param(
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
|
||||
[PSCustomObject]$Configuration
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
Write-Host ""
|
||||
|
||||
Write-Host `
|
||||
"Prüfe SQL Konfiguration..." `
|
||||
-ForegroundColor Yellow
|
||||
|
||||
|
||||
|
||||
$Result =
|
||||
|
||||
Test-SQLConfiguration `
|
||||
|
||||
-Server $Configuration.SQL.Server `
|
||||
|
||||
-Instance $Configuration.SQL.Instance `
|
||||
|
||||
-Database $Configuration.SQL.Database
|
||||
|
||||
|
||||
|
||||
return $Result
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Veeam Installation
|
||||
############################################################
|
||||
|
||||
function Install-VeeamProduct {
|
||||
|
||||
|
||||
param(
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
|
||||
[PSCustomObject]$Configuration,
|
||||
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
|
||||
[string]$SourcePath
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
Write-Host ""
|
||||
|
||||
Write-Host `
|
||||
"Installiere Veeam..." `
|
||||
-ForegroundColor Yellow
|
||||
|
||||
|
||||
|
||||
if($DryRun)
|
||||
{
|
||||
|
||||
return (
|
||||
|
||||
Test-DryRunInstallation -SourcePath $SourcePath -SQLServer $Configuration.SQL.Server -Database $Configuration.SQL.Database
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
|
||||
Invoke-VeeamInstallation -SourcePath $SourcePath -SQLServer $Configuration.SQL.Server -SQLInstance $Configuration.SQL.Instance -Database $Configuration.SQL.Database
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Repository Initialisierung
|
||||
############################################################
|
||||
|
||||
function Initialize-BackupRepository {
|
||||
|
||||
|
||||
param(
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
|
||||
[PSCustomObject]$Configuration
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
Write-Host ""
|
||||
|
||||
Write-Host `
|
||||
"Erstelle Repository..." `
|
||||
-ForegroundColor Yellow
|
||||
|
||||
|
||||
|
||||
if($DryRun)
|
||||
{
|
||||
|
||||
return (
|
||||
|
||||
Test-DryRunRepository -Name $Configuration.Repository.Name -Path $Configuration.Repository.Path
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
|
||||
Deploy-RepositoryConfiguration -Name $Configuration.Repository.Name -Path $Configuration.Repository.Path -RetentionDays $Configuration.Repository.RetentionDays
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
#Begin PART 4
|
||||
############################################################
|
||||
# Backup Job Initialisierung
|
||||
############################################################
|
||||
|
||||
function Initialize-BackupJobs
|
||||
{
|
||||
param(
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
|
||||
[PSCustomObject]$Configuration
|
||||
|
||||
)
|
||||
|
||||
Write-Host ""
|
||||
|
||||
Write-Host `
|
||||
"Erstelle Backup Jobs..." `
|
||||
-ForegroundColor Yellow
|
||||
|
||||
|
||||
|
||||
if($DryRun)
|
||||
{
|
||||
|
||||
return (
|
||||
|
||||
Test-DryRunBackupJob -Name $Configuration.BackupJob.Name -Repository $Configuration.Repository.Name -RetentionDays $Configuration.Repository.RetentionDays
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$Job =
|
||||
|
||||
New-BackupJobDefinition `
|
||||
|
||||
-Name $Configuration.BackupJob.Name `
|
||||
|
||||
-Repository $Configuration.Repository.Name `
|
||||
|
||||
-RetentionDays $Configuration.Repository.RetentionDays
|
||||
|
||||
|
||||
|
||||
$Schedule = New-BackupSchedule -Time $Configuration.BackupJob.Schedule
|
||||
|
||||
$ApplicationAware = New-ApplicationAwareConfiguration -Enabled $Configuration.Options.ApplicationAware
|
||||
|
||||
|
||||
|
||||
return [PSCustomObject]@{
|
||||
|
||||
|
||||
Job = $Job
|
||||
|
||||
Schedule = $Schedule
|
||||
|
||||
ApplicationAware = $ApplicationAware
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Haupt Installationsablauf
|
||||
############################################################
|
||||
|
||||
function Start-VeeamEnterpriseInstall {
|
||||
|
||||
|
||||
param(
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
|
||||
[string]$VeeamSourcePath
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
$Configuration = Get-InstallerConfiguration
|
||||
|
||||
if($DryRun)
|
||||
{
|
||||
|
||||
Write-Host ""
|
||||
|
||||
Write-Host "DRY-RUN aktiviert" -ForegroundColor Yellow
|
||||
|
||||
$Simulation = Invoke-DryRunPipeline -Configuration $Configuration
|
||||
|
||||
return (
|
||||
|
||||
Get-DryRunReport -Results $Simulation
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$SystemCheck = Test-InstallerPrerequisites
|
||||
|
||||
$SQLCheck = Test-InstallerSQL -Configuration $Configuration
|
||||
|
||||
$Installation = Install-VeeamProduct -Configuration $Configuration -SourcePath $VeeamSourcePath
|
||||
|
||||
$Repository = Initialize-BackupRepository -Configuration $Configuration
|
||||
|
||||
$Jobs = Initialize-BackupJobs -Configuration $Configuration
|
||||
|
||||
|
||||
|
||||
return [PSCustomObject]@{
|
||||
|
||||
Configuration = $Configuration
|
||||
|
||||
System = $SystemCheck
|
||||
|
||||
SQL = $SQLCheck
|
||||
|
||||
Installation = $Installation
|
||||
|
||||
Repository = $Repository
|
||||
|
||||
Jobs =$Jobs
|
||||
|
||||
Completed = Get-Date
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
Write-ExceptionLog -Exception $_.Exception -Context "Installation"
|
||||
throw
|
||||
}
|
||||
|
||||
}
|
||||
#Begin PART 5
|
||||
############################################################
|
||||
# Enterprise Report
|
||||
############################################################
|
||||
|
||||
function Get-EnterpriseInstallationReport {
|
||||
|
||||
|
||||
param(
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
|
||||
[PSCustomObject]$Result
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
[PSCustomObject]@{
|
||||
|
||||
|
||||
Computer =
|
||||
|
||||
$env:COMPUTERNAME
|
||||
|
||||
|
||||
|
||||
Mode =
|
||||
|
||||
if($DryRun)
|
||||
{
|
||||
|
||||
"DryRun"
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
"Production"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
VeeamVersion =
|
||||
|
||||
$Result.Configuration.Veeam.Version
|
||||
|
||||
|
||||
|
||||
SQLServer =
|
||||
|
||||
$Result.Configuration.SQL.Server
|
||||
|
||||
|
||||
|
||||
SQLInstance =
|
||||
|
||||
$Result.Configuration.SQL.Instance
|
||||
|
||||
|
||||
|
||||
Database =
|
||||
|
||||
$Result.Configuration.SQL.Database
|
||||
|
||||
|
||||
|
||||
Repository =
|
||||
|
||||
$Result.Configuration.Repository.Path
|
||||
|
||||
|
||||
|
||||
BackupJob =
|
||||
|
||||
$Result.Configuration.BackupJob.Name
|
||||
|
||||
|
||||
|
||||
Completed =
|
||||
|
||||
Get-Date
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Report speichern
|
||||
############################################################
|
||||
|
||||
function Save-EnterpriseReport {
|
||||
|
||||
|
||||
param(
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
|
||||
[PSCustomObject]$Report
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
$Path =
|
||||
|
||||
Join-Path `
|
||||
|
||||
$Script:InstallerRoot `
|
||||
|
||||
"Reports"
|
||||
|
||||
|
||||
|
||||
if(!(Test-Path $Path))
|
||||
{
|
||||
|
||||
New-Item `
|
||||
|
||||
-Path $Path `
|
||||
|
||||
-ItemType Directory `
|
||||
|
||||
-Force |
|
||||
|
||||
Out-Null
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$File =
|
||||
|
||||
Join-Path `
|
||||
|
||||
$Path `
|
||||
|
||||
(
|
||||
"EnterpriseReport_" +
|
||||
|
||||
(
|
||||
Get-Date `
|
||||
-Format "yyyyMMdd_HHmmss"
|
||||
) +
|
||||
|
||||
".json"
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
$Report |
|
||||
|
||||
ConvertTo-Json `
|
||||
|
||||
-Depth 10 |
|
||||
|
||||
Out-File `
|
||||
|
||||
-FilePath $File `
|
||||
|
||||
-Encoding UTF8
|
||||
|
||||
|
||||
|
||||
return $File
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Hauptausführung
|
||||
############################################################
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
Initialize-Installer
|
||||
|
||||
|
||||
|
||||
Initialize-EnterpriseLog `
|
||||
|
||||
-Name "VeeamEnterprise"
|
||||
|
||||
|
||||
|
||||
Write-EnterpriseLog `
|
||||
|
||||
-Level INFO `
|
||||
|
||||
-Message "Installer gestartet"
|
||||
|
||||
|
||||
|
||||
if($DryRun)
|
||||
{
|
||||
|
||||
Enable-DryRunMode
|
||||
|
||||
Write-EnterpriseLog `
|
||||
|
||||
-Level INFO `
|
||||
|
||||
-Message "DryRun aktiviert"
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$Result =
|
||||
|
||||
Start-VeeamEnterpriseInstall `
|
||||
|
||||
-VeeamSourcePath $VeeamSourcePath
|
||||
|
||||
|
||||
|
||||
$Report =
|
||||
|
||||
Get-EnterpriseInstallationReport `
|
||||
|
||||
-Result $Result
|
||||
|
||||
|
||||
|
||||
$ReportFile =
|
||||
|
||||
Save-EnterpriseReport `
|
||||
|
||||
-Report $Report
|
||||
|
||||
|
||||
|
||||
Write-EnterpriseLog `
|
||||
|
||||
-Level INFO `
|
||||
|
||||
-Message (
|
||||
|
||||
"Installation abgeschlossen: " +
|
||||
$ReportFile
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
||||
Write-Host ""
|
||||
|
||||
Write-Host `
|
||||
"Installation abgeschlossen" `
|
||||
-ForegroundColor Green
|
||||
|
||||
|
||||
|
||||
Write-Host `
|
||||
$ReportFile `
|
||||
-ForegroundColor Cyan
|
||||
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Write-ExceptionLog `
|
||||
|
||||
-Exception $_.Exception `
|
||||
|
||||
-Context "Main Installer"
|
||||
|
||||
|
||||
|
||||
Write-Host ""
|
||||
|
||||
Write-Host `
|
||||
"Installation fehlgeschlagen" `
|
||||
-ForegroundColor Red
|
||||
|
||||
|
||||
|
||||
exit 1
|
||||
|
||||
}
|
||||
#Begin PART 6
|
||||
############################################################
|
||||
# Abschluss
|
||||
############################################################
|
||||
|
||||
Write-EnterpriseLog `
|
||||
|
||||
-Level INFO `
|
||||
|
||||
-Message "Installer beendet"
|
||||
|
||||
|
||||
|
||||
Write-AuditEvent `
|
||||
|
||||
-Action "Installer beendet" `
|
||||
|
||||
-Status "SUCCESS"
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Ende Install-VeeamEnterprise.ps1
|
||||
############################################################
|
||||
Reference in New Issue
Block a user