PowerShell script exchange
Post Reply
FireExit
Novice
Posts: 9
Liked: 2 times
Joined: Nov 26, 2015 12:06 am
Contact:

Add Wasabi repository to VBR with PowerShell?

Post by FireExit »

Hi,

In Veeam B&R 12, the GUI wizard for "add backup repository" has separate options for "S3 Compatible" and "Wasabi Cloud Storage".
See the screenshot in the docs here: https://helpcenter.veeam.com/docs/backu ... ml?ver=120

(What's the difference between them?)

In Veeam for Microsoft 365, the cmdlet "Add-VBOAmazonS3CompatibleObjectStorageRepository" has a -Type option for WasabiCloud
See the docs here: https://helpcenter.veeam.com/docs/vbo36 ... tml?ver=70

In Veeam B&R, the cmdlet "Add-VBRAmazonS3CompatibleRepository" (VBR instead of VBO) doesn't have any mention of -Type, or Wasabi, and I can't find a cmdlet for Wasabi repositories.
See the docs here: https://helpcenter.veeam.com/docs/backu ... ml?ver=120

If I add it as S3 compatible, it comes up with a different icon.
Are there any other differences, does a Wasabi repository behave differently in any way?

Is there a way to script adding a Wasabi one?
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Add Wasabi repository to VBR with PowerShell?

Post by david.domask »

Hi @FireExit, as best I know we don't have a dedicated cmdlet for Wasabi like in the UI, and you would use instead Add-VBRAmazonS3CompatibleRepository: https://helpcenter.veeam.com/docs/backu ... ge&ver=120

The main difference as best I understand it is that the UI version will tweak a few things to be specific to Wasabi (like concurrent connections, concurrent tasks, etc), but I've not tested this on v12 to be honest, so take it with a grain of salt. It should work with the S3-Compatible, but it might be nice to have a flag for Powershell since we have a UI option specifically for Wasabi.

If possible, I'd recommend just manually setting the Wasabi ones for right now from the UI, and hopefully in future versions we'll have more flexibility on the scripting side.

If you're willing to use REST, the VBR API has the repositories endpoint and it has Wasabi: https://helpcenter.veeam.com/docs/backu ... Repository

So maybe you can mix in some REST requests into your script for now.
David Domask | Product Management: Principal Analyst
FireExit
Novice
Posts: 9
Liked: 2 times
Joined: Nov 26, 2015 12:06 am
Contact:

Re: Add Wasabi repository to VBR with PowerShell?

Post by FireExit » 1 person likes this post

Thank you @david.domask , that's very helpful!

I don't object to REST if it means not having to add dozens of repositories by hand.
For any Google people in future, here are roughly all the steps, using Veeam B&R 12, and beware of typos and gaps where I tried to remove company specific information:
  • In the Wasabi web portal, add a user with API access and get the secret keys.
  • Use the AWS PowerShell with Wasabi guide to go through PowerShell `Install-Module -Name AWS.Tools.Installer` and `Install-AWSToolsModule AWS.Tools.S3 -CleanUp` and `Set-AWSCredential` to save the keys in a profile.
  • Setup the Wasabi bucket for Veeam to use, assuming the UK and wanting backup immutability: `New-S3Bucket -BucketName "my-backup-bucket" -EndpointUrl "https://s3.eu-west-1.wasabisys.com" -ProfileName wasabi-saved-keys-profile -ObjectLockEnabledForBucket`
  • if you don't want the UK, update the region and endpoint using Wasabi Service URLS for different storage regions documentation.
  • In Veeam B&R Console, File -> Manage Cloud Credentials and add an entry with the Wasabi portal API user keys.
  • Switch to Veeam PowerShell and run `Get-VBRAmazonAccount` and find the ID of the Wasabi credentials you just added.
Then make a new folder in the bucket for Veeam to use, still in Veeam PowerShell:

Code: Select all

Connect-VBRServer -Server my-veeam-server
$wasabiAccount = Get-VBRAmazonAccount -Id "<the credentials ID you just found>"
$wasabiConnection = Connect-VBRAmazonS3CompatibleService -Account $wasabiAccount -CustomRegionId = "eu-west-1" -ServicePoint ="s3.eu-west-1.wasabisys.com" -ConnectionType Direct

$bucketName = "my-backup-bucket"
$bucket = Get-VBRAmazonS3Bucket -Connection $wasabiConnection -Name $bucketName
$folder = New-AmazonS3Folder -Connection $wasabiConnection -Bucket $bucket -Name 'backup'

Disconnect-VBRAmazonS3Service -Connection $wasabiConnection
If you don't mind using "S3 compatible" for your repository from PowerShell, then (note $folder carries over from the above code, it's not a string, and I think $folder is what connects the repository to the right bucket):

Code: Select all

$mountOptions = New-VBRRepositoryMountServerOptions -MountServer my-veeam-server.corp.example.com -MountFolder 'C:\ProgramData\Veeam\Backup\' -EnableVPowerNFS 
Add-VBRAmazonS3CompatibleRepository -Name "Wasabi-repo-example" -Description "Wasabi Cloud Storage" -AmazonS3Folder $folder -Connection $wasabiConnection -EnableBackupImmutability -ImmutabilityPeriod 7 -Verbose -MountServerOptions $mountOptions
That does add a repository, but I haven't tried using it. For the REST version to get a 'proper' Wasabi repository, I added a Wasabi repository into Veeam manually, then queried the REST API for it, pulled out the IDs for mount servers and credentials and proxy appliances and used those for the new one.

Code: Select all

$endPoint = 'https://my-veeam-server:9419'

# Enable TLS1.2 in PowerShell bodge
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols

# Ignore self-signed cert in PowerShell bodge
add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy


# Headers for all Veeam API calls
$GlobalHeaders = @{
    'x-api-version' = '1.1-rev0'
}

# Body for the login API call to get an access token
$authBody = @{
    grant_type = 'password'
    username   = '<your-veeam-username-here>'
    password   = '<your-veeam-password-here>'
} | ConvertTo-Json

$tokens = Invoke-RestMethod -Method Post -Uri "$endPoint/api/oauth2/token" -Headers $GlobalHeaders -ContentType "application/json" -Body $authBody

$GlobalHeaders['Authorization'] = "Bearer $($tokens.access_token)"


$newRepoDetails = [ordered]@{
    type =  'WasabiCloud'
    id =  [guid]::NewGuid().guid     # suspect this isn't required
    name =  'Wasabi-Repository'
    description =  'Storage on Wasabi S3 Cloud service'
    
    enableTaskLimit = $false
    maxTaskCount    =  -1
    
    account = @{
        regionId             = 'eu-west-1'
        credentialsId        = '<WASABI CREDENTIAL ID FROM VEEAM AGAIN HERE>'
        connectionSettings   = @{
            connectionType   = 'Direct'
        }
    }
    
    bucket = @{
        bucketName =  'my-backup-bucket'
        folderName =  'backup'
        storageConsumptionLimit  =  @{
            consumptionLimitKind =  'TB'
            isEnabled =  $false
            consumptionLimitCount =  10
        }

        immutability  =  @{
            isEnabled =  $true
            daysCount =  7
        }
    }

    mountServer =  @{
        mountServerId    =  '<UGH ANOTHER GUID HERE>'
        writeCacheFolder =  'C:\ProgramData\Veeam\Backup\'
        vPowerNFSEnabled =  $true
        vPowerNFSPortSettings =  @{
            mountPort     =  1063
            vPowerNFSPort =  2049
        }
    }

    proxyAppliance = @{
        managedServerId = '<MORE GUID HERE>'
    }
    
}


$newRepoBody = $newRepoDetails | ConvertTo-Json -Depth 99
Invoke-RestMethod -Method POST -Uri "$endPoint/api/v1/backupInfrastructure/repositories" -Headers $GlobalHeaders -ContentType "application/json" -Body $newRepoBody
david.domask
Veeam Software
Posts: 1226
Liked: 322 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: Add Wasabi repository to VBR with PowerShell?

Post by david.domask » 1 person likes this post

Hi @FireExit, very glad I could help and thank you very much for sharing your code, I am positive that many others will make great use of it :)
David Domask | Product Management: Principal Analyst
FireExit
Novice
Posts: 9
Liked: 2 times
Joined: Nov 26, 2015 12:06 am
Contact:

Re: Add Wasabi repository to VBR with PowerShell?

Post by FireExit » 1 person likes this post

Adding one more bit, to expand on this comment:

> I added a Wasabi repository into Veeam manually, then queried the REST API for it,

I copied all the auth code and changed the end to do a GET request to the "/repositories" endpoint with no body, converted the results back to JSON and into a text editor, and copied chunks out of that as the template:

Code: Select all

# <... auth code... >

$repos = Invoke-RestMethod -Method GET -Uri "$endPoint/api/v1/backupInfrastructure/repositories" -Headers $GlobalHeaders -ContentType "application/json"

$repos.data| ConvertTo-Json
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests