PowerShell script exchange
Post Reply
spp
Novice
Posts: 8
Liked: never
Joined: Dec 16, 2011 10:18 am
Full Name: Sorin Pop
Contact:

Declare a Backup Repository on Linux

Post by spp »

Hello.

I'm trying to add a Linux server with Powershell in v6, to make it host a Backup Repository Server.

Code: Select all

# add the Linux server
$secpasswd = ConvertTo-SecureString "pass" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("account", $secpasswd)
$srv=Add-VBRLinux -Name devspp -SSHUser root -SSHPassword "root_pass" -Credential $mycreds

# declare the new backup repository on the Linux server
$mntsrv=get-vbrserver | where {$_.Name -eq "This server"}
Add-VBRBackupRepository -Name "devspp_bkp_repo" -Server $srv -MountServer $mntsrv -Folder "/synerway/applishare/vmware_ultimate" -Type "LinuxLocal"

The "account" I'll use is a service account, not root, and I need to set the ElevateRoot and AutoSudo properties of the Linux server to "true".
To retrieve their values, I can use "$srv.GetSSHCreds()" on a VBRServer object.

Is there a way to set those properties with the SSH credentials?


Thanx a lot.
Sorin Pop.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Declare a Backup Repository on Linux

Post by ThomasMc »

I can't test this but would this work?

Code: Select all

$srv = Add-VBRLinux -Name "devspp" -SSHUser "ServiceAccount" -SSHPassword "SAPASSWORD"
$vbrServer = Get-VBRServer -Name "devspp"
$creds = $vbrServer.getsshcreds()

$creds.ElevateToRoot = $true
$creds.EncryptedRootPassword = $mycreds
$vbrServer.SetCredentials($creds)
My assumptions are that you connect to ssh via this service account and elevating to root
spp
Novice
Posts: 8
Liked: never
Joined: Dec 16, 2011 10:18 am
Full Name: Sorin Pop
Contact:

Re: Declare a Backup Repository on Linux

Post by spp »

Hello.

Thank you Thomas for your answer.
I will try to be more accurate.

I need to connect to a Linux server using ssh with this "service" account, so I have to elevate it to root and force the autosudo.

Actually, I'm trying to reproduce in Powershell this settings:

Image

Those PS cmdlets were supposed to give me that.

I also tried your idea:

Code: Select all

$srv=get-vbrserver | where {$_.Name -eq "spp4"}
$creds=$srv.getSSHCreds()
$creds.ElevateRoot=$true
$creds.AutoSudo=$true
$srv.setcredentials($creds)
and the result was a typecast error:

Code: Select all

Impossible de convertir l'argument « 0 » (valeur « Veeam.Backup.Model.CDBSshCreds ») de « SetCredentials » en type « Veeam.Backup.Common.CCredentials » : « Impossible de convertir la valeur « Veeam.Backup.Model.CDBSshCreds » du type « Ve
eam.Backup.Model.CDBSshCreds » en type « Veeam.Backup.Common.CCredentials ». »
Au niveau de C:\spp\scripts\add_linux_server.ps1 : 33 Caractère : 20
+ $srv.setcredentials <<<< ($creds)
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
What can I do?

Thanx again.

Sorin
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Declare a Backup Repository on Linux

Post by ThomasMc »

Well I've had a good dig about and I have came to the conclusion that;

1) The Add-VBRLinux doesn't behave
2) Someone left out UpdateSshCreds

Code: Select all

Add-VBRLinux -Name "LinuxServer" -SSHUser "ServiceUser" -SSHPassword "SApassword"

$vbrServer = Get-VBRServer -Name "LinuxServer"
$creds = $vbrServer.getsshcreds()
$creds.ElevateRoot = $true
$creds.RootPassword = "RootPassword"

$Manager = [Veeam.Backup.DBManager.CDBManager]::Instance
$Manager.Host.UpdateSshCreds($creds)
Had to look back at a example from Seth to get this one :D
spp
Novice
Posts: 8
Liked: never
Joined: Dec 16, 2011 10:18 am
Full Name: Sorin Pop
Contact:

Re: Declare a Backup Repository on Linux

Post by spp »

Hello,

Thank you, Thomas, nicely done, it works like a heart!
Pretty tricky though!

Thanks again.

Sorin
Post Reply

Who is online

Users browsing this forum: masahide.k and 14 guests