PowerShell script exchange
Post Reply
ssid00
Lurker
Posts: 2
Liked: never
Joined: Jan 16, 2017 10:46 am
Full Name: Slawek Sidorski
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by ssid00 »

Hallo,
I have 9,5 Free Edition.
I want backup 3 VM's, but when I use this:
# Names of VMs to backup separated by semicolon (Mandatory)
$VMNames = "MyVM1";"MyVM2";"MyVM3"
This script didn't backup all 3 VM's, but only the first one.

I use original script without any changes:
# Author: Vladimir Eremin
# Created Date: 3/24/2015
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

As mentioned in the blog post, you should use comma instead of semicolon as a separator. Most likely, you've somehow got the very first version of the script having that misleading note. Thanks.
ssid00
Lurker
Posts: 2
Liked: never
Joined: Jan 16, 2017 10:46 am
Full Name: Slawek Sidorski
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by ssid00 »

Thans a lot...it's work.
I don't know why I didn't find this solution...

I have one more question. Sometimes I have this error:

Code: Select all

2017-01-16 12:25:51 :: Processing VM1 Error: The specified network name is no longer available.
Failed to write data to the file [\\xxx.xxx.xxx.xxx.\Share_1\VM1D2017-01-16T122524.vbk].
Failed to download disk.
Shared memory connection was closed.
Failed to upload disk.
Agent failed to process method {DataTransfer.SyncDisk}.
I have to add, that this share is from HPE StoreOnce VSA.
Any idea what can be the problem?
solidus
Novice
Posts: 5
Liked: 1 time
Joined: Jan 02, 2017 3:45 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by solidus »

@ssid00

have you tried on a share residing on a different host or trying using the IP instead of network name?


@Vlad

Ok Vlad, I made it work with the "CredMan" APIs

What I have done is just adding these parts of code on the original script in the user define variables:

Code: Select all

...
# Protect resulting backup with encryption keys (Optional; $True/$False)
$EnableEncryption = $True

# Name of the user (windows credential vault), which provides the encryption key used to encrypt the vbk backup result file (Mandatory if $EnableEncryption enabled above; for instance, backup_user)
$EncryptionUser = ""

# 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 = "Never"
...
And these in the "invoke Start-VBRZip" part:

Code: Select all

...
Asnp VeeamPSSnapin

# Dot sourced include to CredMan.ps1
. "$PSScriptRoot\CredMan.ps1"

$Server = Get-VBRServer -name $HostName
$MesssagyBody = @()
...
...
    If ($EnableEncryption)
    {
        $CredType = "GENERIC"
        $Target = $EncryptionUser
        [Object] $Cred = Read-Creds $Target $CredType
        If($null -eq $Cred)
        {
            Write-Host "Credential for '$Target' as '$CredType' type was not found."
            return
        }
        If($Cred -is [Management.Automation.ErrorRecord])
        {
            return $Cred
        }
        $SecureCredStr = ConvertTo-SecureString "$($Cred.CredentialBlob)" -AsPlainText -Force
        $EncryptionKey = Add-VBREncryptionKey -Password $SecureCredStr
        $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
...
This works but is quite improvable, Im still working on it

Also, I made other changes to the original to make it more "profitable", I PMed you about this


thank you
carussell
Influencer
Posts: 12
Liked: 2 times
Joined: Jan 17, 2017 3:36 pm
Full Name: Chris Russell
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by carussell »

OK i have looked all over and I see lots of references, but nothing that seems to solve my issue.

I can't get the script to work. Every time I get the error:

Code: Select all

Start-VBRZip : Cannot validate argument on parameter 'Entity'. The argument is null. Provide a valid value for the argument, and 
then try running the command again.
At C:\VeeamZIPtest2.ps1:86 char:40
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compre ...
+                                        ~~~
    + CategoryInfo          : InvalidData: (:) [Start-VBRZip], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip
details are:
windows 2016 for the VBR server
version 9.5 free
Hyper-V host
backups work fine from the console

could dashes in the HyperV Host name, or in the VM names have anything to do with it?

And though new, if I could offer one SMALL suggestion. when various updates are made to the model script, could a small "revised date" be added at the top. There seem to be multiple versions running around and they all seem to say 3/24 at the top.
solidus
Novice
Posts: 5
Liked: 1 time
Joined: Jan 02, 2017 3:45 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by solidus »

Hi carussell

I got the same error in VMware when mistyped the correct vm name in the variable $VMNames, the result was that "Find-VBRViEntity" function could not find any host with that vm name so the variable $VM was assigned null and subsequently the Start-VBRZip function says that parameter 'Entity' using $VM cant be validated

Not sure if is your case, just check. Maybe try doing a little debug putting a "Write-Host $VM" after
$VM = Find-VBRViEntity -Name $VMName -Server $Server
and before
$ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention -EncryptionKey $EncryptionKey
carussell
Influencer
Posts: 12
Liked: 2 times
Joined: Jan 17, 2017 3:36 pm
Full Name: Chris Russell
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by carussell »

OK === Seems I may have solved this ===

in my efforts to make sure I got the most updated version of the script I was careful to make sure I used the one that specified it was "updated". I did finally find a post that referenced the VBRViEntity command and indicated it was solely for VMware... then I compared and found it in my script. I guess even though I loaded from the HyperV link, and it said it was Hyper V, it had a copy of the VMware version in it as well. I replaced that "Vi" command with the corresponding VBRHvEntity command. Re-ran the scrript and it seems to work. Now for the next part. scheduling and seeing if I can get everything to backup, save and delete at the right times.

Like I said, a nice extra line at the top to specify what hypervisor and what the revision date is would be a GREAT addition if its not too much trouble. If its in there somewhere and I missed it I apologize....

--- Edit --- Solidus, I didn't see the reply until I already had it kind of fixed. I had actually double and triple checked the names ahead of time assuming it was just an issue of something being case sensitive, but nothing had worked. can I assume from your post that you are using VMware? I went back and double checked the file I downloaded. It was VeeamZIP-updated-HV but inside the compressed file were two files.... one labeled HV and one labeled updated. I used updated which was apparently wrong.
solidus
Novice
Posts: 5
Liked: 1 time
Joined: Jan 02, 2017 3:45 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by solidus »

I had actually double and triple checked the names
:lol: Sorry just tried to give hint, nor I knew your level of expertise with PS
corresponding VBRHvEntity command
thats it, is it "Find-VBRHvEntity" the corresponding?
As you correctly said I use the VMware version...
carussell
Influencer
Posts: 12
Liked: 2 times
Joined: Jan 17, 2017 3:36 pm
Full Name: Chris Russell
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by carussell »

yeah no problem with the suggestions... my level isn't all that high.

Yes, from what I can tell, the VMware versions use Find-VBRViEntity, and the HyperV uses Find-VBRHvEntity. I was just blown away that the file labeled HV version would have the VMware version in it too... it never occured to me that might be the case.

Well at least I found a solution and now I can get to scheduling the DR plan...

Thanks again.
carussell
Influencer
Posts: 12
Liked: 2 times
Joined: Jan 17, 2017 3:36 pm
Full Name: Chris Russell
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by carussell »

OK.. Now my problem is with task scheduler.... Scripts will work fine if launched individually, but can't be run from task scheduler. They show as completed in TS, but no backup file created, no job shows on console, and no backup listed on console.

I have seen stuff about this not working, but this all seems to be centered around remote file shares. This is saving backups to local storage on the VBR server
tdewin
Veeam Software
Posts: 1818
Liked: 655 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by tdewin »

Could be a permission issue though. Try running the task as administrator

Alternatively, you can add this to the end of the script (providing c:\d\ exists). It will echo the error variable to a file, so you can inspect what is going wrong

Code: Select all

$error | Out-File -FilePath "C:\d\error.txt"
carussell
Influencer
Posts: 12
Liked: 2 times
Joined: Jan 17, 2017 3:36 pm
Full Name: Chris Russell
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by carussell »

VBR, SQL, tasks, and SCRIPT, all be setup and run as domain/administrator so there shouldn't be any rights issues.

creating and trying the error file to see what I get
carussell
Influencer
Posts: 12
Liked: 2 times
Joined: Jan 17, 2017 3:36 pm
Full Name: Chris Russell
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by carussell »

OK no error in the given location. I guess that only means that something is preventing the script from running. This makes sense to me since I can run it from PS and everything works.
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

I'm along the same line with Timothy here. Looks like permission problem.

Are you positive that while executing script manually and automatically (Task Scheduler), you've used the very same account? Is "run with the highest privileges" check-box enabled?

Thanks.
carussell
Influencer
Posts: 12
Liked: 2 times
Joined: Jan 17, 2017 3:36 pm
Full Name: Chris Russell
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by carussell »

yes .... double checked all that (and triple checked).

Found the issue I think. Script was in a folder called \PS Scripts and was titled VM2-Daily BU.ps1. Launching from powershell or from a right click was never an issue, but from task scheduler, it created this:
powershell -executionpolicy bypass -file d:\PS Scripts\VM2 Daily.ps1

I am really a novice at all this, including powershell, so it might be a rookie mistake, but it seems as though task scheduler can't handle the spaces (and maybe dashes) in the folder and file name. changed those names to remove spaces and dashes, and it launched like a dream.

SO.... If its not launching from task scheduler... check for spaces in file or folder names... could be the issue

next question though.... I see in the console that there are retention options (version 9.5) for In6Months and In1year. Are those valid scriptable retention options for the Powershell script?
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Changed those names to remove spaces and dashes, and it launched like a dream.
Not only there were spaces in script names, but also scripts seem to have been named differently: VM2-Daily BU.ps1 and VM2 Daily.ps1 .
Are those valid scriptable retention options for the Powershell script?
Correct.
carussell
Influencer
Posts: 12
Liked: 2 times
Joined: Jan 17, 2017 3:36 pm
Full Name: Chris Russell
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by carussell »

v.Eremin wrote:Not only there were spaces in script names, but also scripts seem to have been named differently: VM2-Daily BU.ps1 and VM2 Daily.ps1 .
Actually, that was a typo.. (I changed the file and folder names for security reasons and mistyped)... all I did was shorten the names to remove spaces and dashes.
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Got it. I've thought that a different names might have been an additional cause of the problem.

Anyway, glad to know that you've fixed the issue.
elyos002
Novice
Posts: 3
Liked: never
Joined: Jan 31, 2017 8:46 am
Contact:

[MERGED] backup with powershell script

Post by elyos002 »

Hello everybody,

First, I apologize because my english is very poor.
I installed VEEAM backup free edition on a Windows Server 2008 R2. I succeeded in making a backup of a test VM in the directory : "C:\backup". Then, i also suuceeded in doing another backup of this VM with the powershell script wrritten by Vladimir, still at the same place.
Then, I wanted to make this backup on a NAS. I succedeed in doing it with the graphical interface because I could provide the credentials of the NAS (login / password). But now, I am trying to do the same with the powershell sript but it does not work, because I do not know how to provide the credentials of the NAS within the script. Does anyone know which command line I have to insert in the script to provide the credentials?
I precise that the NAS is mounted as network share in the computer under the letter "N:\".

Thank you for your help.
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Your post has been merged into existing thread.

Kindly, check the answers provided above, this question has been discussed several times already.

Thanks.
efishta
Lurker
Posts: 1
Liked: never
Joined: Feb 21, 2017 3:55 am
Full Name: ef

[MERGED] multiple VMs error

Post by efishta »

I followed the guide posted on VEAM's blog to automate backup scheduling, and I'm running into an error. I have pasted the script below. The only changes made from the stock script were the removal of the email notification section, and the addition of the required variables in the script.

When I run it, I get this error message:

Code: Select all

PS C:\autobackup_script> C:\autobackup_script\VeeamZIP.ps1
Start-VBRZip : Veeam Backup Free Edition does not support of multiple VMs backup. Specify a single VM, or install a paid product license.
At C:\autobackup_script\VeeamZIP.ps1:57 char:19
+     $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $Comp ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Start-VBRZip], Exception
    + FullyQualifiedErrorId : System.Exception,Veeam.Backup.PowerShell.Cmdlets.StartVBRZip
and here is the script being run:

Code: Select all

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

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

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

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

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

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


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

#################### DO NOT MODIFY PAST THIS LINE ################
Asnp VeeamPSSnapin

$Server = Get-VBRServer -name $HostName

foreach ($VMName in $VMNames)
{
  $VM = Find-VBRViEntity -Name $VMName -Server $Server
  
  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 
  {
    $ZIPSession = Start-VBRZip -Entity $VM -Folder $Directory -Compression $CompressionLevel -DisableQuiesce:(!$EnableQuiescence) -AutoDelete $Retention
  }
  
}
What am I doing wrong here? I have not modified the core functionality of the script at all.
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Are you positive there is only one VM in your infrastructure with "h-dc01" name? How many VMs will be returned, if you input $VM variable into console? Thanks.
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Update for everyone struggling with retention parameter issue:

Our QA team is about to investigate it closely.

I will update the topic once I have more information.
JBFriedrich
Lurker
Posts: 2
Liked: 1 time
Joined: Mar 08, 2017 10:18 am
Full Name: Jason Friedrich
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by JBFriedrich »

First of all, thank you very much for creating the very easy to use Powershell script and of course to include the Powershell extensions in the Free Edition. It works quite well when using it with a local directory, but as so many in this, I have problems running it with a SMB share as a target. Everything works fine in the UI, but of course I can specify a username/password there to access the share.

I read the whole thread, and it seems that either adding the Computer Account with the right permissions to the share, or running the Veeam Services under a user that has read/write access to the share, solves the problem for almost everyone. Unfortunately that is not an option for me as I only have a user for the SMB share, but otherwise no Domain Administrator or even Administrator permissions. There is also no way to get these permissions or get the Computer Account added.

Does anyone have a suggestion how to solve this issue with my use case, i.e. when there is no way to change permissions on the share and the only method of authentication is a username and a password?

Thanks!
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin » 1 person likes this post

I don't think we have any solution for you at the moment, but most likely -NetworkCredentials parameter will be added to Start-VBRZip commandlet in the upcoming Update 2. Thanks.
JBFriedrich
Lurker
Posts: 2
Liked: 1 time
Joined: Mar 08, 2017 10:18 am
Full Name: Jason Friedrich
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by JBFriedrich » 1 person likes this post

v.Eremin wrote:I don't think we have any solution for you at the moment, but most likely -NetworkCredentials parameter will be added to Start-VBRZip commandlet in the upcoming Update 2. Thanks.
That would be an awesome improvement! Thanks Vladimir! In the meantime I have used your Powershell script as a boiler plate and modified it a little bit. My script now uses a temporary directory on C:\ where it writes the VBK file. After the backup process is completed for that VM, the file is moved to the remote SMB repository, then the next VM is processed. This keeps the temporary backup storage footprint low on the VM itself. After all VMs are backed up and moved, the script removes all VBK files older than "n" days from the remote repository. Another little workaround because I cannot use the retention setting at the moment.

The script is available as a Gist on GitHub. Hope that helps some people who have the same or a similar setup. Can't wait for Update 2 though and have a proper method of directly accessing the SMB repository. Thanks again for providing the initial Powershell script and for your responsiveness here in the forums. It is much appreciated! :D
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

You've found a smart workaround to address current limitation. Glad to hear that. Hopefully, with Update 2 this pain will go away.

As to retention settings not working properly, according to QA team, they are about to conduct an investigation in this regard. I'll keep you updated on the results on their findings.
ischneider
Novice
Posts: 3
Liked: never
Joined: Jan 04, 2017 12:45 pm
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by ischneider »

Adding the -NetworkCredentials parameter will be a hughe improvement....

Is there an announced date for update 2 already?
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRZip in Veeam Backup Free Edition

Post by veremin »

Not yet. Most likely, some specifics regarding it will be shared in one of the next forum weekly digests.
shlomia
Influencer
Posts: 19
Liked: never
Joined: Mar 20, 2017 3:40 pm
Full Name: Shlomi Avraham
Contact:

[MERGED] AutoDelete Question

Post by shlomia »

Hi,

I'm using Veeam with powershell & task schedule.
I have the following script:

Code: Select all

Param(
  [Parameter(Mandatory=$true)][string]$VM,
  [Parameter(Mandatory=$true)][string]$Destination,
  [Parameter(Mandatory=$true)][ValidateSet(0,4,5,6,9)][int]$Compression,
  [bool]$DisableQuiesce=$true,
  [Parameter(Mandatory=$true)][ValidateSet("Never","Tonight","TomorrowNight","In3days","In1Week","In2Weeks","In1Month")][string]$Autodelete
)
#Load Veeam Toolkit
& "C:\Program Files\Veeam\Backup and Replication\Backup\Initialize-VeeamToolkit.ps1"
#Validate any parameters
$vmentity = Find-VBRViEntity -Name $VM 
if ($vm -eq $null)
{
  Write-Host "VM: $VM not found" -ForegroundColor "red"
  exit
}
if (-Not (Test-Path $Destination))
{
  Write-Host "Destination: $vmname not valid" -ForegroundColor "red"
  exit
}
if ($DisableQuiesce -eq $true)
{
    Start-VBRZip -Entity $vmentity -Folder $destination -Compression $Compression -AutoDelete $Autodelete -DisableQuiesce
}
else
{
    Start-VBRZip -Entity $vmentity -Folder $destination -Compression $Compression -AutoDelete $Autodelete
}
I can add parameters and execute the script for each VM.
So my question is, if I have '-AutoDelete 'In2Weeks’' - who is responsible of the erasing?
Also, If I doesn't want to autodelete the backup after the backup is done, How can I remove this 'auto delete' parameter from the backup file? ( after the file is already created with the -autodelete option )
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests