Hello,
My Konfiguration: PC with Windows 7, VEEAM Backup & Recovery Version 9.5.0.823 Free Version, HyperV 2008 R2 Cluster, Synology DS416 NAS 10TB Raid 5
i use this script below, that i have a little modified.
Backup is working correctly, but the Retention is not work. First i have installed Version 9.0 Update 2. With this Version the Script and retention is working proberly. After Update to Version 9.5.0.823 the Retention is not working. I use the Retention with "In1Week". After 7 Day's the VeeamZIP Files are not removed and remain in the specified location.
Could anyone help me, please.
Code: Select all
# Veeam Script ####################################################################
# Author: Vladimir Eremin
# Created Date: 3/24/2015
# http://forums.veeam.com/member31097.html
#
##################################################################
# User Defined Variables
##################################################################
# Names of VMs to backup separated by comma (Mandatory). For instance, $VMNames = “VM1”,”VM2”
#$VMNames = "SRV002"
$VMNames = "SRV002","SRV001","SRV007","SRV008","SRV006","SRV003","SRV004","SRV005"
# Name of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = "CL001"
# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "\\nas002\Backup"
# $Repository = ""
# Desired compression level (Optional; Possible values: 0 - None, 4 - Dedupe-friendly, 5 - Optimal, 6 - High, 9 - Extreme)
$CompressionLevel = "5"
# Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
$EnableQuiescence = $False
# Protect resulting backup with encryption key (Optional; $True/$False)
$EnableEncryption = $True
# Encryption Key (EncryptionKey, (Description) Which is stored in the GUI under Managed Passwords, can also be retrieved via Powershell with Get-VbrEncryptionKey)
#$EncryptionKey = "C:\Scripts\SecureString.txt" #not used in the current configuration
$Encryption_Description="Name_Encryption" # Instead, the password specified in the GUI with the specified name is used
# The reason for this is, in the original script, a new password is added with each pass and the identifier is given a date
# Retention settings (Optional; By default, VeeamZIP files are not removed and kept in the specified location for an indefinite period of time.
# Possible values: Never , Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month)
$Retention = "In1Week"
##################################################################
# Notification Settings
##################################################################
# Enable notification (Optional)
$EnableNotification = $True
# Email SMTP server
$SMTPServer = "smtp.gmail.com"
# Email FROM
$EmailFrom = "sender@mailaddress.de"
# Email TO
$EmailTo = "recipient@mailaddress.de"
# Email subject
$EmailSubject = "VeeamBackup_" + $VMNames
# Email User
$EmailUser= "sender@mailaddress.de"
#EMailPassword
$EmailPassword="Password"
##################################################################
# Email formatting
##################################################################
$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "</style>"
##################################################################
# End User Defined Variables
##################################################################
#################### DO NOT MODIFY PAST THIS LINE ################
Asnp VeeamPSSnapin
$Server = Get-VBRServer -name $HostName
$MesssagyBody = @()
foreach ($VMName in $VMNames)
{
$VM = Find-VBRHvEntity -Name $VMName -Server $Server
If ($EnableEncryption)
{
#$EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString -AsPlainText -force )
#Script changed here, because otherwise every time a new key is generated. Please use the GUI under Managed Passwords to create a key
#EncryptionKey create once manually in the GUI and specify the name, always is used this password.
$EncryptionKey = Get-VBREncryptionKey -Description $Encryption_Description
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
}
Else
{
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
#$ZIPSession = Start-VBRZip -Entity $VM -BackupRepository $Repository -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
}
If ($EnableNotification)
{
$TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
$FailedSessions = $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}
if ($FailedSessions -ne $Null)
{
$MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={$FailedSessions.Title}})
}
Else
{
$MesssagyBody = $MesssagyBody + ($ZIPSession | Select-Object @{n="Name";e={($_.name).Substring(0, $_.name.LastIndexOf("("))}} ,@{n="Start Time";e={$_.CreationTime}},@{n="End Time";e={$_.EndTime}},Result,@{n="Details";e={($TaskSessions | sort creationtime -Descending | select -first 1).Title}})
}
}
}
If ($EnableNotification)
{
$Message = New-Object System.Net.Mail.MailMessage $EmailFrom, $EmailTo
$Message.Subject = $EmailSubject
$Message.IsBodyHTML = $True
$message.Body = $MesssagyBody | ConvertTo-Html -head $style | Out-String
$SMTP = New-Object Net.Mail.SmtpClient($SMTPServer,"587")
$SMTP.EnableSsl = $true
$SMTP.Credentials = New-Object System.Net.NetworkCredential($EmailUser, $EmailPassword);
$SMTP.Send($Message)
}