Standalone backup agent for Microsoft Windows servers and workstations (formerly Veeam Endpoint Backup FREE)
Post Reply
apronk
Enthusiast
Posts: 76
Liked: 9 times
Joined: Mar 23, 2015 2:47 pm
Full Name: Arend Pronk
Contact:

Veeam Agent Job Configuration Commandline

Post by apronk »

Hello,

I find myself needing an option to read from either registry or commandline that a Backup Job is configured and/or not Jobs are configured.
When deploying the Agent for Windows I need to find out wether or not I need to import a backup job for the Agent.
The result codes are not sufficient since ExitCode: 50 could mean Job Already Exists or Configuration Not Correct.

With regards,

Arend
HannesK
Product Manager
Posts: 14287
Liked: 2877 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: Veeam Agent Job Configuration Commandline

Post by HannesK »

Hello,
the configuration is stored in SQL Express Local DB. If you build something that queries the database, please be aware that this will break with the next major upgrade (V6).

I ask myself, whether it is needed to apply the jobs manually / scripted. With protection groups with pre-installed agents, the agent is doing that automatically.

Best regards,
Hannes
apronk
Enthusiast
Posts: 76
Liked: 9 times
Joined: Mar 23, 2015 2:47 pm
Full Name: Arend Pronk
Contact:

Re: Veeam Agent Job Configuration Commandline

Post by apronk »

Hi Hannes,

As I use a custom deployment system to install and upgrade the Veeam Agents, I need to know wether or not a job is already configured.
The System only checks if the version of Veeam Agent it is deploying is installed or not. So it does not check for previous versions.
So, as a task sequence it will check if there is a Backup Job configuration available for this machine at the repository and then imports this job.
So I need to add logic to see if it needs to do this or not, simply said to know wether or not a Veeam Agent already has a Job configured or not.

With regards,

Arend
HannesK
Product Manager
Posts: 14287
Liked: 2877 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: Veeam Agent Job Configuration Commandline

Post by HannesK »

Hello,
then the option via database should work, but it will break soon as mentioned earlier.
The result codes are not sufficient since ExitCode: 50 could mean Job Already Exists or Configuration Not Correct.
which command is this comment about? I was thinking whether it might be easier to check the export of the configuration.

Best regards,
Hannes
apronk
Enthusiast
Posts: 76
Liked: 9 times
Joined: Mar 23, 2015 2:47 pm
Full Name: Arend Pronk
Contact:

Re: Veeam Agent Job Configuration Commandline

Post by apronk »

Nevermind, I just wrote the code for Powershell to figure it out. It was faster than waiting for something that would never seem to happen.

Code: Select all

$objConnection = New-Object System.Data.SqlClient.SqlConnection
$objConnection.ConnectionString = "Data Source=(localdb)\VeeamEndPoint;Connection Timeout=5;Integrated Security=true"
$objConnection.Open()
$objCommand = New-Object System.Data.SqlClient.SqlCommand
$objCommand.Connection = $objConnection
$objCommand.CommandText = "Select name from VeeamBackup.dbo.BJobs"
$objCommand.CommandTimeout = 0
$objAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$objAdapter.SelectCommand = $objCommand 
$objDataSet = New-Object System.Data.DataSet
$objAdapter.Fill($objDataSet) | Out-Null
$objConnection.Close()
$objResult = $objDataSet.Tables
$objResult.Name
This code must run using the "NT Authority\SYSTEM" user, else the Data Source is not found.
HannesK
Product Manager
Posts: 14287
Liked: 2877 times
Joined: Sep 01, 2014 11:46 am
Full Name: Hannes Kasparick
Location: Austria
Contact:

Re: Veeam Agent Job Configuration Commandline

Post by HannesK »

thanks for sharing with the community. for V6 it's probably similar, just SQLite instead of MS SQL
apronk
Enthusiast
Posts: 76
Liked: 9 times
Joined: Mar 23, 2015 2:47 pm
Full Name: Arend Pronk
Contact:

Re: Veeam Agent Job Configuration Commandline

Post by apronk »

Code: Select all

$objConnection = New-Object System.Data.SqlClient.SqlConnection
$objConnection.ConnectionString = "Data Source=(localdb)\VeeamEndPoint;Connection Timeout=5;Integrated Security=true"
Try { $objConnection.Open() }
Catch { return 9999 }
If ($objConnection.State -eq "Open") {
  $objCommand = New-Object System.Data.SqlClient.SqlCommand
  $objCommand.Connection = $objConnection
  $objCommand.CommandText = "Select name from VeeamBackup.dbo.BJobs"
  $objCommand.CommandTimeout = 0
  $objAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  $objAdapter.SelectCommand = $objCommand 
  $objDataSet = New-Object System.Data.DataSet
  $objAdapter.Fill($objDataSet) | Out-Null
  $objConnection.Close()
}
$objResult = $objDataSet.Tables
If ($objResult.Name) { return 1 } Else { return 0 }
Fixed a logical error and made it more reliable.
Return codes:
0 = No Jobs Found
1 = 1 Job Found
9999 = Could not connect (Not running as SYSTEM)
apronk
Enthusiast
Posts: 76
Liked: 9 times
Joined: Mar 23, 2015 2:47 pm
Full Name: Arend Pronk
Contact:

Re: Veeam Agent Job Configuration Commandline

Post by apronk » 1 person likes this post

And here is the code for Veeam Agent 6 using SQLite:

Code: Select all

$strSQlitePath = '{0}\Veeam\Endpoint Backup\System.Data.SQLite.dll' -f $env:ProgramFiles
$strSqliteDB = '{0}\Veeam\EndpointData\VeeamBackup.db' -f $env:ProgramData
If (((Test-Path -Path $strSQlitePath) -eq $true) -and ((Test-Path -Path $strSQlitePath) -eq $true)) {
  $null = Add-Type -Path $strSQlitePath
  $strDBConnectionString = [string]::Format('Data Source={0}',$strSqliteDB)
  $objSQLiteConnection = New-Object -TypeName System.Data.SQLite.SQLiteConnection
  $objSQLiteConnection.ConnectionString = $strDBConnectionString
  $objSQLiteConnection.Open()
  $objSQLiteDBCommand = $objSQLiteConnection.CreateCommand()
  $objSQLiteDBCommand.CommandText = 'Select Name from BJobs'
  $objSQLiteDBCommand.CommandType = [System.Data.CommandType]::Text
  $strJob = $objSQLiteDBCommand.ExecuteScalar()
  Write-Host $strJob
  $objSQLiteDBCommand.Dispose()
  $objSQLiteConnection.Close()
}
Post Reply

Who is online

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