PowerShell script exchange
Vitaliy S.
Product Manager
Posts: 23005
Liked: 1560 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup single VM (not all VMs) within job?

Post by Vitaliy S. » Mar 02, 2017 12:43 pm

Yes, this makes total sense and is already acknowledged as an important feature > Backup VM within a Job - especially SQL?

stephen.loera
Service Provider
Posts: 31
Liked: 6 times
Joined: May 11, 2016 4:59 am
Full Name: Stephen Loera
Contact:

Re: backup single VM (not all VMs) within job?

Post by stephen.loera » Dec 04, 2017 11:19 pm

Any chance that this will be a feature in Update 3?

I know that "Quick Backup" is an option but that only works if there is an existing full backup. If I add a new VM to backup, I would like to be able to kick off a "full" backup on that newly added VM without the need to run the eintire job on all the VMs.

veremin
Product Manager
Posts: 16901
Liked: 1440 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: backup single VM (not all VMs) within job?

Post by veremin » Dec 05, 2017 1:48 pm

Any chance that this will be a feature in Update 3?
Update 3 does not have this feature implemented. So, for now the scripts and Quick Backup (for cases where full backup is there) are the only options. Thanks.

Dani
Novice
Posts: 5
Liked: never
Joined: Mar 12, 2015 11:44 am
Full Name: Daniel
Contact:

[MERGED] Backup only one VM within a job with powershell

Post by Dani » Dec 06, 2017 1:55 pm

Hello

We have a backup job configured to backup all vms on a specific volume.

Virtual machines to backup: "cluster shared volume 01"
Runtime: every day at 10PM.

Additionally, we want to run a backup of one VM whithin this volume every 2 hours from 8AM to 6PM.

What would be the best way to do that?
Would it be possible with a powershell script?
If yes, how?

Thanks,
Daniel

veremin
Product Manager
Posts: 16901
Liked: 1440 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: backup single VM (not all VMs) within job?

Post by veremin » Dec 06, 2017 2:46 pm

Your post has been merged into existing discussion talking about similar matter. Please, check the answers provided above. Thanks.

t481
Enthusiast
Posts: 56
Liked: never
Joined: Apr 28, 2015 7:52 am
Contact:

Re: backup single VM (not all VMs) within job?

Post by t481 » Feb 08, 2018 11:51 am

hi Veeam engineers,
Surely this is an indication that there is a requirement for this feature to be implemented. I'm having the same issue whereby I need to manually backup individual VMs that have just been added to a job and I need to test how this would work within the same job. I could create a separate backup job to test the backup but I don't see why such a simple feature hasn't been added especially since it's been present in legacy backup software for as long as I can remember!

veremin
Product Manager
Posts: 16901
Liked: 1440 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: backup single VM (not all VMs) within job?

Post by veremin » Feb 08, 2018 11:56 am

Isn't Quick Backup something you're looking for? Thanks.

t481
Enthusiast
Posts: 56
Liked: never
Joined: Apr 28, 2015 7:52 am
Contact:

Re: backup single VM (not all VMs) within job?

Post by t481 » Feb 26, 2018 7:43 am

Almost the same thing here.

I added an SQL VM to a job and wanted to back it up but could not use QuickBackup due to lack of existing full backup file. Sometimes you just want to run a job against a VM immediately for political as well as practical reasons e.g. SQL log backup and truncation.

veremin
Product Manager
Posts: 16901
Liked: 1440 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: backup single VM (not all VMs) within job?

Post by veremin » Feb 26, 2018 6:55 pm

Then, you can exclude all but one VM, back it up and include other VMs back. Some scripts examples are provided above. Thanks.

t481
Enthusiast
Posts: 56
Liked: never
Joined: Apr 28, 2015 7:52 am
Contact:

Re: backup single VM (not all VMs) within job?

Post by t481 » Feb 27, 2018 8:37 am

I contacted your support team seeking help with the script as I had an issue with it (case no. 02593627) and was told that this is for an older version of Veeam. I was also advised to write a "feature request" here in the forum.

veremin
Product Manager
Posts: 16901
Liked: 1440 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: backup single VM (not all VMs) within job?

Post by veremin » Feb 27, 2018 6:00 pm

Consider your feature request counted.

As to the script, can you tell me how VMs are added to backup job? As individual VMs or as a part of container (folder, resource pool, etc.)?

Thanks.

adb98
Enthusiast
Posts: 49
Liked: 9 times
Joined: Jul 21, 2016 5:03 pm
Full Name: Aaron B
Contact:

Re: backup single VM (not all VMs) within job?

Post by adb98 » Mar 01, 2018 7:57 pm

I have been wanting to write a script for a while that will do a quick backup via powershell. I have done so but had been contemplating wither to publish it out since I know I will get my fair share of snickers as I am no expert but I decided to go for it. Be easy on me as I not a Powershell god. Once you source the script and have the snappin registered, it will load the snappin, connect to your VBR server you tell it to, lookup the name you are trying to backup, check to see if that name is valid, if not it gives a list that are a close match. If it does match the script moves on and ensures that the backup job the VM is in is not currently running, if that passes it starts the quick backup.

Legal requires me to say run at your own risk. Adjust to suite your needs and enjoy.

Code: Select all

Function QuickBackup { 
# ----------------------------------------------------------------------------------------------
# Author - ABelisle - Sr. Sys Admin - THS 03/01/18
#**Legal stuff I have to state** This script comes with no warranty and I am not responsible for any issues this script may cause.
#Prequisites you will need to have the VeeamSnappin registered. It will add the snapping automatically but it has to be there.
#Function of this script is to load VeeamPSSnappin module, log into the main VBR server, check server name not given, and if valid start a quick backup
#Before using source the script . ./veeam quick Backup - after it is sourced. Type QuickBackup to run the script. You must use -vbrserver and type in a Veeam Server
# ----------------------------------------------------------------------------------------------
<#
Examples of this script are as follows:

QuickBackup server1,server2,server3

Example 1 - Quickbackup -vbrserver test -computername server1
Example 2 - Quickbackup -vbrserver test -computername server1,server2


#>
#Parameters   
Param(
[parameter(ValueFromPipeLineByPropertyName=$true,Mandatory=$true)][string[]]$computername, 
[parameter(Mandatory=$true)][string[]]$VBRServer)


#Loading Veeam Snappin Piece and Veeam Connection to the server - If it is not registered it tells you and stops the script. Once the Snappin is loaded it trys to connect to the VBR Server

    if( -Not( Get-PSSnapin -Name "VeeamPSSnapIn" -ErrorAction:SilentlyContinue ) ) { 
        if( Get-PSSnapin -Registered | Where-Object { $_.Name -eq "VeeamPSSnapIn" } ) { 
            # Snap-in is available, but not loaded; Add the snap-in
            Add-PSSnapin -Name "VeeamPSSnapIn" 
        } else { 
            # Module not available on the computer
            Write-Host -ForegroundColor Red "ERROR: The specified snap-in VeeamPSSnapIn is not found on this computer."
            break
        } # End if
    } else { 
        # Module is already loaded

    } # End if


try {((Get-VBRServer -name "$vbrserver" -ErrorAction SilentlyContinue) -eq $null)
    Write-Host -ForegroundColor Green "You are already connected to Veeam VBR server $vbrserver...Skipping sign in"}
catch
    {Write-Host "Please enter your credentials to connect to $vbrserver server"
    $creds = get-credential
    (Connect-VBRServer -server "$VBRServer" -Credential $creds)
}  


#This piece is where we check the server names given and ensure all is ok and run the script. It does this for each VM.

foreach ($c in $computername){
if((Find-VBRViEntity -Name $c) -eq $null){
    Write-Host -ForegroundColor Red "Server $c not valid. These server names listed below are a close match to what you might be looking for. Once name is corrected run it again. "
    (Find-VBRviEntity -Name "*$c*" |select Name)
     break
}
else{
    Write-Host -ForegroundColor Green "Server $c Found. Checking if Job containing VM is running."} 
    

if((Find-VBRViEntity -Name $c |Start-VBRQuickBackup -ErrorAction SilentlyContinue) -eq $null){
    write-error "Backup Job with $c in it already running! Check VBR Console"
    break
}
else{
    Write-Host -ForegroundColor Green "Quick Backup Request submitted for $c. Check VBR Console."}
    }
    
} # End Function Load-Module 


veremin
Product Manager
Posts: 16901
Liked: 1440 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: backup single VM (not all VMs) within job?

Post by veremin » Mar 02, 2018 10:14 am

Thank you, Aaron, for sharing the script; much appreciated.

However, it won't necessarily help in this particular case: Quick Backup requires full backup which does not exist for newly-added VMs.

Thanks.

t481
Enthusiast
Posts: 56
Liked: never
Joined: Apr 28, 2015 7:52 am
Contact:

Re: backup single VM (not all VMs) within job?

Post by t481 » Mar 05, 2018 11:57 am

The VMs are normally added individually.

veremin
Product Manager
Posts: 16901
Liked: 1440 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: backup single VM (not all VMs) within job?

Post by veremin » Mar 06, 2018 1:52 pm

I've just checked and the modified script provided on the second page works as expected. Feel free to leverage it. Thanks.

wwx500
Novice
Posts: 4
Liked: 1 time
Joined: Jul 11, 2017 8:57 pm
Full Name: William Wallhausser
Contact:

Re: backup single VM (not all VMs) within job?

Post by wwx500 » May 02, 2018 8:38 pm

Quick backup is handy, but it needs more options.
Eg. I have a vm with a failed backup but the failed vm is in multiple jobs and I have no way to tell quick backup which job should be rerun with the single vm.
I would also like the option to add several vms to rerun them in quick job rather than having to run, wait and monitor it several times.

veremin
Product Manager
Posts: 16901
Liked: 1440 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: backup single VM (not all VMs) within job?

Post by veremin » May 24, 2018 10:16 pm

I would also like the option to add several vms to rerun them in quick job rather than having to run, wait and monitor it several times.
Should be already there, as -VM parameter accepts the array of VMs for which you want to perform the QuickBackup.

reaperhammer
Service Provider
Posts: 27
Liked: 7 times
Joined: Aug 18, 2016 7:59 pm
Full Name: Will S
Contact:

Re: backup single VM (not all VMs) within job?

Post by reaperhammer » Jul 16, 2018 8:12 pm

I modified the script on Page2 to be compatible with Hyper-V VM's as well as VMware as the previous was only working with VMware.
WARNING I noticed this script will reset any custom disk exclusions, guest processing and credentials on the VM's that are removed then re-added to the job.
Another reason why Veeam should implement this feature in the GUI.

Code: Select all

# Load Veeam snapin
Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
 
Clear-Host
Write-Host "Veeam Single VM Backup Script`n"
Write-Host "Notes:"
Write-Host "VM must be explicitly defined in the job"
Write-Host "VM can not be inherited by a folder, datastore or other object"
Write-Host "else it will get excluded as well and job will be empty."
Write-Host "Always confirm job completion via Veeam BR Console!"
 
# Check Veeam Version (Must be v8)
If ((Get-PSSnapin VeeamPSSnapin).Version.Major -ne 8) {
   Write-Host "You must be running VBR v8 to run this script...Exiting"
   Exit
}
$ErrorActionPreference = 'Inquire'
 
# User Input
$jobName = Read-Host "Enter Job Name"
$vmName = Read-Host "Enter VM Name"
 
 
# Find the job that has our VM
$job = Get-VBRJob | ?{$_.Name -eq $jobName}
 
# Get all objects in job apart from our target VM
$execObjs = $job.GetObjectsInJob() | ?{$_.Name -ne $vmName}
 
# Exclude the objects from the job
Remove-VBRJobObject -Objects $execObjs
 
# Start the job only backing up the target VM
$runJob = Start-VBRJob -Job $job
 
# Find the exclude job objects
$incObjs = $job.GetObjectsInJob() | ?{$_.Type -eq "Exclude"}
 
# Delete the exclude objects and re-add to job
foreach ($obj in $incObjs) {
try {
    if ($obj.info.platform.platform -eq 'EHyperV') {
    $Excitem = Find-VBRHvEntity -Name $obj.Name
    Add-VBRHvJobObject -job $Job -Entities $Excitem | Out-Null
    $obj.Delete()
    } elseif ($obj.info.platform.platform -eq 'EVmware') {
    $Excitem = Find-VBRViEntity -Name $obj.Name
    Add-VBRViJobObject -job $Job -Entities $Excitem | Out-Null
    $obj.Delete()
    } else {
    Write-Error "This script does not support the entity type $($obj.info.platform.platform)"
    }
    } catch {
    $error[0]
    } #catch
}
$ErrorActionPreference = 'SilentlyContinue'
Write-Host "`nBackup Complete"

mrholm
Enthusiast
Posts: 61
Liked: 4 times
Joined: Apr 20, 2018 8:12 am
Full Name: Mats Holm
Contact:

[MERGED] Script to only run one VM in a job

Post by mrholm » Aug 28, 2018 1:02 pm

Hi
I have an old script from this forum that worked before (not sure what version of Veeam) but now with 9.5 it doesn't work anymore.

The script works fine until it should delete excluded objects and then re-add those objects to the job in the section "#* Delete the exclude objects and re-add to job"
The script looks like this:

#* Load Veeam snapin
Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

#* User Input
$jobName = Read-Host "Enter Job Name"
$vmName = Read-Host "Enter VM Name"


#* Find the job that has our VM
$job = Get-VBRJob | ?{$_.Name -eq $jobName}

#* Get all objects in job apart from our target VM
$execObjs = $job.GetObjectsInJob() | ?{$_.Name -ne $vmName}

#* Exclude the objects from the job(*Note: this isn't removing the objects
#* from the job)
Remove-VBRJobObject -Objects $execObjs

#* Start the job only backing up the target VM
Start-VBRJob -Job $job

#* Find the exclude job objects
$incObjs = $job.GetObjectsInJob() | ?{$_.Type -eq "Exclude"}

#* Delete the exclude objects and re-add to job
foreach ($obj in $incObjs) {
Excitem = $obj.GetObject().GetItem()
Add-VBRViJobObject -job $Job -Entities $Excitem
$obj.Delete() | Out-Null
}


The error I get is:

Method invocation failed because [Veeam.Backup.Core.CHierarchyObj] does not contain a method named 'GetItem'.
At C:\Veeam_Scripts\test1.ps1:27 char:4
+ $Excitem = $obj.GetObject().GetItem()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound


Anyone with knowledge that can share som light on how to do this?

Regnor
Service Provider
Posts: 322
Liked: 62 times
Joined: Jan 31, 2011 11:17 am
Full Name: Max
Contact:

Re: Script to only run one VM in a job

Post by Regnor » Aug 31, 2018 6:48 pm

Wouldn't a quick backup be much easier?

https://helpcenter.veeam.com/docs/backu ... tml?ver=95

veremin
Product Manager
Posts: 16901
Liked: 1440 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: backup single VM (not all VMs) within job?

Post by veremin » Sep 03, 2018 5:29 pm

If quick backup does not work for some reason, check suggestions above. Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests