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 » Apr 05, 2019 4:09 pm

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: 5465
Liked: 498 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by PTide » Apr 05, 2019 6:14 pm

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 Software
Posts: 157
Liked: 46 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by jhoughes » Apr 05, 2019 7:07 pm

Can you post your full script, or at least the full portion for the Linux agent jobs?
Husband, Father, Solutions Architect, Geek Extraordinaire | @AustinVMUG & @ATXPowerShell leader | VMUG US South Regional Champion | 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 » Apr 19, 2019 2:50 pm

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: 5465
Liked: 498 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Scripting volume level backup jobs with Linux agent

Post by PTide » Apr 23, 2019 6:12 pm

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 » Apr 30, 2019 5:21 pm

P.Tide, THANK YOU! That was a yuuuuuge help.

jarzi
Service Provider
Posts: 13
Liked: 2 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 » Feb 16, 2020 6:14 am

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: 224
Liked: 71 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 » Feb 16, 2020 9:30 am

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: 13
Liked: 2 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 » Feb 17, 2020 6:00 am

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: 224
Liked: 71 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 » Feb 18, 2020 11:42 am

Hi,

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

Thanks,
Oleg

jarzi
Service Provider
Posts: 13
Liked: 2 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 » Feb 18, 2020 2:44 pm

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: 224
Liked: 71 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 » Feb 19, 2020 1:30 pm 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: 13
Liked: 2 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 » Feb 19, 2020 2:00 pm

Cheers, I'll try that.

jarzi
Service Provider
Posts: 13
Liked: 2 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 » Feb 19, 2020 6:14 pm

Thanks Oleg, that worked :)

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests