Automatiser les backups de ses VMs avec VEEAM Backup Free edition
Pré-requis :
Un share réseau sur lequel l’objet COMPUTER de la machine VEEAM a les droits en écriture.
Le soft ignore les paramètres de credentials créés pour l’occasion, alors, autant s’en passer complètement 🙂
Le script doit être lancé en tant qu’administrateur !!
J’ai préféré créer un script qui fait tout plutôt que de faire de la config dans l’application et dans le script.
Le script :
# Author: Vladimir Eremin # Created Date: 3/24/2015 # http://forums.veeam.com/member31097.html # # Adapted by Myself # Must be run as administrator ! # backup everything except VMs defined ################################################################## # User Defined Variables ################################################################## $ExceptionVMNames = @('DSVA-VM01','VM-VEEAM-01') # Theses VMs will NOT be backuped. $HostName = "ESXNAME01" $Directory = "\\NAS01.DOMAIN.COM\VEEAM" $CompressionLevel = "5" # Desired compression level (Optional; Possible values: 0 - None, 4 - Dedupe-friendly, 5 - Optimal, 6 - High, 9 - Extreme) $EnableQuiescence = $True # Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False) $Retention = "In3days" # Possible values: Never , Tonight, TomorrowNight, In3days, In1Week, In2Weeks, In1Month) $EnableNotification = $True # Send an eMail about the backup when completed. $SMTPServer = "smtp.domain.com" $EmailFrom = "veeam.site1@domain.com" $EmailTo = "myself@domain.com" $EmailSubject = "VM backup of SITE 1" # Pour la création des objets nécessaires au backup. Il n'est pas nécessaire de les créer dans l'interface graphique. $ESX_name='ESXNAME01.domain.com' $ESX_User='root' $ESX_password='MemePasEnReve:-)' $NAS_name='NAS01' # Get-Command -Module VeeamPSSnapIn # pour lister les commandes possibles... ################################################################## # End User Defined Variables ################################################################## Add-PSSnapin VeeamPSSnapin Connect-VBRServer -server localhost if ( Find-VBRViEntity -name $ESX_name -HostsAndClusters ) { Write-Host "ESX exist" -foregroundcolor GREEN } else { Write-Host "ESX does not exist. Create it" -foregroundcolor CYAN Add-VBRESXi -Name $ESX_name -User $ESX_User -Password $ESX_password } $Server = Get-VBRServer -name $HostName # Création du repository. # Attention, les droits NTFS du share doivent autoriser l'objet COMPUTER a modifier les fichiers sur le NAS. if (Get-VBRBackupRepository -name $NAS_name ) { Write-Host "Repository exist" -foregroundcolor GREEN } else { Write-Host "Repository does not exist. Create it" -foregroundcolor CYAN Add-VBRBackupRepository -Name $NAS_name -Type CifsShare -RotatedDrive -Description "Synology NAS" -Server $server -Folder $Directory } # Creation du proxy pour backup local if ( ( Get-VBRViProxy | measure).count -ne 1 ) { Write-Host "Proxy does not exist. Create it" -foregroundcolor CYAN Get-VBRServer | ? { $_.type -eq "Local" } | Add-VBRViProxy -Description "Local Backup Proxy" -MaxTasks 2 } else { Write-Host "Proxy exist" -foregroundcolor GREEN } #################### Main program ################ $MesssagyBody = @() foreach ($VM in Find-VBRViEntity -Server $Server | ? {$_.type -eq "vm" -and $_.name -notin $ExceptionVMNames -and $_.name -notlike "*_clone_*" }){ Write-Host "Starting backup of " $VM.name -nonewline -foregroundcolor cyan $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention if ( $ZIPSession.Result -eq 'Failed' ) { Write-Host ". statut : " $ZIPSession.Result -foregroundcolor RED } else { Write-Host ". statut : " $ZIPSession.Result -foregroundcolor GREEN } If ($EnableNotification){ $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords $FailedSessions = $TaskSessions | where {$_.status -ne "ESucceeded"} 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){ # Email formatting $style = "<style>BODY{font-family: Arial; font-size: 10pt;}" $style+= "TABLE{border: 1px solid black; border-collapse: collapse;}" $style+= "TH{border: 1px solid black; background: #ddddff; padding: 5px; }" $style+= "TD{border: 1px solid black; padding: 5px; }" $style+= "</style>" $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) $SMTP.Send($Message) }
La commande pour la tache planifiée :
schtasks /create /SC daily /TN Daily_VM_backup /TR "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -file C:\Script\Veeam_Zip_SITE1.ps1" /ST 23:00 /RU system
Et voila…
Laisser un commentaire