Compacting and Full Backup list of schedule

PowerShell script exchange

Re: Compacting and Full Backup list of schedule

Veeam Logoby v.Eremin » Fri Mar 21, 2014 3:00 pm 1 person likes this post

Yes, currently it works like this:

1) Get current job settings.
2) Make changes to the settings.
3) Write changed settings to the job.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Compacting and Full Backup list of schedule

Veeam Logoby ehrnst » Mon Mar 24, 2014 8:34 am

I haven't testet it out in our lab yet, but it is good to know that we need to do it in that order. i don't like it, but at lease we can relate to it.
ehrnst
Enthusiast
 
Posts: 35
Liked: 1 time
Joined: Fri Jan 31, 2014 8:24 am
Full Name: Martin Ehrnst

Re: Compacting and Full Backup list of schedule

Veeam Logoby v.Eremin » Mon Mar 24, 2014 8:44 am

Yep, it works like that in the moment. In order to change some settings, you have to write them to the variable, make changes to the variable, and pass the changed settings (variable) to the entity.

Anyway, let me know if putting the said part into the cycle makes any difference.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Compacting and Full Backup list of schedule

Veeam Logoby ehrnst » Mon Mar 24, 2014 11:56 am

Putting the get.options inside the cycle did the trick. That is probably why i did not have any problems with the backup jobs. To clearify, scripts should look like this (modify to your needs)

Backup Copy:

Code: Select all
#Loop through backup copy jobs, and set Monthly compact schedule#
Add-PSSnapin VeeamPSSnapin #Load veeam snapin
#$CompanyCode = Read-Host "First letter in CopyJob" #User input for first letters in job
#$CompanyCode2 = Read-Host "First letter in CopyJob (second)"
$CopyJobs = Get-VBRJob | where {($_.jobtype -eq "BackupSync") -and ($_.Name -like "PutInNameOrUseVariable") -and ($_.IsScheduleEnabled -eq $true)} #Search for enabled jobs with imput from user
ForEach ($job in $CopyJobs)
    {
    $options = $job.getoptions() #get options
    $DayInMonth = ("First","Second","Fourth") | Get-Random #fill our variables for the day number in month will randomize
    $Day = ("Sunday","Tuesday") | Get-Random #fill inn for weekdays - will randomize
    $options.GenerationPolicy.CompactFullBackupMonthlyScheduleOptions.DayNumberInMonth = "$DayInMonth" #get the random day number first,second etc
    $options.GenerationPolicy.CompactFullBackupMonthlyScheduleOptions.DayOfWeek = "$Day" #get the random day Monday, Wednesday
    $Options.GenerationPolicy.EnableCompactFull = $True #enable compact schedule
    $job.SetOptions($options) #set options to copyjobs variable
    write-host "OK  "$job.Name "Compact full set" # list out the jobs and parameters set
    }
   


Backup:

Code: Select all
#Loop through backup jobs, and set Monthly active full backup#
Add-PSSnapin VeeamPSSnapin #Load veeam snapin
#$CompanyCode = Read-Host "First letter in BackupJob" #User input for first letters in job"
$BackupJobs = Get-VBRJob | where {($_.jobtype -eq "Backup") -and ($_.Name -like "PutInNameOrUseVariable") -and ($_.IsScheduleEnabled -eq $true)} #Search for enabled jobs with imput from user
$FullBackupMonth = "January","March", "May", "July","September","November" #Month's where you want active full backup to run 
   ForEach ($Object in $BackupJobs)
    {
    $Day = "Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday" | Get-Random #fill inn for weekdays - will randomize
    $DayNumber = "First", "Second", "Third", "Fourth" | get-random #fill inn for week day number - will randomize
    $options = $Object.getoptions() #get options
    $options.BackupStorageOptions.EnableFullBackup = $true
    $options.BackupTargetOptions.FullBackupMonthlyScheduleOptions.DayOfWeek = $Day #insert the random day Monday, Wednesday
    $options.BackupTargetOptions.FullBackupMonthlyScheduleOptions.DayNumberInMonth = $DayNumber #Inserts daynumber
    $options.BackupTargetOptions.FullBackupMonthlyScheduleOptions.Months = $FullBackupMonth #sets month's to perform backup
    $options.BackupTargetOptions.FullBackupScheduleKind = "Monthly" #Monthly Schedule
    $Object.SetOptions($options) #set options to Backupjobs variable
    write-host "OK  "$object.Name "Active Full Backup date set" # list out the jobs and parameters set
    }
ehrnst
Enthusiast
 
Posts: 35
Liked: 1 time
Joined: Fri Jan 31, 2014 8:24 am
Full Name: Martin Ehrnst

Re: Compacting and Full Backup list of schedule

Veeam Logoby ehrnst » Wed Mar 26, 2014 1:19 pm

Hello,

Just one question regarding this "problem" getting the options before modifying them. Let's say i would like to change the storage optimization for every job in our environment. From what i experienced with my scripts posted in this thread, i would just create a foreach loop and aquire the options for each job and set the optimization with something like this;

Code: Select all
BackupStorageOptions.StgBlockSize = "KbBlockSize1024"


But, what would happen if i use a one liner to do the job,

Code: Select all
Get-VBRJob | Set-VBRJobAdvancedStorageOptions -StorageBlockSize 3


From what i can understand, this will set the storage optimization to "Local Target" for all jobs, but will it reset all other options set, if not - why does the "script" approach do so when we do not use "getOptions" first. I would be great if you can explain all this to me (and probably others who wonder)

Thank you
ehrnst
Enthusiast
 
Posts: 35
Liked: 1 time
Joined: Fri Jan 31, 2014 8:24 am
Full Name: Martin Ehrnst

Re: Compacting and Full Backup list of schedule

Veeam Logoby v.Eremin » Wed Mar 26, 2014 1:36 pm

From what i can understand, this will set the storage optimization to "Local Target" for all jobs, but will it reset all other options set

Not, the said commandlet won't reset the other settings, because it has corresponding switch ("-StorageBlockSize") that limits scope of changes to the particular property. Meanwhile, GetOptions() and SetOptions() operate with options as the whole. Therefore, if you pass the pre-defined ("template") options to SetOptions(), the existing job options will be overwritten by them.

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Compacting and Full Backup list of schedule

Veeam Logoby ehrnst » Wed Mar 26, 2014 2:03 pm

Thank you. That made it clearer.

What if i specify $options like this, will it work?

Code: Select all
$options = $object.BackupStorageOptions.StgBlockSize = "KbBlockSize1024"
$Object.SetOptions($options)
ehrnst
Enthusiast
 
Posts: 35
Liked: 1 time
Joined: Fri Jan 31, 2014 8:24 am
Full Name: Martin Ehrnst

Re: Compacting and Full Backup list of schedule

Veeam Logoby v.Eremin » Wed Mar 26, 2014 2:22 pm 1 person likes this post

No, it won't because SetOptions() expects to receive CJobOptions object, whole you're trying to pass EKbBlockSize one to it. Thanks.
v.Eremin
Veeam Software
 
Posts: 13296
Liked: 973 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Previous

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 7 guests