Donnerstag, der 24. Juni 2021 - 05:39 Uhr

Veaam Endpoint Backup Mail Notification

erstellt am: 21.06.2016 | von: DevLink | Kategorie(n): Backup | Keine Kommentare

Auch wenn Veeam sich dazu entschieden hat, mit der Version 1.5 vom 17.03.2016
die Mailbenachrichtigung zu implementieren, dient dieses Script dazu,
sich nach dem Backup ein paar mehr Informationen per Mail zukommen zu lassen.

Folgende Informationen können dadurch eingesehen werden:

  • Start-, Endzeit und Dauer
  • Größe der gesicherten Daten
  • Gesamtgröße der Backupdaten
  • Freier Speicherplatz auf dem Backupmedium
  • Detail und Grund warum ein Backup nicht erfolgreich war.

Installation:

  1. Powershell als Administrator öffnen, folgendes einfügen:
    "Set-ExecutionPolicy Unrestricted" - und bestätigen.
  2. In der Aufgabenplanung eine neue Aufgabe erstellen und nach Wunsch benennen (z.B. "Mailscript").
  3. Unter Allgemein folgendes einstellen:
    Unabhängig von der Benutzeranmeldung ausführen,
    Kennwort nicht speichern und mit höchsten Privilegien ausführen
  4. Neuen Trigger erstellen "Bei einem Ereignis" und "Veeam Endpoint Backup" als Protokoll und Quelle auswählen.
  5. Neue Aktion erstellen und unter Programm/Script
    "%SystemRoot%\system32\WindowsPowerShell\​v1.0\powershell.exe" einfügen (ohne "").
  6. Unter Argumente: -command "C:\path\to\script\veeam.ps1" einfügen (die "" beim Pfad sind Pflicht)
  7. Das untenstehende Script kopieren und als *.ps1 speichern.
  8. Variablen im Script nach Sender, Empfänger, Host und Server anspassen
  9. Backup ausführen

Screenshot:

veeam

Script:

 
###########################################################
#  														  #
#				 Endpoint Notification					  #
#														  #
###########################################################

# Set information about sender and recipient
$emailMessage = New-Object System.Net.Mail.MailMessage
$emailMessage.From = "sender@sender.com"
$emailMessage.To.Add( "recipient@recipient.com" )
$hostname = "TestBackup"

# SMTP Server Informationen
$emailSmtpServer = "yourmailserver.com"
$emailSmtpServerPort = "25"

# Put most info into the body of the email:
$TimeGenerated   =get-eventlog "Veeam Endpoint Backup" -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-Wide -property TimeGenerated | out-string
$TimeBackupStarted   =get-eventlog "Veeam Endpoint Backup" -InstanceID 110 -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-Wide -property TimeGenerated | out-string
$Source      =get-eventlog "Veeam Endpoint Backup" -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property Source | out-string
$EntryType   =get-eventlog "Veeam Endpoint Backup" -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property EntryType | out-string
$Message   =get-eventlog "Veeam Endpoint Backup" -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-Wide -property Message -AutoSize | out-string
$InstanceID   =get-eventlog "Veeam Endpoint Backup" -newest 1 -entrytype Information, Warning, Error -source "Veeam Endpoint Backup" | Format-List -property InstanceID| out-string

#Formatting Variables into readable data
$date = Get-Date -format F
$difference = (new-timespan -Start $TimeBackupStarted -End $TimeGenerated)
$duration = "{0:c}" -f $difference
$TimeGenerated = [datetime]::parse($TimeGenerated)
$TimeBackupStarted = [datetime]::parse($TimeBackupStarted)
$start = "{0:HH:mm:ss}" -f $TimeBackupStarted
$end = "{0:HH:mm:ss}" -f $TimeGenerated
$mb = " MB"
$gb = " GB"
$tb = " TB"

# Connecting to the Veeam SQL Database
$key = "hklm:\SOFTWARE\Veeam\Veeam Endpoint Backup"
$User = (get-Item $key).GetValue("SqlLogin")
$Pass = (get-Item $key).GetValue("SqlPassword")
$dbServer = (get-Item $key).GetValue("SqlInstancePipeName")
$db = (get-Item $key).GetValue("SqlDatabaseName")
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server=$dbServer;Database=$db;uid=$User;password=$Pass;"
$SQLConnection.Open()
$SQLCommand = $SQLConnection.CreateCommand()
$sql = "SELECT TOP 1 stored_size AS size, job_name AS job FROM [VeeamBackup].[dbo].[ReportSessionView] ORDER BY [creation_time] DESC;
SELECT [free_space] AS [free] FROM [VeeamBackup].[dbo].[BackupRepositories] WHERE (name != 'Default Backup Repository')
SELECT  SUM(backup_size) AS backupsize FROM [VeeamBackup].[dbo].[WmiServer.RestorePointsView]
SELECT TOP 1 reason AS Reason, stop_details AS Detail FROM [VeeamBackup].[dbo].[Backup.Model.JobSessions] ORDER BY creation_time DESC"
$SQLCommand.CommandText = $sql
$readAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$readSet = New-Object System.Data.DataSet
$readAdapter.SelectCommand = $SQLCommand
$readAdapter.Fill($readSet) |out-null
Foreach ($row in $readSet.Tables[0].rows) {$space_backup = $row[0]; $job = $row[1]}
Foreach ($row2 in $readSet.Tables[1].rows) {$space_free = $row2[0]}
Foreach ($row3 in $readSet.Tables[2].rows) {$space_all = $row3[0]}
Foreach ($row4 in $readSet.Tables[3].rows) {$reason = $row4[0]; $detail = $row4[1]}
$SQLConnection.Close()

if($reason -eq [System.DBNull]::Value)
{$reason = $Message}

if($space_backup -ge 1048576 -and $space_backup -lt 1073741824)
{$spacebackup = "{0:n2}" -f ($space_backup /1048576) + $mb}
elseif($space_backup -ge 1073741824 -and $space_backup -lt 1099511627776)
{$spacebackup = "{0:n2}" -f ($space_backup /1073741824) + $gb}
elseif($space_backup -ge 1099511627776)
{$spacebackup = "{0:n2}" -f ($space_backup /1099511627776) + $tb}
else
{$spacebackup = ("0" + $mb)}

if($space_free -ge 1048576 -and $space_free -lt 1073741824)
{$spacefree = "{0:n2}" -f ($space_free /1048576) + $mb}
elseif($space_free -ge 1073741824 -and $space_free -lt 1099511627776)
{$spacefree = "{0:n2}" -f ($space_free /1073741824) + $gb}
elseif($space_free -ge 1099511627776)
{$spacefree = "{0:n2}" -f ($space_free /1099511627776) + $tb}
else
{$spacefree = ("0" + $mb)}

if($space_all -ge 1048576 -and $space_all -lt 1073741824)
{$spaceall = "{0:n2}" -f ($space_all /1048576) + $mb}
elseif($space_all -ge 1073741824 -and $space_all -lt 1099511627776)
{$spaceall = "{0:n2}" -f ($space_all /1073741824) + $gb}
elseif($space_all -ge 1099511627776)
{$spaceall = "{0:n2}" -f ($space_all /1099511627776) + $tb}
else
{$spaceall = ("0" + $mb)}

# Determine the subject and background according to the result of the backup

if($Message.contains("Success"))
{$subject = "[Success] Endpoint Backup $hostname (VEB)"
$Message2 = "EndpointBackup job '$job' finished with success."
$bgcolor = "#00B050"}
elseif($Message.contains("Failed"))
{$subject = "[Failed] Endpoint Backup $hostname failed (VEB)"
$Message2 = "EndpointBackup job '$job' finished with failed."
$bgcolor = "#fb9895"}
elseif($Message.contains("Warning"))
{$subject = "[Warning] Endpoint Backup $hostname finished with Warning. (VEB)"
$Message2 = "EndpointBackup job '$job' finished with warning."
$bgcolor = "#ffd96c"}

# Giving the typical Veeam look
$Body =

"<meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" />
<table cellspacing=""0"" cellpadding=""0"" width=""50%"" border=""0"" style=""border-collapse: collapse;"">
<tr>
<td style=""padding: 0px;font-family: Tahoma;font-size: 12px;"">
<table cellspacing=""0"" cellpadding=""0"" width=""100%"" border=""0"" bordercolor=""#a7a9ac"" style=""border-collapse: collapse;"">
<tr>
<td colspan=""5"" style=""border: 1px solid #a7a9ac;background-color: $bgcolor;color: White;font-family: Tahoma;font-weight: bold;font-size: 16px;height: 70px;vertical-align: bottom;padding: 0 0 15px 15px;"">Backup job: $Hostname
<div style=""margin-top: 5px;font-size: 12px;"">$Message2</div>
</td></tr><tr>
<td colspan=""5"" style=""height: 35px;border: 1px solid #a7a9ac; background-color: #f3f4f4;font-size: 16px;vertical-align: middle;padding: 5px 0 0 15px;color: #626365; font-family: Tahoma;"">
<span>$date</span></td></tr>
<tr>
<td nowrap="""" style=""width:100px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;""><b>Start time </b></td>
<td nowrap="""" style=""width:150px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;"">$start</td>
<td nowrap="""" style=""width:150px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;""><b>Data size</b></td>
<td nowrap="""" style=""width:150px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;"">$spacebackup</td>
<td rowspan=""3"" style=""border: 1px solid #a7a9ac;""><span style=""font-size: 10px;""> </span></td>
</tr><tr>
<td nowrap="""" style=""width:100px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;""><b>End time</b></td>
<td nowrap="""" style=""width:150px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;"">$end</td>
<td nowrap="""" style=""width:150px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;""><b>Total backup size</b></td>
<td nowrap="""" style=""width:150px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;"">$spaceall</td>
</tr><tr>
<td nowrap="""" style=""width:100px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;""><b>Duration</b></td>
<td nowrap="""" style=""width:150px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;"">$duration</td>
<td nowrap="""" style=""width:150px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;""><b>Free disk space</b></td>
<td nowrap="""" style=""width:150px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;font-size: 12px;"">$spacefree</td>
</tr>
<tr><td colspan=""5"" style=""font-size:10px;padding: 2px 3px 2px 3px;border: 1px solid #a7a9ac;background-color:#f3f4f4;""> </td></tr>
<tr><td colspan=""5"" style=""font-size:12px;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;"">$reason<br>$detail</td></tr>
</table></td></tr>
<tr><td > </td></tr><tr>
<td style=""font-size:12px;color:#626365;padding: 2px 3px 2px 3px;vertical-align: top;border: 1px solid #a7a9ac;font-family: Tahoma;"">Veeam Endpoint Backup</td>
</tr>
</table>"


$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.EnableSsl = $true
$emailMessage.Subject = $subject
$emailMessage.IsBodyHtml = $true
$emailMessage.Body = $Body

# Send the email
if ($InstanceID.contains("190")) {
$SMTPClient.Send( $emailMessage )
} else {
write-host "I don't want messages on 10010 and 10050 Restorepoint-creation or -remove Emails, skip those"
}


write-host "Script finished with -$instanceID- as the last event-ID"

Für Mailserver mit Anmeldung folgendes abändern:

 
# Send the email
if ($InstanceID.contains("190")) {
$SMTPclient.EnableSsl = $true
$SMTPAuthUsername = "username"
$SMTPAuthPassword = "password"
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($SMTPAuthUsername, $SMTPAuthPassword)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { return $true }
$SMTPClient.Send( $emailMessage )

Original Diskussion und Beiträge bei Veeam



, , ,

Keine Kommentare


Bis jetzt noch keine Kommentare

Einen Kommentar abgeben

Themen:

51 Artikel in 7 Kategorien:

  • Backup (2)
  • Exchange Server (16)
  • Linux (6)
  • Microsoft Server (6)
  • Tutorials (8)
  • Virtualisierung (2)
  • Windows (11)