PowerShell script exchange
Post Reply
Mental_floss
Novice
Posts: 3
Liked: never
Joined: Apr 05, 2019 3:58 pm
Full Name: John Doe
Contact:

Scripting volume level backup jobs with Linux agent

Post by Mental_floss »

I am running 9.3 U4a at a retailer with 200+ stores and I am looking to deploy Veeam with PowerShell. I have it 99% figured out except for the Linux backup job.

There is a Windows and Linux protection group at each location. When creating the Windows backup job I am able to use Add-VBRComputerBackupJob with the switches -BackupType SelectedVolumes -SelectedVolumes "C:\","D:\" to only backup C: and D: on all VMS in that Protection Group. With the Linux VMs I only want to backup volume groups VG00 and VG01. I use the switches -BackupType SelectedVolumes -SelectedVolumes "/dev/vg00","/dev/vg01" and the job fails with:

Code: Select all

Add-VBRComputerBackupJob : The specified computer backup job is invalid.
Source:
Job and SelectedVolumes OS platform mismatch
At line:1 char:1
+ Add-VBRComputerBackupJob -OSPlatform Linux -Type Server -Mode Managed ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-VBRComputerBackupJob], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Veeam.Backup.PowerShell.Cmdlets.AddVBRComputerBackupJob 
Help? TIA.
PTide
Product Manager
Posts: 6408
Liked: 724 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by PTide »

Hi,

While I am awaiting for some response regarding why is it not working from the team, I want to ask you a question:

Have you tried going with "-BackupType EntireComputer"?

Thanks!
jhoughes
Veeam Vanguard
Posts: 279
Liked: 112 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Castle Rock, CO
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by jhoughes »

Can you post your full script, or at least the full portion for the Linux agent jobs?
Husband, Father, Solutions Architect, Geek Extraordinaire | @DenverVMUG, @AustinVMUG & @ATXPowerShell leader | VMware vExpert | Cisco Champion
Mental_floss
Novice
Posts: 3
Liked: never
Joined: Apr 05, 2019 3:58 pm
Full Name: John Doe
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by Mental_floss »

P.Tide, yes if I create the Linux backup job with -BackupType EntireComputer the job is created and runs successfully.

jhoughes Here is the line I use to create the Linux backup job with "-BackupType EntireComputer". With this the job is created and it runs fine;

Add-VBRComputerBackupJob -OSPlatform Linux -Type Server -Mode ManagedByBackupServer -Name ($StoreNumber + "-LB") -BackupObject $LPG -BackupType EntireComputer -BackupRepository $VBRRepo -RetentionPolicy 14 -Description " " -ScheduleOptions $LBschedule -EnableSchedule

This line is where I create a backup of the Windows Protection Group to backup C: and D: only, works fine;

Add-VBRComputerBackupJob -OSPlatform Windows -Type Server -Mode ManagedByBackupServer -Name ($StoreNumber + "-WB") -BackupObject $WPG -BackupType SelectedVolumes -SelectedVolumes "C:\","D:\" -BackupRepository $VBRRepo -RetentionPolicy 14 -Description " " -ScheduleOptions $WBschedule -EnableSchedule

So what I was thinking should work to backup only VG00 and VG01 would be this;

Add-VBRComputerBackupJob -OSPlatform Linux -Type Server -Mode ManagedByBackupServer -Name ($StoreNumber + "-LB") -BackupObject $LPG -BackupType SelectedVolumes -SelectedVolumes "/dev/vg00","/dev/vg01" -BackupRepository $VBRRepo -RetentionPolicy 14 -Description " " -ScheduleOptions $LBschedule -EnableSchedule

Any attempt to use the "-BackupType SelectedVolumes" with Linux jobs gets me the OS Mismatch error. The documentation I am looking at only shows three options for -BackupType: EntireComputer, SelectedVolumes and SelectedFiles. Is Add-VBRComputerBackup the proper command to use to create a Linux agent backup job?
PTide
Product Manager
Posts: 6408
Liked: 724 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by PTide »

Hi,

You should use New-VBRLinuxSelectedVolume and do something like this:

Code: Select all

$scope = New-VBRLinuxSelectedVolume -Type Device -Path "/dev/sda"
and pass that $scope to -SelectedVolumes

For multiple devices you need to create an pass an array:

Code: Select all

-SelectedVolumes @((New-VBRLinuxSelectedVolume -Type Device -Path "/dev/sda"), (New-VBRLinuxSelectedVolume -Type Device -Path "/dev/sdb"))
Thanks
Mental_floss
Novice
Posts: 3
Liked: never
Joined: Apr 05, 2019 3:58 pm
Full Name: John Doe
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by Mental_floss »

P.Tide, THANK YOU! That was a yuuuuuge help.
jarzi
Service Provider
Posts: 22
Liked: 3 times
Joined: Aug 29, 2016 1:57 pm
Full Name: Jarno Arajärvi
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by jarzi »

Hi,

an old thread but I hit a snag trying to script a backup selecting multiple volumes.

Tried it like this

Code: Select all

$volumes = $(Read-host "Included mount points. IE. /,/home.") 

Code: Select all

-BackupType SelectedVolumes -SelectedVolumes @(foreach ($element in $volumes) {new-VBRLinuxSelectedVolume -type mountpoint -path $element })
The end result was that "objects to backup" page had the mount point like this:

Code: Select all

/,/home
And that doesn't work
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by oleg.feoktistov »

Hi Jarno,

What is the purpose of writing it like this?

Code: Select all

$volumes = $(Read-host "Included mount points. IE. /,/home.") 
And why did you specified /,/home ?

Thanks,
Oleg
jarzi
Service Provider
Posts: 22
Liked: 3 times
Joined: Aug 29, 2016 1:57 pm
Full Name: Jarno Arajärvi
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by jarzi »

What is the purpose of writing it like this?
That allows the one running the script decide what mount points will be selected. We have lot of servers where database mount needs to be excluded and AFAIK it's impossible to exclude a mount point from full server backup.
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by oleg.feoktistov »

Hi,

Can you, please, share the rest of the code?

Thanks,
Oleg
jarzi
Service Provider
Posts: 22
Liked: 3 times
Joined: Aug 29, 2016 1:57 pm
Full Name: Jarno Arajärvi
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by jarzi »

Here you go

Code: Select all

#Disclaimer
Write-host "this script will create a protection group, add server to it, create backup job and copy job and add the servers IP to the NSX firewall rule."
Write-Host "Work in progress. You need to manually adit the backup job mountpoints for Linux servers"

Add-PSSnapin VeeamPSSnapin
Import-Module powernsx

#Check if we have connection to backup server
$backup02 = get-VBRServer
if (!$backup02) {
    $vbrcred = get-credential
    Connect-VBRServer -credential $vbrcred -server backup.dom.local

}

# User input variables
$os = $(Read-Host "Linux | windows ?")
$protectionGroupName = $(read-host "Protection group name. This will be the job name as well")
$ips = $(Read-host "IP. x.x.x.x")
$retention = $(Read-host "Backup retention in days")
$time = $(Read-host "Schedule start time")

#Set repo
$repository = Get-VBRBackupRepository -name backup02 -scaleout

if ($os -eq 'Linux'){
$volumes = $(Read-host "Included mount points. IE. /,/home.")
$destination = New-VBRComputerDestinationOptions -OSPlatform Linux -BackupRepository $repository

 } else {
$destination = New-VBRComputerDestinationOptions -OSPlatform Windows -BackupRepository $repository  
 }

#Add IP to NSX ipset
$nsxip = $(Read-host "Add IP to NSX? y|n ")
if ($nsxip -eq 'y'){
$nsxcred = get-credential -credential $env:UserName
connect-nsxserver -vcenter vcenter -credential $nsxcred
get-nsxipset -Name veeam-backup-clients | Add-NsxIpSetMember -IPAddress $ips
}

#Static variables
$rescanPolicyType = "daily" 
$rescanTime = "20:00"
$newComputers = @($ips)
$daily = New-VBRDailyOptions -Type Everyday -Period $time
$schedule = New-VBRServerScheduleOptions -Type Daily -DailyOptions $daily
$storage = New-VBRStorageOptions -CompressionLevel Optimal -StorageOptimizationType LANTarget
$notification = New-VBRNotificationOptions -EnableAdditionalNotification -AdditionalAddress servicedesk@company.com
$date = Get-Date -Format "dd/MM/yyyy"
$description = "Job created by $env:UserName, date: $date, $retention days"

# function definition for creating protection group
function NewProtectionGroup($protectionGroupName, $newComputers, $rescanTime, $rescanPolicyType, $rescanPeriod, $rebootComputer) {
  Write-Host -foreground yellow "Enter credentials for computers in protection group " $protectionGroupName
  $creds = Get-Credential -message "Server admin credentials for $protectionGroupName"
  $newCreds = Add-VBRCredentials -Credential $creds -Description "powershell added creds for $protectionGroupName" -Type $os
  $newComputersCreds = $newComputers | ForEach { New-VBRIndividualComputerCustomCredentials -HostName $_ -Credentials $newCreds}
  $newContainer = New-VBRIndividualComputerContainer -CustomCredentials $newComputersCreds
 
  $dailyOptions = New-VBRDailyOptions -Type Everyday -Period $rescanTime
  $scanSchedule = New-VBRProtectionGroupScheduleOptions -PolicyType Daily -DailyOptions  $dailyOptions
 
  $dailyOptions = New-VBRDailyOptions -Type Everyday -Period $rescanTime
  $scanSchedule = New-VBRProtectionGroupScheduleOptions -PolicyType Daily -DailyOptions  $dailyOptions

  $deployment = New-VBRProtectionGroupDeploymentOptions -InstallAgent -UpgradeAutomatically

  $protectionGroup = Add-VBRProtectionGroup -Name $protectionGroupName -Container $newContainer -ScheduleOptions $scanSchedule -DeploymentOptions $deployment
}

# Create protection group
if (Get-VBRProtectionGroup -Name $protectionGroupName -ErrorAction SilentlyContinue) {
 Write-Host -foreground red "Protection group:" $protectionGroupName "already exists. Use another name for protection group."
} else {
 NewProtectionGroup -protectionGroupName $protectionGroupName -newComputers $newComputers -rescanTime $rescanTime -rescanPolicyType $rescanPolicyType
}

#Define protectiongroup for install command
$object = Get-VBRProtectionGroup -Name $protectionGroupName

# Create backup job
if ($os -eq 'Linux'){
#How to define correct mountpoints? This doesn't work @(foreach ($element in $volumes) {new-VBRLinuxSelectedVolume -type mountpoint -path $element })
Add-VBRComputerBackupJob -OSPlatform Linux -Type Server -Mode ManagedByBackupServer -Name $protectionGroupName -BackupRepository $repository -BackupObject $object -BackupType SelectedVolumes -SelectedVolumes  @(foreach ($element in $volumes) {new-VBRLinuxSelectedVolume -type mountpoint -path $element }) -DestinationOptions $destination -ScheduleOptions $schedule -EnableSchedule -RetentionPolicy $retention -NotificationOptions $notification -StorageOptions $storage -Description $description 
$job = get-vbrbackup -name $protectionGroupName
$copydescription = "Job created by $env:UserName, date: $date"
Copy-VBRJob -job aaa-copy-template-linux -name Copy_$protectionGroupName -repository copy01 -description $copydescription
}
else {
 Add-VBRComputerBackupJob -OSPlatform Windows -Type Server -Mode ManagedByBackupServer -Name $protectionGroupName -BackupRepository $repository -BackupObject $object -BackupType EntireComputer -DestinationOptions $destination -ScheduleOptions $schedule -EnableSchedule -RetentionPolicy $retention -NotificationOptions $notification -StorageOptions $storage -Description $description    
$job = get-vbrbackup -name $protectionGroupName
$copydescription = "Job created by $env:UserName, date: $date"
Copy-VBRJob -job aaa-copy-template-windows -name Copy_$protectionGroupName -repository copy01 -description $copydescription
}
#Create and enable copyjob
$copyjob = get-vbrjob -Name Copy_$protectionGroupName
enable-vbrjob -Job $copyjob
oleg.feoktistov
Veeam Software
Posts: 1912
Liked: 635 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by oleg.feoktistov » 1 person likes this post

Hi,

You need to call split() method on $volumes variable right after value assignment with a separator specified as powershell cannot deconstruct a value of "string" type into an array of elements inside foreach loop automatically if multiple mount points chosen.
In your case, as per the Read-Host statement, "," would work as a separator:

Code: Select all

$volumes = $(Read-Host "Included mount points. IE. /,/home.")
$volumes = $volumes.split(",")
Kind regards,
Oleg
jarzi
Service Provider
Posts: 22
Liked: 3 times
Joined: Aug 29, 2016 1:57 pm
Full Name: Jarno Arajärvi
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by jarzi »

Cheers, I'll try that.
jarzi
Service Provider
Posts: 22
Liked: 3 times
Joined: Aug 29, 2016 1:57 pm
Full Name: Jarno Arajärvi
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by jarzi »

Thanks Oleg, that worked :)
Post Reply

Who is online

Users browsing this forum: Baidu [Spider] and 15 guests