Результат выполнения командлета Start-VBRZip
PS C:\> $VMs = "veeam-pn"
PS C:\> & "C:\Program Files\Veeam\Backup and Replication\Backup\Initialize-VeeamToolkit.ps1"
Get-Content : Не удается найти путь "C:\Program Files\Veeam\Backup and Replication\Backup\Veeam.Backup.Powershell.Cmdle
ts.xml", так как он не существует.
C:\Program Files\Veeam\Backup and Replication\Backup\Initialize-VeeamToolkit.ps1:8 знак:14
+ [xml]$xml = Get-Content $xmlPath
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Program File...ell.Cmdlets.xml:String) [Get-Content], ItemNotFoundEx
ception
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand
Welcome to the Veeam Backup and Replication PowerShell Toolkit!
To list available commands, type Get-VBRCommand
To open online documentation on all available commands, type Get-VBRToolkitDocumentation
Copyright © Veeam Software AG. All rights reserved.
PS C:\> $VM = "veeam-pn"
PS C:\> $HVServer = "hv4.mkucou.local"
PS C:\> $Destination = "H:\Veeam\Backup\_Week"
PS C:\> $BackupRepo = "BackupRepositoryHV4"
PS C:\> $Compression = 5
PS C:\> $Autodelete = "In2Week"
PS C:\> $vmentity = Get-VBRServer -Name $HVServer | Find-VBRHvEntity -Name $VM
PS C:\> $vbrzipResult = Start-VBRZip -Entity $vmentity -Folder $Destination -Compression $Compression -Auto
Delete $Autodelete
PS C:\> $vbrzipResult | fl
EventNotifier : Veeam.Backup.Core.CEventNotifier
BottleneckManager : CJobBottleneckManager
Info : Veeam.Backup.Model.CBackupSessionInfo
Progress : Veeam.Backup.Model.CBackupProgressData
StartupMode : Normal
JobSourceType : HyperV
CurrentPointId : 00000000-0000-0000-0000-000000000000
OriginalSessionId : 47a0a6c3-d2ba-4aa4-98d4-b96c5c38b9ba
ParentSessionId : 00000000-0000-0000-0000-000000000000
IsFullMode : True
IsRetryMode : False
IsRecheckRetry : False
IsQuickBackup : False
IsVeeamZip : True
IsPlannedFailover : False
IsReplicaFromBackup : False
IsEpAgentManagement : False
PostActivity : AskService
Name : veeam-pn_2018-09-27T084047 (Active Full)
OrigJobName : veeam-pn_2018-09-27T084047
BackupStats : Veeam.Backup.Model.CBackupStats
WorkDetails : Veeam.Backup.Core.CBackupSessionWorkDetails
WillBeRetried : False
IsManuallyStopped : False
IsTransformLaunched : False
LastProgressSaveTime : 01.01.0001 0:00:00
SessionCryptoSpec : Veeam.Backup.Crypto.CCryptoSymmetricSpec
UserKey :
MasterKey :
UserCryptoSpec :
SelectiveProcessingSpec :
BackupVerificationResult :
IsEncryptionEnabledByOptions : False
IsEncryptionEnabled : False
SplitStoragesPerVm :
DataBag : {}
SessionInfo : Veeam.Backup.Model.CBackupSessionInfo
Id : 47a0a6c3-d2ba-4aa4-98d4-b96c5c38b9ba
LeaseId : 00000000-0000-0000-0000-000000000000
JobType : Backup
JobName : veeam-pn_2018-09-27T084047
JobSpec : <FreeBackupSpec><JobId>4fc83ea2-bead-40fa-96c1-44bd21cb978b</JobId><JobName>veeam-pn_201
8-09-27T084047</JobName><VmName>veeam-pn</VmName><Platform>EHyperV</Platform><BackupObje
cts><ObjectId>291d2467-64df-48b4-8bc4-f60dad84f9c3</ObjectId></BackupObjects><UseReposit
ory>False</UseRepository><RepositoryId>00000000-0000-0000-0000-000000000000</RepositoryI
d><FolderName>H:\Veeam\Backup\_Week</FolderName><CredsId>00000000-0000-0000-0000-0000000
00000</CredsId><CompressionLevel>5</CompressionLevel><VmToolsQuiesce>True</VmToolsQuiesc
e><RetainDatetime>10/11/2018 00:00:00</RetainDatetime><PwdKeyId>00000000-0000-0000-0000-
000000000000</PwdKeyId><ModifiedBy>DOMAIN\Admin</ModifiedBy></FreeBackupSpec>
JobTypeString : Backup
CreationTimeUTC : 27.09.2018 8:40:47
Operation :
Description :
BaseProgress : 100
IsCompleted : True
IsWorking : False
IsStarting : False
IsPostprocessing : False
JobId : 4fc83ea2-bead-40fa-96c1-44bd21cb978b
Result : Success
State : Stopped
EndTime : 27.09.2018 8:45:26
EndTimeUTC : 27.09.2018 8:45:26
CreationTime : 27.09.2018 8:40:47
AuxData : <AuxData><CBackupStats><BackupSize>2938765312</BackupSize><DataSize>17179900104</DataSiz
e><DedupRatio>38</DedupRatio><CompressRatio>44</CompressRatio></CBackupStats><CBackupSes
sionWorkDetails><WorkDuration>2791212001</WorkDuration></CBackupSessionWorkDetails><Sess
ionStarterInfo Version="1" UserName="Admin" UserDomainName="DOMAIN" RunManually="True"
LoginType="0" /></AuxData>
IsLowerAgentPriority : True
LogName : Job.veeam-pn_2018-09-27T084047
LogsSubFolder : veeam-pn_2018-09-27T084047
Logger : Veeam.Backup.Core.XmlLogger
Tracer : Veeam.Backup.Core.CSessionLogTracer
AuxData
PS C:\> $xml = New-Object -TypeName System.Xml.XmlDocument
PS C:\> $xml.LoadXml($vbrzipResult.AuxData)
PS C:\> $xml
AuxData
-------
AuxData
PS C:\> $xml.AuxData
CBackupStats CBackupSessionWorkDetails SessionStarterInfo
------------ ------------------------- ------------------
CBackupStats CBackupSessionWorkDetails SessionStarterInfo
PS C:\> $xml.AuxData.CBackupStats
BackupSize DataSize DedupRatio CompressRatio
---------- -------- ---------- -------------
2938765312 17179900104 38 44
PS C:\> $xml.AuxData.CBackupSessionWorkDetails
WorkDuration
------------
2791212001
PS C:\> $xml.AuxData.SessionStarterInfo
Version : 1
UserName : Admin
UserDomainName : DOMAIN
RunManually : True
LoginType : 0
JobSpec
PS C:\> $xml = New-Object -TypeName System.Xml.XmlDocument
PS C:\> $xml.LoadXml($vbrzipResult.JobSpec)
PS C:\> $xml
FreeBackupSpec
--------------
FreeBackupSpec
PS C:\> $xml.FreeBackupSpec
JobId : 4fc83ea2-bead-40fa-96c1-44bd21cb978b
JobName : veeam-pn_2018-09-27T084047
VmName : veeam-pn
Platform : EHyperV
BackupObjects : BackupObjects
UseRepository : False
RepositoryId : 00000000-0000-0000-0000-000000000000
FolderName : H:\Veeam\Backup\_Week
CredsId : 00000000-0000-0000-0000-000000000000
CompressionLevel : 5
VmToolsQuiesce : True
RetainDatetime : 10/11/2018 00:00:00
PwdKeyId : 00000000-0000-0000-0000-000000000000
ModifiedBy : DOMAIN\Admin
Скрипт запуска бэкапа в планировщике задач
<#
.SYNOPSIS
Скрипт запуска архивации на Veeavm Backup & Replication сервере
.LINK
https://webnote.satin-pl.ru/2018/09/27/veeam_results_to_icinga2/
.NOTES
Version: 0.1
Author: Pavel Satin
Email: plsatin@yandex.ru
Creation Date: 27.09.2018
Purpose/Change: Initial script development
#>
$HVServer = "hv4.mkucou.local"
$Destination = "H:\Veeam\Backup\_Week"
$Compression = 5
# Specifies the retention settings for the created VeeamZIP file: Never, Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month.
$Autodelete = "In2Weeks"
$VMs = "elastix.mkucou.local", "ts4.mkucou.local"
#Load Veeam Toolkit
& "C:\Program Files\Veeam\Backup and Replication\Backup\Initialize-VeeamToolkit.ps1"
foreach ($VM in $VMs) {
#Validate any parameters
$vmentity = Get-VBRServer -Name $HVServer | Find-VBRHvEntity -Name $VM
if ($vmentity -eq $null) {
& "C:\ProgramData\icinga2\Scripts\icinga2\Send-Icinga2ServiceResult.ps1" $VM 1 "Warning - VM: $VM not found"
} else {
if (-Not (Test-Path $Destination)) {
& "C:\ProgramData\icinga2\Scripts\icinga2\Send-Icinga2ServiceResult.ps1" $VM 2 "Critical - Destination: $Destination not valid"
} else {
$vbrzipResult = Start-VBRZip -Entity $vmentity -Folder $Destination -Compression $Compression -AutoDelete $Autodelete
if ($vbrzipResult.Result -eq "Success") {
$JobResult = 0
$JobResultStr = "OK"
} elseif ($vbrzipResult.Result -eq "Failed") {
$JobResult = 2
$JobResultStr = "Critical"
} else {
$JobResult = 1
$JobResultStr = "Warning"
}
$xml = New-Object -TypeName System.Xml.XmlDocument
$xml.LoadXml($vbrzipResult.AuxData)
$s = $xml.AuxData.CBackupSessionWorkDetails.WorkDuration / 10000000
$ts = [timespan]::fromseconds($s)
$duration = "{0:HH:mm:ss}" -f ([datetime]$ts.Ticks)
$vbrzipString = "<table>"
$vbrzipString += "<tr><td>Result:</td><td>" + $vbrzipResult.Result + "</td></tr>"
$vbrzipString += "<tr><td>CreationTime:</td><td>" + $vbrzipResult.CreationTime.ToString() + "</td></tr>"
$vbrzipString += "<tr><td>EndTime:</td><td>" + $vbrzipResult.EndTime.ToString() + "</td></tr>"
$vbrzipString += "<tr><td>BackupSize:</td><td>" + $xml.AuxData.CBackupStats.BackupSize + "</td></tr>"
$vbrzipString += "<tr><td>DataSize:</td><td>" + $xml.AuxData.CBackupStats.DataSize + "</td></tr>"
$vbrzipString += "<tr><td>DedupRatio:</td><td>" + $xml.AuxData.CBackupStats.DedupRatio + "</td></tr>"
$vbrzipString += "<tr><td>CompressRatio:</td><td>" + $xml.AuxData.CBackupStats.CompressRatio + "</td></tr>"
$vbrzipString += "<tr><td>WorkDuration:</td><td>" + $duration + "</td></tr>"
$vbrzipString += "</table>"
& "C:\ProgramData\icinga2\Scripts\icinga2\Send-Icinga2ServiceResult.ps1" $VM $JobResult $vbrzipString
}
}
}
Скрипт отправки результата на сервер мониторинга (Send-Icinga2ServiceResult.ps1)
<#
.SYNOPSIS
Отправка на сервер Icinga состояния сервиса.
.PARAMETER ComputerName
Имя компьютера
.PARAMETER taskStatus
Статус завершения задачи
.PARAMETER taskOutput
Вывод завершенной задачи
.PARAMETER serviceName
Имя сервиса хоста
.LINK
https://webnote.satin-pl.ru
.NOTES
Version: 0.1
Author: Pavel Satin
Email: plsatin@yandex.ru
Creation Date: 17.02.2018
Purpose/Change: Initial script development
#>
Param(
[Parameter(Position=0,Mandatory = $true)]
[string]$ComputerName,
[Parameter(Position=1,Mandatory = $true)]
[string]$taskStatus,
[Parameter(Position=2,Mandatory = $true)]
[string]$taskOutput,
[Parameter(Position=3,Mandatory = $false)]
[string]$serviceName = "hv-backup-result"
)
#[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$returnStateOK = 0
$returnStateWarning = 1
$returnStateCritical = 2
$returnStateUnknown = 3
$taskOutput = $taskOutput
$taskOutput = $taskOutput -replace "[\\]", "/"
$taskOutput = $taskOutput -replace '"', "'"
#Verbose
Write-Verbose $taskOutput
#Доверяем всем сертификатам
add-type -TypeDefinition @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$user = "root"
$pass = "icinga"
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($user, $secpasswd)
$json = [System.Text.Encoding]::UTF8.GetBytes(@"
{ "exit_status": $taskStatus, "plugin_output": "$taskOutput", "check_source": "$ComputerName" }
"@)
$apiurl = "https://192.168.0.209:5665/v1/actions/process-check-result?service=$ComputerName!$serviceName"
$headers = @{}
$headers["Accept"] = "application/json"
$retryCount = 0
$completed = $False
$response = $Null
$result = $Null
$SecondsDelay = 2
$Retries = 17
while (-not $completed) {
try {
$response = Invoke-WebRequest -Credential $credential -Uri $apiurl -Body $json -ContentType "application/json" -Headers $headers -Method Post -UseBasicParsing
if ($response.StatusCode -ne 200) {
throw "Expecting reponse code 200, was: $($response.StatusCode)"
}
$completed = $True
} catch {
if ($retryCount -ge $Retries) {
Write-Verbose "Request to $url failed the maximum number of $retryCount times."
$completed = $True
throw
} else {
Write-Verbose "Request to $url failed. Retrying in $SecondsDelay seconds."
Start-Sleep $SecondsDelay
$retryCount++
}
}
}
Задача копирования бэкапа
PS C:\Windows\system32> & "C:\Program Files\Veeam\Backup and Replication\Backup\Initialize-VeeamToolkit.ps1"
Welcome to the Veeam Backup and Replication PowerShell Toolkit!
To list available commands, type Get-VBRCommand
To open online documentation on all available commands, type Get-VBRToolkitDocumentation
Copyright © Veeam Software AG. All rights reserved.
PS C:\> Get-VBRJob -Name "to_RDC5"
Job Name Type State Last Result Description
-------- ---- ----- ----------- -----------
to_RDC5 File Copy Stopped Success Created by MKUCOU\admin at 02.07.2016 21:55.
PS C:\> $jbWeek = Get-VBRJob -Name "to_HV4"
PS C:\> Start-VBRJob -Job $jbWeek
Job Name State Start Time End Time Result
-------- ----- ---------- -------- ------
to_HV4 Stopped Success
Ссылки