标签:veeam脚本 veeam计划任务 veeam免费版计划任务 veeam free
Veeam对于备份虚拟机而言,挺不错的,而且还有免费版,目前最新的是Veeam Backup Free Edition 9.5。因此,免费版每天的备份量是很大的,有条件的可以考虑使用收费版。
言归正传,我们现在来设置一下,让免费版也有计划任务。
免费版在程序界面是设置不了计划的,谁让它是免费的呢,但是我们可以借助PowerShell和PS脚本,手动来做个包含批量备份的计划任务。
# VM names separated by commas
$VMNames = "Windows Server 1","Windows Server 2","CentOS 7"
# vCenter name/IP
$HostName = "192.168.0.1"
# Directory that VM backups should go to
$Directory = "D:\Backup"
# Desired compression level, following compression level from Veeam (Optional)
$CompressionLevel = "10"
# Quiesce VM when taking snapshot (Optional; VMware Tools are required; Possible values: $True/$False)
$EnableQuiescence = $True
# Protect resulting backup with encryption key (Optional; $True/$False)
$EnableEncryption = $False
# Encryption Key (Optional; path to a secure string, C:\SecureString.txt"
$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 = "In1Week"
# Email Settings
# Enable notification (Optional)
$EnableNotification = $True
# Email SMTP server
$SMTPServer = "smtp.smtp.com"
# Email FROM
$EmailFrom = "sender@mail.com"
# Email TO
$EmailTo = "recipient@mail.com"
# Email subject
$EmailSubject = "Veeam Backup Job"
# 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: #54b948; 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
$mbody = @()
foreach ($VMName in $VMNames)
{
$VM = Find-VBRViEntity -Name $VMName -Server $Server
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
If ($EnableNotification)
{
$TaskSessions = $ZIPSession.GetTaskSessions()
$FailedSessions = $TaskSessions | where {$_.status -eq "EWarning" -or $_.Status -eq "EFailed"}
if ($FailedSessions -ne $Null)
{
$mbody = $mbody + ($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
{
$mbody = $mbody + ($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 = $mbody | ConvertTo-Html -head $style | Out-String
#$SMTP = New-Object Net.Mail.SmtpClient($SMTPServer)
#$SMTP.Send($Message)
}
VMNames:后面跟虚拟机的名字,在vCenter、ESXi上显示的名字
HostName:vCenter服务器的IP或域名,我只在vCenter上面试过,因为涉及到多台服务器。如果没有vCenter并且要备份多台服务器里的虚拟机,不清楚能不能像vmnames这样做一个foreach。
Directory:目录,支持网络路径,即\192.168.x.x\Folder
CompressionLevel :默认是4,数字越大压缩率越高,相关文档没介绍这个值可以最大多少
Retention:这个没有测过,备份保存天数。In1Week是保存一周。不清楚会不会自动删除旧备份。如果不会删,看我之前的一个帖子,手动写个清理脚本也可以。
EMAIL那部分就是SMTP地址、发件人、收件人,最后两行我注释掉了,如果需要发送邮件,去掉最后两行的注释就可以。
然后保存这个脚本,可以放到C盘,起名VeeamZip.ps1
PowerShell路径:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
计划任务里,设置powershell的路径,参数设置"C:\VeeamZip.ps1"
OK,设置个任务它就可以自动备份了,添加完后可以手动执行一下看看效果。
以上脚本参考外国网站,具体哪个网站我没记,搜索一下应该可以搜索到原文的。
标签:veeam脚本 veeam计划任务 veeam免费版计划任务 veeam free
原文地址:http://blog.51cto.com/cto99/2124918