-
- Lurker
- Posts: 1
- Liked: never
- Joined: Aug 18, 2011 11:53 am
- Full Name: Mark Zigadlo
How to Update targetdir with Powershell
I have been looking for a way to update targetdir in my backup jobs with powershell.
Does anyone know where this can be done?
-Mark
Does anyone know where this can be done?
-Mark
-
- Chief Product Officer
- Posts: 31806
- Liked: 7300 times
- Joined: Jan 01, 2006 1:01 am
- Location: Baar, Switzerland
- Contact:
Re: How to Update targetdir with Powershell
Hi Mark, I am pretty sure this is possible, however you would still have to move backup files manually to the new location, or the job will cease functioning.
-
- Veteran
- Posts: 282
- Liked: 26 times
- Joined: Nov 10, 2010 6:51 pm
- Full Name: Seth Bartlett
- Contact:
Re: How to Update targetdir with Powershell
Here is the ridiculous code to do so, I have created a function called SetDir:
To call it, you will want to do SetDir "JobName" "Directory"
Code: Select all
Function SetDir
{
param ([string]$JobName, [string]$targetDir)
$job = Get-VBRJob | where-object {$_.name -eq $JobName}
$info = [Veeam.Backup.Model.CDbBackupJobInfo]::CreateExisting($job.id, $job.name, $job.description, $job.jobtargettype, $job.gettargethost().id, $targetDir, $job.info.targetfile, $job.info.options, $job.info.scheduleoptions, $job.info.vssoptions, $job.info.postcommandruncount, $job.info.vcbhostid, $job.info.jobsourcetype, $job.info.targettype, $job.info.includedsize, $job.info.excludedsize, $job.info.isdeleted, $job.getlastresult(), $job.isscheduleenabled, $job.info.backupplatform)
[Veeam.Backup.Core.CBackupJob]::Update($info)
}
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
-
- Veteran
- Posts: 282
- Liked: 26 times
- Joined: Nov 10, 2010 6:51 pm
- Full Name: Seth Bartlett
- Contact:
Re: How to Update targetdir with Powershell
Here is the most up to date code, please do not use the other code:
This will update everything properly. As always, I am writing these scripts myself and they are not officially supported by Veeam.
To call it, you will want to do SetDir "JobName" "Directory". Example: SetDir "Myjob" "C:\test\" make sure you append the \ at the end(this is very important)
Code: Select all
Function SetDir
{
param ([string]$JobName, [string]$targetDir)
$job = Get-VBRJob | where-object {$_.name -eq $JobName}
$Manager = [Veeam.Backup.DBManager.CDBManager]::Instance
$Backup = Get-VBRBackup | ?{$_.jobname -eq "JobName"}
$Storage = $Manager.Storages.GetStoragesInBackup($Backup.Id)
$info = [Veeam.Backup.Model.CDbBackupJobInfo]::CreateExisting($job.id, $job.name, $job.description, $job.jobtargettype, $job.gettargethost().id, $targetDir, $job.info.targetfile, $job.info.options, $job.info.scheduleoptions, $job.info.vssoptions, $job.info.postcommandruncount, $job.info.vcbhostid, $job.info.jobsourcetype, $job.info.targettype, $job.info.includedsize, $job.info.excludedsize, $job.info.isdeleted, $job.getlastresult(), $job.isscheduleenabled, $job.info.backupplatform)
[Veeam.Backup.Core.CBackupJob]::Update($info)
foreach($value in $Storage)
{
$value.FilePath = $targetDir + [regex]::Replace($value.filepath,"(.+\\)(.*)",'$2')
$Manager.Storages.UpdateStorage($value)
}
}
To call it, you will want to do SetDir "JobName" "Directory". Example: SetDir "Myjob" "C:\test\" make sure you append the \ at the end(this is very important)
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
-
- Enthusiast
- Posts: 94
- Liked: 6 times
- Joined: Apr 21, 2011 7:37 pm
- Contact:
Re: How to Update targetdir with Powershell
Thanks for this code Seth. A powerful command line interface is one of the main features that makes this product standout from the rest.
-
- Enthusiast
- Posts: 71
- Liked: 2 times
- Joined: Jul 25, 2009 12:14 am
- Contact:
Re: How to Update targetdir with Powershell
Hi Seth,Sethbartlett wrote:Here is the most up to date code, please do not use the other code:
This will update everything properly. As always, I am writing these scripts myself and they are not officially supported by Veeam.Code: Select all
Function SetDir { param ([string]$JobName, [string]$targetDir) $job = Get-VBRJob | where-object {$_.name -eq $JobName} $Manager = [Veeam.Backup.DBManager.CDBManager]::Instance $Backup = Get-VBRBackup | ?{$_.jobname -eq "JobName"} $Storage = $Manager.Storages.GetStoragesInBackup($Backup.Id) $info = [Veeam.Backup.Model.CDbBackupJobInfo]::CreateExisting($job.id, $job.name, $job.description, $job.jobtargettype, $job.gettargethost().id, $targetDir, $job.info.targetfile, $job.info.options, $job.info.scheduleoptions, $job.info.vssoptions, $job.info.postcommandruncount, $job.info.vcbhostid, $job.info.jobsourcetype, $job.info.targettype, $job.info.includedsize, $job.info.excludedsize, $job.info.isdeleted, $job.getlastresult(), $job.isscheduleenabled, $job.info.backupplatform) [Veeam.Backup.Core.CBackupJob]::Update($info) foreach($value in $Storage) { $value.FilePath = $targetDir + [regex]::Replace($value.filepath,"(.+\\)(.*)",'$2') $Manager.Storages.UpdateStorage($value) } }
To call it, you will want to do SetDir "JobName" "Directory". Example: SetDir "Myjob" "C:\test\" make sure you append the \ at the end(this is very important)
This was exactly what i needed but i noticed a typo:
it should be
Code: Select all
$Backup = Get-VBRBackup | ?{$_.jobname -eq $JobName}
Code: Select all
$Backup = Get-VBRBackup | ?{$_.jobname -eq "JobName"}
-
- Veteran
- Posts: 282
- Liked: 26 times
- Joined: Nov 10, 2010 6:51 pm
- Full Name: Seth Bartlett
- Contact:
Re: How to Update targetdir with Powershell
Yeah I noticed that after I wrote it and forgot to edit it:P
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
-
- Lurker
- Posts: 1
- Liked: never
- Joined: Mar 17, 2015 10:43 pm
- Full Name: Joseph Anthony
- Contact:
Re: How to Update targetdir with Powershell
Any idea how to get this working for a File Copy Job? Those jobs don't seem to show up under Get-VBRBackup , only under Get-VBRJob. Tried to modify the script a bit, cannot get past the ($Backup.Id) portion.
Basically, I want my File Copy jobs to go into a new folder each time and not overwrite the last copy. My thought is to add the $Date variable when using this script to set the targetdir.
Thoughts? Thank you
Basically, I want my File Copy jobs to go into a new folder each time and not overwrite the last copy. My thought is to add the $Date variable when using this script to set the targetdir.
Thoughts? Thank you
-
- Lurker
- Posts: 1
- Liked: never
- Joined: Mar 29, 2016 7:08 pm
- Full Name: Stephen Small
- Contact:
Re: How to Update targetdir with Powershell
I ran the code above to alter my TragetDir:
but get this error:
Code: Select all
Function SetDir
{
param ([string]$JobName, [string]$targetDir)
$job = Get-VBRJob | where-object {$_.name -eq $JobName}
$Manager = [Veeam.Backup.DBManager.CDBManager]::Instance
$Backup = Get-VBRBackup | ?{$_.jobname -eq "JobName"}
$Storage = $Manager.Storages.GetStoragesInBackup($Backup.Id)
$info = [Veeam.Backup.Model.CDbBackupJobInfo]::CreateExisting($job.id, $job.name, $job.description, $job.jobtargettype, $job.gettargethost().id, $targetDir, $job.info.targetfile, $job.info.options, $job.info.scheduleoptions, $job.info.vssoptions, $job.info.postcommandruncount, $job.info.vcbhostid, $job.info.jobsourcetype, $job.info.targettype, $job.info.includedsize, $job.info.excludedsize, $job.info.isdeleted, $job.getlastresult(), $job.isscheduleenabled, $job.info.backupplatform)
[Veeam.Backup.Core.CBackupJob]::Update($info)
foreach($value in $Storage)
{
$value.FilePath = $targetDir + [regex]::Replace($value.filepath,"(.+\\)(.*)",'$2')
$Manager.Storages.UpdateStorage($value)
}
}
setdir 'SCCMBackup' 'F:\Backups\'
but get this error:
Code: Select all
Method invocation failed because [Veeam.Backup.DBManager.CStoragesDbScope] does not contain a method named 'GetStoragesInBackup'.
At line:7 char:4
+ $Storage = $Manager.Storages.GetStoragesInBackup($Backup.Id)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Cannot find an overload for "CreateExisting" and the argument count: "20".
At line:8 char:4
+ $info = [Veeam.Backup.Model.CDbBackupJobInfo]::CreateExisting($job ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
Exception calling "Update" with "1" argument(s): "Object reference not set to an instance of an object."
At line:9 char:4
+ [Veeam.Backup.Core.CBackupJob]::Update($info)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NullReferenceException
-
- Product Manager
- Posts: 20406
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: How to Update targetdir with Powershell
Would it be easier just to clone the job via Copy-VBRJob and set a new repository with -Repository parameter? Thanks.
-
- Enthusiast
- Posts: 94
- Liked: 6 times
- Joined: Apr 21, 2011 7:37 pm
- Contact:
Re: How to Update targetdir with Powershell
Using Copy-VBRJob this way, does it cause the next job run to create a full or an incremental?
-
- Product Manager
- Posts: 20406
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: How to Update targetdir with Powershell
Full, unless you move the backups to a new repository and map a backup job. The very same behaviour exists in GUI. Thanks.
-
- Veeam Software
- Posts: 67
- Liked: 3 times
- Joined: Oct 18, 2011 3:47 am
- Full Name: Nelson Simao
- Contact:
Re: How to Update targetdir with Powershell
Hi Vladmir,
I've been trying to find a cmdlet or script for mapping an imported backup to a repository, is it possible?
I've been trying to find a cmdlet or script for mapping an imported backup to a repository, is it possible?
-
- Product Manager
- Posts: 20406
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: How to Update targetdir with Powershell
What exactly do you mean by saying "map imported backup to a repository"? Thanks.
Who is online
Users browsing this forum: No registered users and 8 guests