Version 1.0.1
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
},
|
||||
|
||||
"SQL": {
|
||||
"Engine": "MSSQL",
|
||||
"InstallNew": false,
|
||||
"Server": "Auto",
|
||||
"Instance": "VEEAMSQLSERVER",
|
||||
"Database": "VeeamBackup"
|
||||
@@ -17,7 +19,7 @@
|
||||
|
||||
"Repository": {
|
||||
"Name": "PrimaryRepository",
|
||||
"Path": "D:\\VeeamRepository",
|
||||
"Path": "Auto",
|
||||
"RetentionDays": 30
|
||||
},
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
- Dry-Run Unterstützung
|
||||
|
||||
.VERSION
|
||||
1.0.0
|
||||
1.0.1
|
||||
#>
|
||||
|
||||
|
||||
@@ -59,13 +59,6 @@ $Script:InstallerRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$Script:ModulePath = Join-Path $Script:InstallerRoot "Modules"
|
||||
$Script:ConfigPath = Join-Path (Join-Path $Script:InstallerRoot "Config") "VeeamConfig.json"
|
||||
|
||||
if([string]::IsNullOrWhiteSpace($VeeamAnswerFile))
|
||||
{
|
||||
$VeeamAnswerFile = Join-Path (Join-Path $Script:InstallerRoot "Config") "VeeamAnswerFile.xml"
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Import Installer Module
|
||||
############################################################
|
||||
@@ -390,13 +383,44 @@ function Install-VeeamProduct {
|
||||
|
||||
|
||||
|
||||
return (
|
||||
|
||||
Invoke-VeeamInstallation `
|
||||
$InstallResult = Invoke-VeeamInstallation `
|
||||
-SourcePath $SourcePath `
|
||||
-AnswerFile $AnswerFile
|
||||
-AnswerFile $AnswerFile `
|
||||
-SkipNetworkLogonErrors
|
||||
|
||||
|
||||
if(
|
||||
$null -eq $InstallResult -or
|
||||
$null -eq $InstallResult.Result -or
|
||||
!$InstallResult.Result.Successful
|
||||
)
|
||||
{
|
||||
$ExitCode = $null
|
||||
$LogFile = $null
|
||||
|
||||
if($null -ne $InstallResult -and $null -ne $InstallResult.Result)
|
||||
{
|
||||
$ExitCode = $InstallResult.Result.ExitCode
|
||||
$LogFile = $InstallResult.Result.LogFile
|
||||
}
|
||||
|
||||
$DetailLogFolder = $null
|
||||
if($null -ne $InstallResult)
|
||||
{
|
||||
$DetailLogFolder = $InstallResult.LogFolder
|
||||
}
|
||||
|
||||
throw "Veeam-Installation fehlgeschlagen. ExitCode: $ExitCode; Launcher-Log: $LogFile; Veeam-Logs: $DetailLogFolder"
|
||||
}
|
||||
|
||||
|
||||
if($InstallResult.Result.RebootRequired)
|
||||
{
|
||||
throw "Veeam-Installation war erfolgreich, benötigt aber einen Neustart. Repository-Konfiguration wurde noch nicht gestartet."
|
||||
}
|
||||
|
||||
|
||||
return $InstallResult
|
||||
|
||||
}
|
||||
|
||||
@@ -447,6 +471,62 @@ function Initialize-BackupRepository {
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
############################################################
|
||||
# Temporäres lokales Veeam-Administratorkonto
|
||||
############################################################
|
||||
|
||||
function New-LocalVeeamAdministrator {
|
||||
$UserName = "VEEAM"
|
||||
$PlainPassword = "P@ssw0rd1234."
|
||||
|
||||
if($Script:IsDryRun) {
|
||||
return [PSCustomObject]@{
|
||||
UserName = ".\$UserName"
|
||||
Password = "Wird im Dry-Run nicht gesetzt"
|
||||
Created = $false
|
||||
}
|
||||
}
|
||||
|
||||
if(!(Get-Command New-LocalUser -ErrorAction SilentlyContinue)) {
|
||||
throw "New-LocalUser ist auf diesem System nicht verfügbar. Das lokale Veeam-Administratorkonto konnte nicht erstellt werden."
|
||||
}
|
||||
|
||||
$SecurePassword = ConvertTo-SecureString -String $PlainPassword -AsPlainText -Force
|
||||
$ExistingUser = Get-LocalUser -Name $UserName -ErrorAction SilentlyContinue
|
||||
if($null -eq $ExistingUser) {
|
||||
New-LocalUser `
|
||||
-Name $UserName `
|
||||
-Password $SecurePassword `
|
||||
-Description "Temporäres Veeam-Initialisierungskonto" `
|
||||
-PasswordNeverExpires:$true `
|
||||
-UserMayNotChangePassword:$false `
|
||||
-AccountNeverExpires | Out-Null
|
||||
}
|
||||
else {
|
||||
Set-LocalUser -Name $UserName -Password $SecurePassword -PasswordNeverExpires $true
|
||||
Enable-LocalUser -Name $UserName
|
||||
}
|
||||
|
||||
$AdministratorsGroup = ([Security.Principal.SecurityIdentifier]"S-1-5-32-544").Translate([Security.Principal.NTAccount]).Value.Split("\")[-1]
|
||||
if(-not (Get-LocalGroupMember -Group $AdministratorsGroup -Member $UserName -ErrorAction SilentlyContinue)) {
|
||||
Add-LocalGroupMember -Group $AdministratorsGroup -Member $UserName -ErrorAction Stop
|
||||
}
|
||||
|
||||
$VeeamGroup = Get-LocalGroup -Name "Veeam Backup Administrators" -ErrorAction SilentlyContinue
|
||||
if($null -ne $VeeamGroup) {
|
||||
if(-not (Get-LocalGroupMember -Group $VeeamGroup.Name -Member $UserName -ErrorAction SilentlyContinue)) {
|
||||
Add-LocalGroupMember -Group $VeeamGroup.Name -Member $UserName -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
|
||||
return [PSCustomObject]@{
|
||||
UserName = ".\$UserName"
|
||||
Password = $PlainPassword
|
||||
Created = $true
|
||||
}
|
||||
}
|
||||
#Begin PART 4
|
||||
############################################################
|
||||
# Backup Job Initialisierung
|
||||
@@ -542,8 +622,7 @@ function Start-VeeamEnterpriseInstall {
|
||||
[string]$VeeamSourcePath,
|
||||
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
|
||||
[AllowEmptyString()]
|
||||
[string]$VeeamAnswerFile
|
||||
|
||||
)
|
||||
@@ -560,6 +639,10 @@ function Start-VeeamEnterpriseInstall {
|
||||
-SourcePath $VeeamSourcePath `
|
||||
-ConfiguredPath ([string]$Configuration.Veeam.SourcePath)
|
||||
|
||||
$Configuration.Repository.Path = Resolve-RepositoryPath `
|
||||
-Path ([string]$Configuration.Repository.Path) `
|
||||
-InstallationSource $VeeamSourcePath
|
||||
|
||||
$SystemCheck = Test-InstallerPrerequisites
|
||||
|
||||
if($Script:IsDryRun)
|
||||
@@ -611,7 +694,42 @@ function Start-VeeamEnterpriseInstall {
|
||||
else
|
||||
{
|
||||
|
||||
$SQLCheck = Test-InstallerSQL -Configuration $Configuration
|
||||
if(
|
||||
$Configuration.SQL.Engine -eq "PostgreSQL" -and
|
||||
$Configuration.SQL.InstallNew
|
||||
)
|
||||
{
|
||||
$SQLCheck = [PSCustomObject]@{
|
||||
Engine = "PostgreSQL"
|
||||
Server = "localhost:5432"
|
||||
Database = $Configuration.SQL.Database
|
||||
ConnectionTested = $false
|
||||
Status = "WillBeInstalledByVeeam"
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$SQLCheck = Test-InstallerSQL -Configuration $Configuration
|
||||
|
||||
Write-Host "Bereite Veeam-Datenbank und LocalSystem-Berechtigung vor..." -ForegroundColor Yellow
|
||||
$SQLPreparation = Initialize-VeeamSQLDatabase `
|
||||
-Server $Configuration.SQL.Server `
|
||||
-Instance $Configuration.SQL.Instance `
|
||||
-Database $Configuration.SQL.Database
|
||||
|
||||
Write-EnterpriseLog `
|
||||
-Level INFO `
|
||||
-Message ("SQL-Datenbank vorbereitet: {0}; Konto: {1}; Rolle: {2}" -f $SQLPreparation.Database, $SQLPreparation.ServiceAccount, $SQLPreparation.DatabaseRole)
|
||||
}
|
||||
|
||||
$VeeamAnswerFile = Resolve-VeeamAnswerFile `
|
||||
-AnswerFile $VeeamAnswerFile `
|
||||
-SourcePath $VeeamSourcePath `
|
||||
-LocalConfigPath (Join-Path $Script:InstallerRoot "Config") `
|
||||
-DatabaseEngine $Configuration.SQL.Engine `
|
||||
-SQLServer $Configuration.SQL.Server `
|
||||
-SQLInstance $Configuration.SQL.Instance `
|
||||
-DatabaseName $Configuration.SQL.Database
|
||||
|
||||
$Installation =
|
||||
Install-VeeamProduct `
|
||||
@@ -620,6 +738,14 @@ function Start-VeeamEnterpriseInstall {
|
||||
-AnswerFile $VeeamAnswerFile
|
||||
|
||||
|
||||
if($null -eq (Get-Module -ListAvailable -Name "Veeam.Backup.PowerShell"))
|
||||
{
|
||||
throw "Veeam wurde installiert, aber Veeam.Backup.PowerShell ist noch nicht verfügbar. Neustart oder neue PowerShell-Sitzung erforderlich."
|
||||
}
|
||||
|
||||
Import-Module "Veeam.Backup.PowerShell" -Force -ErrorAction Stop
|
||||
|
||||
|
||||
$Repository =
|
||||
Initialize-BackupRepository `
|
||||
-Configuration $Configuration
|
||||
@@ -857,6 +983,19 @@ if($Script:IsDryRun)
|
||||
|
||||
}
|
||||
|
||||
$VeeamAdmin = New-LocalVeeamAdministrator
|
||||
|
||||
if($VeeamAdmin.Created) {
|
||||
Write-EnterpriseLog -Level INFO -Message ("Lokales Veeam-Administratorkonto erstellt: {0}" -f $VeeamAdmin.UserName)
|
||||
Write-EnterpriseLog -Level WARNING -Message ("Temporäres Kennwort: {0}" -f $VeeamAdmin.Password)
|
||||
Write-EnterpriseLog -Level WARNING -Message "Nach der Veeam-Erstinitialisierung muss das temporäre Konto manuell gelöscht werden: Remove-LocalUser -Name 'VEEAM'"
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Lokales Veeam-Administratorkonto: $($VeeamAdmin.UserName)" -ForegroundColor Cyan
|
||||
Write-Host "Temporäres Kennwort: $($VeeamAdmin.Password)" -ForegroundColor Yellow
|
||||
Write-Host "Nach der Erstinitialisierung löschen: Remove-LocalUser -Name 'VEEAM'" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
$Result = Start-VeeamEnterpriseInstall `
|
||||
-VeeamSourcePath $VeeamSourcePath `
|
||||
-VeeamAnswerFile $VeeamAnswerFile
|
||||
|
||||
@@ -688,6 +688,83 @@ function Get-SQLDatabases {
|
||||
"
|
||||
|
||||
}
|
||||
|
||||
|
||||
############################################################
|
||||
# Initialize-VeeamSQLDatabase
|
||||
############################################################
|
||||
|
||||
function Initialize-VeeamSQLDatabase {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Legt die Veeam-Konfigurationsdatenbank vorab an und berechtigt
|
||||
das standardmäßige Veeam-Dienstkonto LocalSystem als db_owner.
|
||||
#>
|
||||
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$Server,
|
||||
[Parameter(Mandatory)][string]$Instance,
|
||||
[Parameter(Mandatory)][string]$Database
|
||||
)
|
||||
|
||||
if($Database -notmatch '^[A-Za-z0-9_]+$') {
|
||||
throw "Ungültiger SQL-Datenbankname: $Database"
|
||||
}
|
||||
|
||||
# Das integrierte LocalSystem-Konto ist sprachabhängig benannt
|
||||
# (z. B. NT-AUTORITÄT\SYSTEM auf einem deutschen Windows). Die SID ist
|
||||
# dagegen auf allen unterstützten Windows-Systemen identisch.
|
||||
$LocalSystemSid = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-18")
|
||||
$LocalSystemAccount = $LocalSystemSid.Translate([System.Security.Principal.NTAccount]).Value
|
||||
$AccountLiteral = $LocalSystemAccount.Replace("'", "''")
|
||||
$AccountIdentifier = $LocalSystemAccount.Replace("]", "]]" )
|
||||
|
||||
$CreateDatabaseQuery = @"
|
||||
IF SUSER_ID(N'$AccountLiteral') IS NULL
|
||||
BEGIN
|
||||
CREATE LOGIN [$AccountIdentifier] FROM WINDOWS;
|
||||
END;
|
||||
|
||||
IF DB_ID(@DatabaseName) IS NULL
|
||||
BEGIN
|
||||
CREATE DATABASE [$Database];
|
||||
END;
|
||||
"@
|
||||
|
||||
Invoke-SQLQuery `
|
||||
-Server $Server `
|
||||
-Instance $Instance `
|
||||
-Database "master" `
|
||||
-Query $CreateDatabaseQuery `
|
||||
-Parameters @{ DatabaseName = $Database } | Out-Null
|
||||
|
||||
$GrantDatabaseQuery = @"
|
||||
IF DATABASE_PRINCIPAL_ID(N'$AccountLiteral') IS NULL
|
||||
BEGIN
|
||||
CREATE USER [$AccountIdentifier] FOR LOGIN [$AccountIdentifier];
|
||||
END;
|
||||
|
||||
IF IS_ROLEMEMBER(N'db_owner', N'$AccountLiteral') <> 1
|
||||
BEGIN
|
||||
ALTER ROLE [db_owner] ADD MEMBER [$AccountIdentifier];
|
||||
END;
|
||||
"@
|
||||
|
||||
Invoke-SQLQuery `
|
||||
-Server $Server `
|
||||
-Instance $Instance `
|
||||
-Database $Database `
|
||||
-Query $GrantDatabaseQuery | Out-Null
|
||||
|
||||
return [PSCustomObject]@{
|
||||
Server = $Server
|
||||
Instance = $Instance
|
||||
Database = $Database
|
||||
ServiceAccount = $LocalSystemAccount
|
||||
DatabaseRole = "db_owner"
|
||||
Prepared = $true
|
||||
}
|
||||
}
|
||||
#Beginn PART 4
|
||||
############################################################
|
||||
# Test-DatabaseExists
|
||||
@@ -738,7 +815,7 @@ function Test-DatabaseExists {
|
||||
return (
|
||||
|
||||
$null -ne $Result -and
|
||||
$Result.Count -gt 0
|
||||
@($Result).Count -gt 0
|
||||
|
||||
)
|
||||
|
||||
@@ -1021,7 +1098,7 @@ function Test-SQLLoginExists {
|
||||
return (
|
||||
|
||||
$null -ne $Result -and
|
||||
$Result.Count -gt 0
|
||||
@($Result).Count -gt 0
|
||||
|
||||
)
|
||||
|
||||
@@ -1506,6 +1583,7 @@ Export-ModuleMember `
|
||||
New-SQLConnectionString,
|
||||
Test-SQLConnection,
|
||||
Invoke-SQLQuery,
|
||||
Initialize-VeeamSQLDatabase,
|
||||
Get-SQLDatabases,
|
||||
Test-DatabaseExists,
|
||||
New-SQLDatabase,
|
||||
|
||||
@@ -63,6 +63,52 @@ function Test-RepositoryPath {
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Resolve-RepositoryPath
|
||||
############################################################
|
||||
|
||||
function Resolve-RepositoryPath {
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$Path,
|
||||
[AllowEmptyString()][string]$InstallationSource
|
||||
)
|
||||
|
||||
if($Path -ne "Auto") {
|
||||
$Root = [IO.Path]::GetPathRoot($Path)
|
||||
if($env:OS -eq "Windows_NT" -and ![string]::IsNullOrWhiteSpace($Root)) {
|
||||
$DriveId = $Root.TrimEnd('\')
|
||||
$Drive = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = '$DriveId'" -ErrorAction SilentlyContinue
|
||||
if($null -ne $Drive -and $Drive.DriveType -ne 3) {
|
||||
throw "Repository-Pfad liegt nicht auf einer lokalen Festplatte: $Path"
|
||||
}
|
||||
}
|
||||
|
||||
return $Path
|
||||
}
|
||||
|
||||
if($env:OS -ne "Windows_NT") {
|
||||
throw "Automatische Repository-Laufwerkswahl wird nur unter Windows unterstützt."
|
||||
}
|
||||
|
||||
$SourceRoot = [IO.Path]::GetPathRoot($InstallationSource)
|
||||
$FixedDrives = @(
|
||||
Get-CimInstance Win32_LogicalDisk -Filter "DriveType = 3" -ErrorAction Stop |
|
||||
Where-Object {
|
||||
[string]::IsNullOrWhiteSpace($SourceRoot) -or
|
||||
$_.DeviceID -ne $SourceRoot.TrimEnd('\')
|
||||
} |
|
||||
Sort-Object FreeSpace -Descending
|
||||
)
|
||||
|
||||
if($FixedDrives.Count -eq 0) {
|
||||
throw "Keine lokale Festplatte für das Veeam-Repository gefunden."
|
||||
}
|
||||
|
||||
return (Join-Path ("{0}\" -f $FixedDrives[0].DeviceID) "VeeamRepository")
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# New-RepositoryFolder
|
||||
|
||||
@@ -1371,6 +1417,7 @@ function Get-RepositoryModuleInformation {
|
||||
Export-ModuleMember `
|
||||
-Function `
|
||||
Test-RepositoryPath,
|
||||
Resolve-RepositoryPath,
|
||||
New-RepositoryFolder,
|
||||
Get-RepositoryInformation,
|
||||
Test-RepositoryFreeSpace,
|
||||
|
||||
@@ -293,6 +293,266 @@ function Resolve-VeeamSourcePath {
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Resolve-VeeamAnswerFile
|
||||
############################################################
|
||||
|
||||
function Resolve-VeeamAnswerFile {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Ermittelt die Antwortdatei lokal oder relativ zur Installationsquelle.
|
||||
#>
|
||||
|
||||
param(
|
||||
[AllowEmptyString()][string]$AnswerFile,
|
||||
[Parameter(Mandatory)][string]$SourcePath,
|
||||
[Parameter(Mandatory)][string]$LocalConfigPath,
|
||||
[ValidateSet("MSSQL", "PostgreSQL")][string]$DatabaseEngine = "MSSQL",
|
||||
[string]$SQLServer,
|
||||
[string]$SQLInstance,
|
||||
[string]$DatabaseName = "VeeamBackup"
|
||||
)
|
||||
|
||||
if(![string]::IsNullOrWhiteSpace($AnswerFile)) {
|
||||
if(!(Test-Path -LiteralPath $AnswerFile -PathType Leaf)) {
|
||||
throw "Explizit angegebene Veeam-Antwortdatei nicht gefunden: $AnswerFile"
|
||||
}
|
||||
|
||||
return (Resolve-Path -LiteralPath $AnswerFile).Path
|
||||
}
|
||||
|
||||
$LocalAnswerFile = Join-Path $LocalConfigPath "VeeamAnswerFile.xml"
|
||||
if(Test-Path -LiteralPath $LocalAnswerFile -PathType Leaf) {
|
||||
[xml]$LocalXml = Get-Content -LiteralPath $LocalAnswerFile -Raw
|
||||
$RequiredValues = @(
|
||||
"ACCEPT_EULA",
|
||||
"ACCEPT_LICENSING_POLICY",
|
||||
"ACCEPT_THIRDPARTY_LICENSES",
|
||||
"ACCEPT_REQUIRED_SOFTWARE"
|
||||
)
|
||||
$Configured = $true
|
||||
|
||||
foreach($RequiredValue in $RequiredValues) {
|
||||
$Node = $LocalXml.SelectSingleNode("//property[@name='$RequiredValue']")
|
||||
if($null -eq $Node -or $Node.value -ne "1") {
|
||||
$Configured = $false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
# Ohne benutzerdefinierte Dienstkonto-Felder verwendet Veeam den
|
||||
# empfohlenen LocalSystem-Standard. Vorlagenwerte würden sonst als
|
||||
# echte Anmeldedaten validiert und die Installation blockieren.
|
||||
foreach($ServiceProperty in @("VBR_SERVICE_USER", "VBR_SERVICE_PASSWORD")) {
|
||||
if($null -ne $LocalXml.SelectSingleNode("//property[@name='$ServiceProperty']")) {
|
||||
$Configured = $false
|
||||
}
|
||||
}
|
||||
|
||||
$InstallNode = $LocalXml.SelectSingleNode("//property[@name='VBR_SQLSERVER_INSTALL']")
|
||||
$ExpectedInstallValue = if($DatabaseEngine -eq "MSSQL") { "0" } else { "1" }
|
||||
if($null -eq $InstallNode -or $InstallNode.value -ne $ExpectedInstallValue) {
|
||||
$Configured = $false
|
||||
}
|
||||
|
||||
if($DatabaseEngine -eq "MSSQL") {
|
||||
$ExpectedSqlTarget = "{0}\{1}" -f $SQLServer, $SQLInstance
|
||||
$EngineNode = $LocalXml.SelectSingleNode("//property[@name='VBR_SQLSERVER_ENGINE']")
|
||||
$ServerNode = $LocalXml.SelectSingleNode("//property[@name='VBR_SQLSERVER_SERVER']")
|
||||
$DatabaseNode = $LocalXml.SelectSingleNode("//property[@name='VBR_SQLSERVER_DATABASE']")
|
||||
|
||||
if(
|
||||
$null -eq $EngineNode -or $EngineNode.value -ne "0" -or
|
||||
$null -eq $ServerNode -or $ServerNode.value -ne $ExpectedSqlTarget -or
|
||||
$null -eq $DatabaseNode -or $DatabaseNode.value -ne $DatabaseName
|
||||
) {
|
||||
$Configured = $false
|
||||
}
|
||||
}
|
||||
|
||||
if($Configured) {
|
||||
return (Resolve-Path -LiteralPath $LocalAnswerFile).Path
|
||||
}
|
||||
|
||||
return New-VeeamAnswerFileFromTemplate `
|
||||
-TemplatePath $LocalAnswerFile `
|
||||
-DestinationPath $LocalAnswerFile `
|
||||
-DatabaseEngine $DatabaseEngine `
|
||||
-SQLServer $SQLServer `
|
||||
-SQLInstance $SQLInstance `
|
||||
-DatabaseName $DatabaseName
|
||||
}
|
||||
|
||||
$SourceRoot = $SourcePath
|
||||
if(Test-Path -LiteralPath $SourcePath -PathType Leaf) {
|
||||
$SourceRoot = Split-Path -Parent $SourcePath
|
||||
}
|
||||
|
||||
$Candidates = @(
|
||||
(Join-Path $SourceRoot "VeeamAnswerFile.xml"),
|
||||
(Join-Path $SourceRoot "Setup\Silent\VeeamAnswerFile.xml"),
|
||||
(Join-Path $SourceRoot "Setup\Silent\AnswerFiles\VBR\VbrAnswerFile_install.xml")
|
||||
)
|
||||
|
||||
foreach($Candidate in $Candidates) {
|
||||
if(Test-Path -LiteralPath $Candidate -PathType Leaf) {
|
||||
if([IO.Path]::GetFileName($Candidate) -eq "VbrAnswerFile_install.xml") {
|
||||
return New-VeeamAnswerFileFromTemplate `
|
||||
-TemplatePath $Candidate `
|
||||
-DestinationPath $LocalAnswerFile `
|
||||
-DatabaseEngine $DatabaseEngine `
|
||||
-SQLServer $SQLServer `
|
||||
-SQLInstance $SQLInstance `
|
||||
-DatabaseName $DatabaseName
|
||||
}
|
||||
|
||||
return (Resolve-Path -LiteralPath $Candidate).Path
|
||||
}
|
||||
}
|
||||
|
||||
$DiscoveredTemplate = Get-ChildItem `
|
||||
-LiteralPath $SourceRoot `
|
||||
-Recurse `
|
||||
-Filter "VbrAnswerFile_install.xml" `
|
||||
-File `
|
||||
-ErrorAction SilentlyContinue |
|
||||
Select-Object -First 1
|
||||
|
||||
if($null -ne $DiscoveredTemplate) {
|
||||
return New-VeeamAnswerFileFromTemplate `
|
||||
-TemplatePath $DiscoveredTemplate.FullName `
|
||||
-DestinationPath $LocalAnswerFile `
|
||||
-DatabaseEngine $DatabaseEngine `
|
||||
-SQLServer $SQLServer `
|
||||
-SQLInstance $SQLInstance `
|
||||
-DatabaseName $DatabaseName
|
||||
}
|
||||
|
||||
throw "Keine Veeam-Antwortdatei gefunden. Erwartet: Config\VeeamAnswerFile.xml oder DVD-Vorlage VbrAnswerFile_install.xml."
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# New-VeeamAnswerFileFromTemplate
|
||||
############################################################
|
||||
|
||||
function New-VeeamAnswerFileFromTemplate {
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$TemplatePath,
|
||||
[Parameter(Mandatory)][string]$DestinationPath,
|
||||
[ValidateSet("MSSQL", "PostgreSQL")][string]$DatabaseEngine = "MSSQL",
|
||||
[string]$SQLServer,
|
||||
[string]$SQLInstance,
|
||||
[string]$DatabaseName = "VeeamBackup"
|
||||
)
|
||||
|
||||
if(!(Test-Path -LiteralPath $TemplatePath -PathType Leaf)) {
|
||||
throw "Veeam-Antwortvorlage nicht gefunden: $TemplatePath"
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Veeam-Lizenzzustimmungen werden in der Antwortdatei automatisch gesetzt." -ForegroundColor Cyan
|
||||
|
||||
$DestinationDirectory = Split-Path -Parent $DestinationPath
|
||||
if(!(Test-Path -LiteralPath $DestinationDirectory -PathType Container)) {
|
||||
New-Item -Path $DestinationDirectory -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
$TemplateFullPath = [IO.Path]::GetFullPath($TemplatePath)
|
||||
$DestinationFullPath = [IO.Path]::GetFullPath($DestinationPath)
|
||||
|
||||
if($TemplateFullPath -ne $DestinationFullPath) {
|
||||
Copy-Item -LiteralPath $TemplatePath -Destination $DestinationPath -Force
|
||||
}
|
||||
|
||||
# Beim Kopieren von DVD/ISO kann das ReadOnly-Attribut erhalten bleiben.
|
||||
# Vor dem Speichern muss die lokale Antwortdatei beschreibbar sein.
|
||||
$DestinationItem = Get-Item -LiteralPath $DestinationPath -ErrorAction Stop
|
||||
if($DestinationItem.IsReadOnly) {
|
||||
$DestinationItem.IsReadOnly = $false
|
||||
}
|
||||
|
||||
[xml]$Xml = Get-Content -LiteralPath $DestinationPath -Raw
|
||||
$Root = $Xml.unattendedInstallationConfiguration
|
||||
|
||||
if($null -eq $Root -or $Root.bundle -ne "Vbr" -or $Root.mode -ne "install") {
|
||||
throw "Ungültige Veeam-VBR-Installationsvorlage: $TemplatePath"
|
||||
}
|
||||
|
||||
$PropertiesNode = $Root.properties
|
||||
if($null -eq $PropertiesNode) {
|
||||
throw "Eigenschaftsblock fehlt in der Veeam-Antwortvorlage."
|
||||
}
|
||||
|
||||
function Set-AnswerProperty {
|
||||
param([string]$Name, [string]$Value)
|
||||
|
||||
$Node = $Xml.SelectSingleNode("//property[@name='$Name']")
|
||||
if($null -eq $Node) {
|
||||
$Node = $Xml.CreateElement("property")
|
||||
$Node.SetAttribute("name", $Name)
|
||||
$PropertiesNode.AppendChild($Node) | Out-Null
|
||||
}
|
||||
|
||||
$Node.SetAttribute("value", $Value)
|
||||
}
|
||||
|
||||
foreach($Agreement in @(
|
||||
"ACCEPT_EULA",
|
||||
"ACCEPT_LICENSING_POLICY",
|
||||
"ACCEPT_THIRDPARTY_LICENSES",
|
||||
"ACCEPT_REQUIRED_SOFTWARE"
|
||||
)) {
|
||||
Set-AnswerProperty -Name $Agreement -Value "1"
|
||||
}
|
||||
|
||||
if($DatabaseEngine -eq "MSSQL") {
|
||||
if([string]::IsNullOrWhiteSpace($SQLServer) -or [string]::IsNullOrWhiteSpace($SQLInstance)) {
|
||||
throw "Für Microsoft SQL müssen Server und Instanz angegeben sein."
|
||||
}
|
||||
|
||||
Set-AnswerProperty -Name "VBR_SQLSERVER_INSTALL" -Value "0"
|
||||
Set-AnswerProperty -Name "VBR_SQLSERVER_ENGINE" -Value "0"
|
||||
Set-AnswerProperty -Name "VBR_SQLSERVER_SERVER" -Value ("{0}\{1}" -f $SQLServer, $SQLInstance)
|
||||
Set-AnswerProperty -Name "VBR_SQLSERVER_DATABASE" -Value $DatabaseName
|
||||
Set-AnswerProperty -Name "VBR_SQLSERVER_AUTHENTICATION" -Value "0"
|
||||
$UnusedProperties = @(
|
||||
"VBR_SERVICE_USER",
|
||||
"VBR_SERVICE_PASSWORD",
|
||||
"VBR_SQLSERVER_USERNAME",
|
||||
"VBR_SQLSERVER_PASSWORD"
|
||||
)
|
||||
}
|
||||
else {
|
||||
Set-AnswerProperty -Name "VBR_SQLSERVER_INSTALL" -Value "1"
|
||||
Set-AnswerProperty -Name "VBR_SQLSERVER_DATABASE" -Value $DatabaseName
|
||||
$UnusedProperties = @(
|
||||
"VBR_SERVICE_USER",
|
||||
"VBR_SERVICE_PASSWORD",
|
||||
"VBR_SQLSERVER_ENGINE",
|
||||
"VBR_SQLSERVER_SERVER",
|
||||
"VBR_SQLSERVER_AUTHENTICATION",
|
||||
"VBR_SQLSERVER_USERNAME",
|
||||
"VBR_SQLSERVER_PASSWORD"
|
||||
)
|
||||
}
|
||||
|
||||
foreach($UnusedProperty in $UnusedProperties) {
|
||||
$Node = $Xml.SelectSingleNode("//property[@name='$UnusedProperty']")
|
||||
if($null -ne $Node) {
|
||||
$Node.ParentNode.RemoveChild($Node) | Out-Null
|
||||
}
|
||||
}
|
||||
|
||||
$Xml.Save($DestinationPath)
|
||||
|
||||
Write-Host "Konfigurierte Antwortdatei erstellt: $DestinationPath" -ForegroundColor Green
|
||||
return (Resolve-Path -LiteralPath $DestinationPath).Path
|
||||
}
|
||||
|
||||
|
||||
|
||||
############################################################
|
||||
# Test-VeeamSource
|
||||
|
||||
@@ -1179,6 +1439,17 @@ function Invoke-VeeamInstallation {
|
||||
|
||||
|
||||
|
||||
if([string]::IsNullOrWhiteSpace($LogFolder))
|
||||
{
|
||||
$LogFolder = "C:\ProgramData\VeeamInstaller\SetupLogs"
|
||||
}
|
||||
|
||||
if(!(Test-Path -LiteralPath $LogFolder -PathType Container))
|
||||
{
|
||||
New-Item -Path $LogFolder -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
|
||||
$Arguments =
|
||||
|
||||
New-VeeamInstallParameter `
|
||||
@@ -1215,6 +1486,12 @@ function Invoke-VeeamInstallation {
|
||||
|
||||
$Result
|
||||
|
||||
|
||||
|
||||
LogFolder =
|
||||
|
||||
$LogFolder
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1465,6 +1742,8 @@ Export-ModuleMember `
|
||||
Get-VeeamServices,
|
||||
Get-VeeamSetupFile,
|
||||
Resolve-VeeamSourcePath,
|
||||
Resolve-VeeamAnswerFile,
|
||||
New-VeeamAnswerFileFromTemplate,
|
||||
Test-VeeamSource,
|
||||
Get-VeeamRegistryInformation,
|
||||
Get-VeeamVersion,
|
||||
|
||||
Reference in New Issue
Block a user