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)
- 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
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
}
}
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
}
}
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."
}
}