PowerShell script exchange
Post Reply
Gribri
Novice
Posts: 3
Liked: 1 time
Joined: Apr 07, 2021 10:34 am
Contact:

Protection Group fails to be rescanned

Post by Gribri »

Case ID: #04833360
Hiya community

Situation

I'm working on a Powershell script to backup local files to a SMB share which will later be used to integrate it with Java. I'm using Veaam Backup and Replication (Standard).
I'm able to set up a repository, protection group and create a backup job.

Problem

When I start the backup job I first have to rescan/install the protection group which fails.
I get the following error messages:
  • When I am on my home Network I get: 28.05.2021 09:10:05 :: Unable to install backup agent: cannot connect to 192.168.1.46 Error: Der Netzwerkname wurde nicht gefunden. The network name cannot be found. (ERROR_BAD_NET_NAME).
  • When I am on my mobile phone hotspot: 28.05.2021 08:00:46 :: Unable to install backup agent: cannot connect to 192.168.43.180 Error: Der Benutzername oder das Kennwort ist falsch. (Username and Password are wrong)
What I tried so far
  • I've tried to create a protection group with the Veeam application. Same errors
  • I've tried all sorts of possible combinations I could think of: using different users with and without admin rights, using the ip or hostname etc.
  • I've searched the forum for similar problems. One solution I found which worked at some point was disabling LUA (UAC) but this shouldn't be a solution since it will expose the computer to security risks
  • I've tried testing the credentials I supply in the UI which seemed to work
  • Restarted my system a couple of times during the whole process
  • made sure SMB is enabled
  • other things I've tried but forgotten since I've started working on this script
Code

Create Repository

Code: Select all

function createSMBRepository($smbPath, $domain, $username, $password)
{
    if ($isInitialized -eq $true) #I initialize the PS and then store it in a value so I don't have to check every time
    {
        # Ensure Veeam Service is running 
        echo "Ensuring Veeam services are running..."
        $svc = Get-Service VeeamBackupSvc
        $svc.WaitForStatus('Running')
        Write-Progress -Activity "Waiting for Veeam services to start"

        echo "Creating SMB Repository...`n"

        # Create a regular VBR (Veeam Backup and Replication) Repository of type CifsShare
        Add-VBRBackupRepository -Name "SMB Repository" -UserName "$domain\$username" -Password "$password" -Folder "$smbPath" -Type CifsShare

        # Allow Access
        $repository = Get-VBRBackupRepository -Name "SMB Repository"
        Set-VBREPPermission -Repository $repository -Type Everyone

        echo "`n"
        echo "Repository has been created."
    }
    else
    {
        echo "ERROR: SMB Repository cannot be created because PowerShell is not initialized"
        exit 3
    }
}
Create a protection group

Code: Select all

function createProtectionGroup($username, $password, $domain)
{
    #check if the protection group already exists
    $error.Clear()
    try 
    {
        $potentialProtectionGroup = Get-VBRProtectionGroup -Name "Custom Protection Group"
    }
    catch
    {
        echo "No protection group exists yet. Creating one..."
    }

    if ($error)
    {
        # Register credentials and then save them in a variable $credentials
        Add-VBRCredentials -Type Windows -User "$domain\$username" -Password $password
        $credentials = Get-VBRCredentials -Name "$domain\$username"

        $computer = @("$domain") | ForEach { New-VBRIndividualComputerCustomCredentials -HostName $_ -Credentials "$domain\$username" } 

        $scope = New-VBRIndividualComputerContainer -CustomCredentials $computer

        # Create protection group
        Add-VBRProtectionGroup -Name "Custom Protection Group" -Container $scope

        # Get protection Group
        $protectionGroup = Get-VBRProtectionGroup -Name "Custom Protection Group"

        # Scan protection group
        Rescan-VBREntity -Entity $protectionGroup -Wait

        # Get discovered Computer
        $discoveredComputer = Get-VBRDiscoveredComputer -ProtectionGroup $protectionGroup

        # Install Agent
        Install-VBRDiscoveredComputerAgent -DiscoveredComputer $discoveredComputer
    }
}
Create backup Job

Code: Select all

function createBackupJob($selectedFiles, $username, $password, $domain)
{
    if ($global:isInitialized -eq $true)
    {
        # Create protection group (Scope of files that should be included)
        createProtectionGroup $username $password $domain

        # Get the created protection group
        $protectionGroup = Get-VBRProtectionGroup -Name "Custom Protection Group"

        $repository = Get-VBRBackupRepository -Name "SMB Repository"

        #TODO check if repository exists

        # Create SelectedFilesBackupOptions object
        $selectedFilesOptions = New-VBRSelectedFilesBackupOptions -OSPlatform Windows -BackupSelectedFiles -SelectedFiles "$selectedFiles"

        Add-VBRComputerBackupJob -Name "Custom Backup Job" -OSPlatform Windows -Type Server -Mode ManagedByBackupServer -BackupObject $protectionGroup -BackupType SelectedFiles -SelectedFilesOptions $selectedFilesOptions -BackupRepository $repository
    }
    else
    {
        echo "Powershell is not initialized."
    }
}
wishr
Veteran
Posts: 3077
Liked: 455 times
Joined: Aug 07, 2018 3:11 pm
Full Name: Fedor Maslov
Contact:

Re: Protection Group fails to be rescanned

Post by wishr » 1 person likes this post

Hi Gribri,
I've tried to create a protection group with the Veeam application. Same errors
Sounds like an environment-related issue. Our support team should be able to determine the root cause and help you eliminate it, so let's see what they will find out.

Thanks
oleg.feoktistov
Veeam Software
Posts: 2010
Liked: 670 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Protection Group fails to be rescanned

Post by oleg.feoktistov » 2 people like this post

Hi Gribri,

I do agree with Fedor. Tested your script for protection group creation/rescan and could reproduce the same issue in both Powershell and the UI: "The network path was not found. (ERROR_BAD_NET_NAME)." For me it was resolved after I turned on network discovery for the needed profile on the host I wanted to add to a protection group.

Thanks,
Oleg
Gribri
Novice
Posts: 3
Liked: 1 time
Joined: Apr 07, 2021 10:34 am
Contact:

Re: Protection Group fails to be rescanned

Post by Gribri » 1 person likes this post

Hiya both of you :)

Thank you for testing my script and reproducing the error. I think the Problem I encountered with the ERROR_BAD_NET_NAME was related to the network I was using at that time which was a guest network. Now that I am trying it from home again it has been resolved.
Sadly I still encounter the error where username/password are not accepted (not only on the mobile hotspot but on the regular network as well). I tried using different profiles with and without admin rights. Tried all the combinations of host, username & password I could think of. One "solution" is disabling LUA (UAC) which I won't do since it will disable an important security feature.

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests