Automation can start small: PowerShell jobs creation


Userlevel 7
Badge +10

I’ll be the first to admit that I’m not an automation expert. That being said, I also like to start small, and one area I’d think is a good area for many is PowerShell. For Veeam Backup & Replication, I’d like to draw your attention to the PowerShell User Guide: https://helpcenter.veeam.com/docs/backup/powershell/getting_started.html?ver=110

 

This is a great place to start with PowerShell and for a small task like creating jobs, it’s so easy even Rick Vanover can do it. Take for example this 5-line PowerShell script:

 

$repository = Get-VBRBackupRepository -Name "NAS"

$TagsOnlyWayToGo = Find-VBRViEntity -Name "fwu-Engineering" -Tags

Add-VBRViBackupJob -Name "__FWU Backup - Engineering" -BackupRepository $repository -Entity $TagsOnlyWayToGo -Description "Provider level backup job of Engineering - 24h RPO"

Set-VBRJobSchedule -Job "__FWU Backup - Engineering" -Periodicaly -FullPeriod 24 -PeriodicallyKind Hours

Enable-VBRJobSchedule -Job "__FWU Backup - Engineering"

 

You also may have/want to add this string to get PowerShell going:

Add-PSSnapin VeeamPSSnapin
Connect-VBRServer 

 

Once your session is active, the simple 5-line script will create a job, let me walk through each line:

$repository = Get-VBRBackupRepository -Name "NAS"

I have a pre-defined backup repository called “NAS” and this is the target for my backup job to go to.

 

$TagsOnlyWayToGo = Find-VBRViEntity -Name "fwu-Engineering" -Tags

 

I may be a bit boasty, indicating that for this VMware backup job - vSphere Tags are the only way to go and I’m adding to the job a tag type called “fwu-Engineering” and any VM or other object tagged with that will be put in the job. Easy-peasy.

Add-VBRViBackupJob -Name "__FWU Backup - Engineering" -BackupRepository $repository -Entity $TagsOnlyWayToGo -Description "Provider level backup job of Engineering - 24h RPO"

I gave the job a name here, and a description. Use the descriptions here, makes troubleshooting a bit easier later.

Set-VBRJobSchedule -Job "__FWU Backup - Engineering" -Periodicaly -FullPeriod 24 -PeriodicallyKind Hours

I am not too particular on the job other than I want it to run every 24 hours; and I set that here.

Enable-VBRJobSchedule -Job "__FWU Backup - Engineering"

Enable the job and go!

 

I have done a few demos where I was able to quickly onboard backups for a number of different tags, one job per tag quite easily. I like PowerShell job creation as it can ensure they are consistently done and is a quick and easy way to do it. 

Like I said - I’m no Automation Guru but the beauty about Veeam here is you can start small, as simple as jobs and build on that. Let me know if you’ve ever done a PowerShell job creation.


10 comments

Userlevel 7
Badge +14

Would you look at that, Mr. RICKATRON doing automation! 

 

Thank you for sharing this post and the explanation for the steps

Userlevel 7
Badge +10

Would you look at that, Mr. RICKATRON doing automation! 

 

Thank you for sharing this post and the explanation for the steps

I try man. I admire what you do @mkevenaar in this area! I can only go up from here.

Userlevel 6
Badge +2

Yes, this is one of the strength and reason why Veeam is better at the automation, it has the PowerShell commands to do some stuff not just reporting :-)

 

Thanks @Rick Vanover for sharing the info here.

Userlevel 7
Badge +14

Would you look at that, Mr. RICKATRON doing automation! 

 

Thank you for sharing this post and the explanation for the steps

I try man. I admire what you do @mkevenaar in this area! I can only go up from here.

No! Try not! Do or do not, there is no try. - Yoda

 

Userlevel 7
Badge +22

Would you look at that, Mr. RICKATRON doing automation! 

 

Thank you for sharing this post and the explanation for the steps

He has shamed me into action :)> I am going to start the Ansible course at KodeKloud now which was originally further down my list! 

Userlevel 7
Badge +20

Always love PowerShell for doing many things.  With Veeam it works great to change settings and like this create a job. Going to get more in to this and hopefully post back here with some things. 👍

Userlevel 4
Badge +3

Also have a look at this project: https://github.com/vMarkusK/VeeamJobConfig

I used this for Mass Configuration from Reference Job.

Userlevel 7
Badge +20

Also have a look at this project: https://github.com/vMarkusK/VeeamJobConfig

I used this for Mass Configuration from Reference Job.

That is very cool and I will be checking that out for some possible automation. 😎

Userlevel 4
Badge +2

Not to just tag on to your content Rick, but I may have seen someone perform a demo or 2 around this before also.  😉

I covered this in my VeeamON 2020 session video along with some explanation, for those who want to watch and follow along:

Script: NewBackupShellJob.ps1 (GitHub)
Video: 



Also, if anyone needs to be able to run some quick job comparisons by selecting a job to be your reference point, check out these scripts I wrote for VeeamON 2020 demos:

Get-VeeamJobConfiguration.ps1 (GitHub)

Run-VeeamJobComparison.ps1 (GitHub)

 

If you want to see the video on how to use these scripts separately or in a pipeline, along with some quick background on advance functions check here:
 


Cheers, hope it helps someone out.

Userlevel 7
Badge +20

Thanks for sharing those, Joe.  Always good to have automation content available.  😁

Comment