Start-VBRZip in Veeam Backup Free Edition

PowerShell script exchange

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby v.Eremin » Mon Sep 21, 2015 9:35 am

Sorry for a late reply. I must have missed your post.

Anyway, the blog post as well as links it contains seems to be good. They even have been updated recently to address few previously existed inconsistencies. So, kindly check them, if you haven't done it already.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13433
Liked: 987 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby coder51 » Mon Sep 21, 2015 1:39 pm 1 person likes this post

v.Eremin wrote:Sorry for a late reply. I must have missed your post.

Anyway, the blog post as well as links it contains seems to be good. They even have been updated recently to address few previously existed inconsistencies. So, kindly check them, if you haven't done it already.

Thanks.

Ah, so they are. Thank you.
coder51
Lurker
 
Posts: 2
Liked: 1 time
Joined: Wed Aug 26, 2015 3:10 pm

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby v.Eremin » Mon Sep 21, 2015 2:19 pm

You're welcome. Should any help with scripting be needed, kindly, let me know. Thanks.
v.Eremin
Veeam Software
 
Posts: 13433
Liked: 987 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby TC1927 » Thu Sep 24, 2015 10:27 am

Hi there,

Hope you can help with this - apologies if it's something that's already been discussed.

I am trying to run the hyper-v script as a scheduled task. Veeam v8 is installed on a Server2012 instance, with the Hyper V role installed. Powershell v3.

The script returns the following output when run:

Code: Select all
Find-VBRHvEntity : Cannot validate argument on parameter 'Server'. The argument is null. Supply a non-null
argument and try the command again.
At C:\VeeamZIPHV.ps1:77 char:48
+   $VM = Find-VBRHvEntity -Name $VMName -Server $Server
+                                                ~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Find-VBRHvEntity], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.FindVBRHvEnti
   ty
 
Start-VBRZip : Cannot validate argument on parameter 'Entity'. The argument is null. Supply a non-null
argument and try the command again.
At C:\VeeamZIPHV.ps1:87 char:40
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $Comp ...
+                                        ~~~
    + CategoryInfo          : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Commands.Backup.Start
   VBRZip
 
You cannot call a method on a null-valued expression.
At C:\VeeamZIPHV.ps1:92 char:5
+     $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull


Hope someone can assist!

Cheers
TC1927
Lurker
 
Posts: 2
Liked: never
Joined: Thu Sep 24, 2015 10:22 am

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby jbilt2 » Fri Sep 25, 2015 3:47 pm

@TC1927
I originally had the same issue with $Server coming up null. The only way I could get it working was by setting $HostName variable to "LOCALHOST" instead of the actual host name. Might be worth using as a workaround if you're only going to run locally as I am.


I also have my own issue I'm looking for help with:
I have a working script and am jolly about it. Working, that is, as long as I run it manually from PowerShell or from Posh ISE. If I try to run it with Task Scheduler, I get an error about the encryption key. I used Start-Transcript to get the below log when running the script as a SchedTask.

Code: Select all
ConvertTo-SecureString : Key not valid for use in specified state.

At C:\scripts\vm-backup.ps1:81 char:75
+     $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | Conver ...
+                                                                           ~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [ConvertTo-SecureString], CryptographicException
    + FullyQualifiedErrorId : ImportSecureString_InvalidArgument_CryptographicError,Microsoft.PowerShell.Commands.Conv
   ertToSecureStringCommand


PS>TerminatingError(Add-VBREncryptionKey): "Cannot validate argument on parameter 'Password'. The argument is null. Provide a valid value for the argument, and then try running the command again."
Add-VBREncryptionKey : Cannot validate argument on parameter 'Password'. The argument is null. Provide a valid value
for the argument, and then try running the command again.
At C:\scripts\vm-backup.ps1:81 char:53
+     $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | Conver ...
+                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-VBREncryptionKey], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.AddVBREncryptionKey


I have a text file with password that I reference in the variable for $EncryptionKey. Again, the script works when I run manually but not when run via Task Scheduler. Task setup: Run with local admin-level account, highest priv=yes. Saving the backups locally so no issue there.

Any help is appreciated.
jbilt2
Novice
 
Posts: 3
Liked: never
Joined: Thu Sep 24, 2015 1:15 pm

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby TC1927 » Mon Sep 28, 2015 9:09 am

@jbilt2

Thanks for the response - I haven't tried this yet but I'm not sure if it's the answer as the machine running Hyper-V and containing the VMs are separate physical boxes to the one running Veeam.

# Name of vCenter or standalone host VMs to backup reside on (Mandatory)

As I read it, the $Hostname should be the name of your Hyper-V host, which in this case is a remote host rather than local.

As for your issue - have you tried it without encryption (ie encryption = $false) ?

Thanks again
TC1927
Lurker
 
Posts: 2
Liked: never
Joined: Thu Sep 24, 2015 10:22 am

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby v.Eremin » Mon Sep 28, 2015 2:28 pm

TC1927 wrote:The script returns the following output when run:

What name you're specifying as a $HostName variable? Are you positive the host is added to a backup console under the very same name that is setup as $HostName variable?
v.Eremin
Veeam Software
 
Posts: 13433
Liked: 987 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby v.Eremin » Mon Sep 28, 2015 2:47 pm

jbilt2 wrote:I have a working script and am jolly about it. Working, that is, as long as I run it manually from PowerShell or from Posh ISE. If I try to run it with Task Scheduler, I get an error about the encryption key. I used Start-Transcript to get the below log when running the script as a SchedTask.

Have you followed instructions provided in the corresponding blog post ("Encryption" section) on how encryption key should be created? Also, if I remember correctly, to make encryption work properly, the account under which secure key has been created should be the same as the account under which the script is executed. Thanks.
v.Eremin
Veeam Software
 
Posts: 13433
Liked: 987 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby jbilt2 » Wed Sep 30, 2015 6:22 pm

v.Eremin wrote:Also, if I remember correctly, to make encryption work properly, the account under which securekey has been created should be the same as the account under which the script is executed. Thanks.


Indeed it seems this was my problem. I had created the key with my user but was running the scheduled task as a local user (admin). Recreating the key with the local account allowed the script to run successfully.

But this raises a question/concern about this concept: how does this relate to restoration & decryption of the backup files? Is this user account the only one that will be able to decrypt the data? And a secondary question: if I had used a domain account, would the key be portable to other hosts? Or is the SecureKey not only user-specific, but also machine-specific?
jbilt2
Novice
 
Posts: 3
Liked: never
Joined: Thu Sep 24, 2015 1:15 pm

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby v.Eremin » Thu Oct 01, 2015 11:56 am

But this raises a question/concern about this concept: how does this relate to restoration & decryption of the backup files? Is this user account the only one that will be able to decrypt the data?

When you try to restore an encrypted backup file, you'll be asked to enter a corresponding password. So, a person knowing a password will be able to restore the data.

And a secondary question: if I had used a domain account, would the key be portable to other hosts? Or is the SecureKey not only user-specific, but also machine-specific?

I think it's a user-specific, but haven't tested that myself. It should be pretty easy to check, though, just copy a corresponding file to a different machine, log on into it, using the same account, try to run a script and see whether you encounter any issue.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13433
Liked: 987 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

[MERGED] : Backup fo LAN

Veeam Logoby anv » Tue Oct 06, 2015 2:53 pm

Hello! I can make BACKUP for LAN use console (without powershell).I use credentials for access to LAN share. How can I use this paramete in Powershell? Thank you!!!
anv
Novice
 
Posts: 5
Liked: never
Joined: Mon Oct 05, 2015 9:27 am
Full Name: anv

Re: Backup fo LAN

Veeam Logoby v.Eremin » Tue Oct 06, 2015 4:00 pm

What specific issue you get while trying to backup to a specific share via PS? Can you please post a portion of code that fails? Have you tried to map a given share, using New-PSDrive commandlet? Also, does a computer account a script gets executed from has a write permission on the said share? Thanks.
v.Eremin
Veeam Software
 
Posts: 13433
Liked: 987 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Backup fo LAN

Veeam Logoby anv » Wed Oct 07, 2015 6:12 am

When I try to create backup on network share I receive the error, thus the user to run the script created in the network globe,access full

Code: Select all
You cannot call a method of the expression with the value NULL.
D:\Veeam\VeeamZIP-BACKUP.ps1:41 знак:54
+ {$TaskSessions = $ZIP.GetTaskSessions().logger.getlog <<<< ().updatedrecords
    + CategoryInfo          : InvalidOperation: (getlog:String) [], RuntimeExc
   eption
    + FullyQualifiedErrorId : InvokeMethodOnNull


I try to use New-PSDrive , but it was problem with login and password. THANK you!!!
anv
Novice
 
Posts: 5
Liked: never
Joined: Mon Oct 05, 2015 9:27 am
Full Name: anv

[MERGED] : Unable to backup via powershell

Veeam Logoby gotxi » Wed Oct 07, 2015 8:06 am

Hi folks! I have been working on this script to backup all my standalone Hyper-V Server host for 2 days and i am still unable to do backups of my VM's with Veeam via powershell.

It's a modified Script of Vladimir Eremin with some write-hosts and modified to work with Hyper-V.

Code: Select all
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue


# 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 = (get-vm -ComputerName HATHOR | foreach { $_.Name })

#$VMNames = ""


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

# Directory that VM backups should go to (Mandatory; for instance, C:\Backup)
$Directory = "Z:\"
#(Z:\ is a maped network share)

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

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

# Enable notification (Optional)
$EnableNotification = $True

# Email SMTP server
$SMTPServer = "smtp.mycompany.com"

# Email FROM
$EmailFrom = "hathor@mycompany.com"

# Email TO
$EmailTo = "myname@mycompany.com"

# Email subject
$EmailSubject = "HATHOR BACKUP REPORT"

##################################################################
#                   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 ################ I DID!!!
write-host "Iniciando backups..."
Asnp VeeamPSSnapin
write-host "Recopilando información del Hipervisor $HostName..."
$Server = Get-VBRServer -name $HostName
$MesssagyBody = @()
write-host "Hecho."
foreach ($VMName in $VMNames)
{
  Write-Host "Recopilando información de la VM $VMName..."
  $VM = Find-VBRHvEntity -Name $VMName -Server $Server
  Write-Host "Recopilada."
  If ($EnableEncryption)
  {
    $EncryptionKey = Add-VBREncryptionKey -Password (cat $EncryptionKey | ConvertTo-SecureString)
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
  }
 
  Else
  {

    Write-host "Inicio del backup de $VMName..."
    $ZIPSession = Start-VBRZip -Entity $VMName -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
    Write-host "Terminado."
  }
 
  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)
$SMTP.Send($Message)
}




The script Output is this:

Code: Select all
PS C:\Users\Administrator> C:\Users\Administrator\Desktop\VeeamZIP (HV).ps1
Iniciando backups...
Recopilando información del Hipervisor 128.64.80.56...
Hecho.
Recopilando información de 2012R2HATHOR...
Recopilada.
Inicio del backup de 2012R2HATHOR...
Start-VBRZip : Cannot bind parameter 'Entity'. Cannot convert the "2012R2HATHOR" value of type "System.String" to type "Veeam.Backup.Common.IItem".
At C:\Users\Administrator\Desktop\VeeamZIP (HV).ps1:98 char:40
+     $ZIPSession = Start-VBRZip -Entity $VMName -Folder $Directory -Compression $ ...
+                                        ~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Start-VBRZip], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Veeam.Backup.PowerShell.Commands.Backup.StartVBRZip
 
Terminado.
You cannot call a method on a null-valued expression.
At C:\Users\Administrator\Desktop\VeeamZIP (HV).ps1:104 char:5
+     $TaskSessions = $ZIPSession.GetTaskSessions().logger.getlog().updatedrecords
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Recopilando información de C0124_Mizar_Portatil_146...


I cancelled at this point, every VM fails the same.
gotxi
Novice
 
Posts: 5
Liked: never
Joined: Wed Oct 07, 2015 7:30 am
Full Name: David Gacias

Re: Discussion on blog post: Update 2 featuring PowerShell

Veeam Logoby v.Eremin » Wed Oct 07, 2015 10:05 am

anv wrote:When I try to create backup on network share I receive the error

Seems like a $ZIP variable doesn't contain anything, as the result you get the said error. Will the script work if you change target to local disk temporarily?

anv wrote:The user to run the script created in the network globe,access full

I was not talking about an user running a script, but rather about computer account that should have write permissions on the share. Otherwise, you'd get Access Denied message (kindly, check the thread your post has been merged into).

anv wrote:I try to use New-PSDrive , but it was problem with login and password.

What particular error you got?

Thanks.
v.Eremin
Veeam Software
 
Posts: 13433
Liked: 987 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

PreviousNext

Return to PowerShell



Who is online

Users browsing this forum: Bing [Bot] and 2 guests