Upload Quellcode und Anpassung README.md
This commit is contained in:
34
README.md
34
README.md
@ -1,3 +1,35 @@
|
|||||||
# wsb-mailreport
|
# wsb-mailreport
|
||||||
|
|
||||||
Windows Server Backup - Mailreport
|
Windows Server Backup - Mailreport
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Dieses Script wertet den Status der Windows Server Sicherung aus und versendet auf Basis der Daten eine Mail im HTML-Format über den Status der letzten Sicherung. Zusätzlich werden Informationen über das Sicherungsmedium und den freien Speicher übermittelt.
|
||||||
|
|
||||||
|
## Installation, Configuration and Usage
|
||||||
|
|
||||||
|
Erstellen Sie zuerst eine Powershell-Skript mit dem Editor und speichern Sie es auf dem Server als "BackupMailReport.ps1". Passen Sie danach die Variablen Ihren Gegebenheiten an:
|
||||||
|
|
||||||
|
Als nächstes wird eine Ereignisbasiernde Aufgabe benötigt, welche das gerade erstellte Powershell-Skript ausführt. Für den Task "BackupMailReport' werden zwei Trigger konfiguriert, die bei den folgenden Events starten:
|
||||||
|
|
||||||
|
- Ereignis-ID 14 (Abschluss der Sicherung, egal ob erfolgreich oder nicht erfolgreich)
|
||||||
|
- Ereignis-ID 49 (Kein Sicherungsziel gefunden)
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Als Aktion für diese Aufgabe muss "**Programm starten**" ausgewählt und "**powershell.exe**" eingetragen werden. Unter "**Argument hinzufügen**" wird dann als Parameter "**-command c:\BackupMailReport.ps1**" eingetragen. Der Pfad zu dem Script muss den Gegebenheiten angepasst werden.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Nun wird nach jeden durchgeführten Backup eine Mail mit dem Status der Sicherung an die hinterlegte Mailaddresse(n) versandt. Dieses Script wurde unter Windows Server 2008/2008R2 und Windows Server 2012/2012R2 erfolgreich getestet.
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
* Ralf Kirchner
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
wsb-mailreport is licensed under GPLv3 License. See the [LICENSE](https://dev.ksite.de/wsb-mailreport/blob/master/LICENSE) file for details.
|
106
wsb-mailreport.ps1
Normal file
106
wsb-mailreport.ps1
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<#
|
||||||
|
|
||||||
|
.SYNOPSIS
|
||||||
|
Windows Server Backup - Mailreport
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
Dieses Script wertet den Status der Windows Server Sicherung aus
|
||||||
|
und versendet auf Basis der Daten eine Mail im HTML-Format über den
|
||||||
|
Status der letzten Sicherung. Zusätzlich werden Informationen über das
|
||||||
|
Sicherungsmedium und den freien Speicher übermittelt.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
./BackupMailReport.ps1
|
||||||
|
|
||||||
|
.NOTES
|
||||||
|
AUTHOR : Ralf Kirchner
|
||||||
|
EMAIL : ralf.kirchner@ksite.de
|
||||||
|
DATE : 09.08.2015
|
||||||
|
|
||||||
|
.LINK
|
||||||
|
http://www.ksite.de
|
||||||
|
|
||||||
|
#>
|
||||||
|
|
||||||
|
# Set sender address
|
||||||
|
$MailFrom = ""
|
||||||
|
|
||||||
|
# List of users to email the report (separate by comma)
|
||||||
|
# EXAMPLE: $MailTo = "user1@email", "user2@email"
|
||||||
|
$MailTo = ""
|
||||||
|
|
||||||
|
#SMTP server DNS name or IP address
|
||||||
|
$MailServer = ""
|
||||||
|
|
||||||
|
# Benutze Authentifikation (0 = nein, 1 = ja)
|
||||||
|
$MailAuth = 0
|
||||||
|
|
||||||
|
# SMTP Auth username
|
||||||
|
$MailAuthUser = ""
|
||||||
|
|
||||||
|
# SMTP Auth password
|
||||||
|
$MailAuthPass = ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# DO NOT CHANGE ANYTHING PAST THIS LINE!
|
||||||
|
$OSVersionMajor = [System.Environment]::OSVersion.Version.Major
|
||||||
|
$OSVersionMinor = [System.Environment]::OSVersion.Version.Minor
|
||||||
|
|
||||||
|
|
||||||
|
# Required to use PowerShell with Windows Server 2008 Backup
|
||||||
|
if ($OSVersionMajor -eq 6 -And $OSVersionMinor -le 1) {
|
||||||
|
add-pssnapin windows.serverbackup
|
||||||
|
}
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
$CurrentTime = Get-Date -Format F
|
||||||
|
$HostName = Get-Content env:computername
|
||||||
|
$BackupSummary = Get-WBSummary
|
||||||
|
$BackupLastSuccess = $BackupSummary.LastSuccessfulBackupTime
|
||||||
|
$BackupLastBackupTarget = $BackupSummary.LastBackupTarget
|
||||||
|
$BackupNextBackupTime = $BackupSummary.NextBackupTime
|
||||||
|
$BackupLastBackupTime = $BackupSummary.LastBackupTime
|
||||||
|
$BackupResult = $BackupSummary.LastBackupResultHR
|
||||||
|
$BackupErrorMsg = $BackupSummary.DetailedMessage
|
||||||
|
$BackupNumberOfVersions = $BackupSummary.NumberOfVersions
|
||||||
|
|
||||||
|
# Change Result of 0 to Success in green text and any other result as Failure in red text
|
||||||
|
if ($BackupResult -eq 0) {
|
||||||
|
$BackupResult = "Datensicherung erfolgreich abgeschlossen"
|
||||||
|
$BackupResultTitle = "Success"
|
||||||
|
$BackupResultColor = "green"
|
||||||
|
$MailBackupPriority = "Normal"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$BackupResult = "Datensicherung mit Fehler abgeschlossen"
|
||||||
|
$BackupResultTitle = "Error"
|
||||||
|
$BackupResultColor = "red"
|
||||||
|
$MailBackupPriority = "High"
|
||||||
|
}
|
||||||
|
|
||||||
|
$DriveInfo = Get-WmiObject -Class win32_volume -Filter "Label='$BackupLastBackupTarget'"
|
||||||
|
|
||||||
|
$DriveFreeSpace = [math]::Round($DriveInfo.FreeSpace /1Gb, 2)
|
||||||
|
$DriveCapacity = [math]::Round($DriveInfo.Capacity /1Gb, 2)
|
||||||
|
$DriveUsedSpace = $DriveCapacity - $DriveFreeSpace
|
||||||
|
|
||||||
|
|
||||||
|
# Assemble the HTML Report
|
||||||
|
$HTMLMessage = @"
|
||||||
|
<html><head></head><body alink="#003366" leftmargin="0" link="#003366" marginheight="0" marginwidth="0" text="#000000" topmargin="0" vlink="#003366" ><table width="600" cellpadding="0" cellspacing="0" valign="top" align="center" border="0"><tr><td><font style="font-family:arial; font-size:24px; color:#c76e28; font-weight:bold; line-height:40px;">Windows Backup Report</font></td></tr><tr><td><table style="background-color: #eff5fb; border: 1px solid #6782a8;" width="100%"><tr><td><font style="font-family:arial; font-size:14px; color:#c76e28; font-weight:bold;">Backup Status</font></td></tr><tr><td><font style="font-family:arial; font-size:12px; color:$BackupResultColor; font-weight:bold;">$BackupResult !</font></td></tr></table></td></tr><tr><td><br /><table style="background-color: #eff5fb; border: 1px solid #6782a8;" width="100%"><tr><td colspan="2"><font style="font-family:arial; font-size:14px; color:#c76e28; font-weight:bold;">Allgemeine Infos</font></td></tr><tr><td width="220"><font style="font-family:arial; font-size:13px; color:#004979; font-weight:bold;">Letzte Sicherung:</font></td><td><font style="font-family:arial; font-size:13px;">$BackupLastBackupTime</font></td></tr><tr><td><font style="font-family:arial; font-size:13px; color:#004979; font-weight:bold;">Letzte erfolgreiche Sicherung:</font></td><td><font style="font-family:arial; font-size:13px;">$BackupLastSuccess</font></td></tr><tr><td><font style="font-family:arial; font-size:13px; color:#004979; font-weight:bold;">Nächste Sicherung:</font></td><td><font style="font-family:arial; font-size:13px;">$BackupNextBackupTime</font></td></tr></table></td></tr><tr><td><br /><table style="background-color: #eff5fb; border: 1px solid #6782a8;" width="100%"><tr><td colspan="2"><font style="font-family:arial; font-size:14px; color:#c76e28; font-weight:bold;">Zielverwendung</font></td></tr><tr><td width="220"><font style="font-family:arial; font-size:13px; color:#004979; font-weight:bold;">Name:</font></td><td><font style="font-family:arial; font-size:13px;">$BackupLastBackupTarget</font></td></tr><tr><td><font style="font-family:arial; font-size:13px; color:#004979; font-weight:bold;">Kapazität:</font></td><td><font style="font-family:arial; font-size:13px;">$DriveCapacity GB</font></td></tr><tr><td><font style="font-family:arial; font-size:13px; color:#004979; font-weight:bold;">Belegter Speicher:</font></td><td><font style="font-family:arial; font-size:13px;">$DriveUsedSpace GB</font></td></tr><tr><td><font style="font-family:arial; font-size:13px; color:#004979; font-weight:bold;">Freier Speicher:</font></td><td><font style="font-family:arial; font-size:13px;">$DriveFreeSpace GB</font></td></tr><tr><td><font style="font-family:arial; font-size:13px; color:#004979; font-weight:bold;">Verfügbare Sicherungen:</font></td><td><font style="font-family:arial; font-size:13px;">$BackupNumberOfVersions Kopien</font></td></tr></table></td></tr><tr><td><br /><table style="background-color: #eff5fb; border: 1px solid #6782a8;" width="100%"><tr><td><font style="font-family:arial; font-size:14px; color:#c76e28; font-weight:bold;">Fehlermeldung (wenn verfügbar)</font></td></tr><tr><td><font style="font-family:arial; font-size:13px; color:#004979; font-weight:bold;">$BackupErrorMsg</font></td></tr></table></td></tr><tr><td style="text-align: right;"><font style="font-family: Arial; color: #004979; font-weight: bold; font-size: 0.6em;">MailReport by <a href="http://www.ksite.de">www.ksite.de</a></font></td></tr></table></body></html>
|
||||||
|
"@
|
||||||
|
|
||||||
|
|
||||||
|
if ($MailAuth) {
|
||||||
|
# set SMTP cerdentials
|
||||||
|
$SecuredPassword = ConvertTo-SecureString -String "$MailAuthPass" -AsPlainText -Force
|
||||||
|
$SecuredCredentials = New-Object System.Management.Automation.PSCredential($MailAuthUser,$SecuredPassword)
|
||||||
|
|
||||||
|
# Email the report
|
||||||
|
Send-MailMessage -from $MailFrom -to $MailTo -subject "$HostName Windows Backup $BackupResultTitle" -Encoding UTF8 -BodyAsHTML -body $HTMLMessage -priority $MailBackupPriority -Credential $SecuredCredentials -smtpServer $MailServer
|
||||||
|
} else {
|
||||||
|
# Email the report
|
||||||
|
Send-MailMessage -from $MailFrom -to $MailTo -subject "$HostName Windows Backup $BackupResultTitle" -Encoding UTF8 -BodyAsHTML -body $HTMLMessage -priority $MailBackupPriority -smtpServer $MailServer
|
||||||
|
}
|
Reference in New Issue
Block a user