Reading Time: 5 minutes

Uno dei limiti di VeeamZIP (la versione gratuita di Veeam Backup & Replication) è l’impossibilità di pianificare dei job di backup.

A dire il vero c’è anche il limite significativo che ogni VeeamZIP è sempre un backup full, sia lato sorgente che destinazione, ma questo limite potrebbe essere minimale per realtà molto piccole, dove lo spazio in gioco è poco.

Per ovviare il limite della pianificazione automatica, da un po’ di tempo è possibile ricorrere a script in PowerShell che automatizzino la creazione di un VeeamZip, usando poi il pianificatore di Windows come strumento di automazione e ripetizione automatica dei backup.

Tra l’altro, da quest’anno esiste anche un ottimo blog post in Italiano: Veeam Backup Free Edition: ora con PowerShell!

Il blog spiega passo passo come procedere e implementare così una soluzione di backup economica e gratuita (a parte l’hardware e la licenza di Windows).

Lo script è il seguente ed è stato adattato e migliorato da un italiano:

# Author: Vladimir Eremin
# Created Date: 3/24/2015
# http://forums.veeam.com/mem...
#
# modified by Fabio Roncarati
# 02/13/2018
# - forced VeeamPSSnapin loading
# - network credentials for backup repository
# - SMTP authentication, SSL support, Port

Add-PSSnapin VeeamPSSnapin

##################################################################
# User Defined Variables
##################################################################

# Names of VMs to backup separated by semicolon (Mandatory)
$VMNames = ""

# Name or IP of vCenter or standalone host VMs to backup reside on (Mandatory)
$HostName = ""

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = ""

# Credentials with r/w access for the backup folder (store first in Veeam "Manage Credentials")
# example $DirCredentials = "domain\username"
$DirCredentials = $False

# 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 = $False

# Encryption Key (Optional; path to a secure string)
$EncryptionKey = ""

# 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 = "In3days"

##################################################################
# Notification Settings
##################################################################

# Enable notification (Optional)
$EnableNotification = $True

# Email SMTP server
$SMTPServer = ""

# SMTP port
$SMTPport = ""

# SMTP use SSL
$SMTPssl = $False

# SMTP user for authentication
$SMTPuser = ""

# SMTP password for authentication
$SMTPpass = ""

# Email FROM
$EmailFrom = ""

# Email TO
$EmailTo = ""

# Email subject
$EmailSubject = ""

##################################################################
# 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-VBRViEntity -Name $VMName -Server $Server

If ($EnableEncryption)
{
$EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString)

If ($DirCredentials) {
$Credentials = Get-VBRCredentials -Name $DirCredentials
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -NetworkCredentials $Credentials -AutoDelete $Retention -EncryptionKey $EncryptionKey
} else {
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
}
}

Else
{
If ($DirCredentials) {
$Credentials = Get-VBRCredentials -Name $DirCredentials
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -NetworkCredentials $Credentials -AutoDelete $Retention
} else {
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -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, $SMTPport)
$SMTP.EnableSsl = $SMTPssl
$SMTP.Credentials = New-Object System.Net.NetworkCredential($SMTPuser, $SMTPpass);
$SMTP.Send($Message)
}

Lo script prevede persino la possibilità di inviare mail di notifica, gestire la retention o cifrare il contenuto del backup.

I parametri più importanti sono:

##################################################################

# Variabili definite dall'utente

##################################################################

# Nomi delle VM di cui eseguire il backup separati da una virgola (obbligatorio). Ad esempio, $VMNames = “VM1”,”VM2”

$VMNames = ""

# Nome del vCenter o dell'host indipendente su cui risiedono le VM di cui eseguire il backup (obbligatorio)

$HostName = ""

# Directory di destinazione dei backup della VM (obbligatorio; ad esempio, C:\Backup)

$Directory = ""

Maggiori dettagli nell’articolo originale:

https://www.veeam.com/blog/it/veeam-backup-free-edition-now-with-powershell.html

Share

Virtualization, Cloud and Storage Architect. Tech Field delegate. VMUG IT Co-Founder and board member. VMware VMTN Moderator and vExpert 2010-24. Dell TechCenter Rockstar 2014-15. Microsoft MVP 2014-16. Veeam Vanguard 2015-23. Nutanix NTC 2014-20. Several certifications including: VCDX-DCV, VCP-DCV/DT/Cloud, VCAP-DCA/DCD/CIA/CID/DTA/DTD, MCSA, MCSE, MCITP, CCA, NPP.