-
- Veeam Software
- Posts: 21139
- Liked: 2141 times
- Joined: Jul 11, 2011 10:22 am
- Full Name: Alexander Fogelson
- Contact:
Re: Veeam 7 Copy Job - Transform
Yes, script examples are given here as a starting point, you can take one and adapt it to your environment.
-
- Enthusiast
- Posts: 26
- Liked: never
- Joined: Feb 07, 2013 8:49 pm
- Full Name: Tom Scott
- Contact:
Re: Veeam 7 Copy Job - Transform
I tried to run the script manually via PS and get this:
Thanks for the help.PS C:\> .\BackupCopy.ps1
Add-PSSnapin : Cannot load Windows PowerShell snap-in VeeamPSSnapin because of the following error: Could not load file
or assembly 'file:///C:\Program Files\Veeam\Backup and Replication\Veeam.Backup.PowerShell.dll' or one of its dependen
cies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
At C:\BackupCopy.ps1:1 char:5
+ asnp <<<< VeeamPSSnapin
+ CategoryInfo : InvalidArgument: (VeeamPSSnapin:String) [Add-PSSnapin], PSSnapInException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
The term 'Get-VBRBackup' is not recognized as the name of a cmdlet, function, script file, or operable program. Check t
he spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\BackupCopy.ps1:6 char:24
+ $backup = Get-VBRBackup <<<< -Name $jobname
+ CategoryInfo : ObjectNotFound: (Get-VBRBackup:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
You cannot call a method on a null-valued expression.
At C:\BackupCopy.ps1:7 char:39
+ $backupfilepath = ($backup.GetStorages <<<< () | ?{$_.GetStorageType() -eq "vbk"}).FilePath
+ CategoryInfo : InvalidOperation: (GetStorages:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At C:\BackupCopy.ps1:8 char:38
+ $backupdirpath = ($backup.GetStorages <<<< () | ?{$_.GetStorageType() -eq "vbk"}).DirPath
+ CategoryInfo : InvalidOperation: (GetStorages:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Test-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\BackupCopy.ps1:11 char:19
+ if (-not(Test-Path <<<< "$backupfilepath")) {
+ CategoryInfo : InvalidData: (:) [Test-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.Test
PathCommand
-
- Influencer
- Posts: 11
- Liked: 2 times
- Joined: Sep 04, 2013 2:09 pm
- Full Name: Thomas Voß
Re: Veeam 7 Copy Job - Transform
This could be one of these:
1.) You did run that Script on a different machine than where Veeam is installed
2.) You have not installed the Veeam Powershell Extension
3.) Your Powershell Profile may be broken / No Access?
So find out which PS Snapins are loadable try:
Start Powershell
type: get-module -Listavailable
if there is no Veeam Sanpin, you are probably on the wrong machine if you installed it. Or the Snapin is not installed.
If it is not installed try this: http://www.veeam.com/kb1489
If that did not fix the error try to repair the Powershell Profile. How this works you have to google.
P.S.: You have to check which Script you are using, some of them (like i have posted, needs a CopyJob Name as parameter).
1.) You did run that Script on a different machine than where Veeam is installed
2.) You have not installed the Veeam Powershell Extension
3.) Your Powershell Profile may be broken / No Access?
So find out which PS Snapins are loadable try:
Start Powershell
type: get-module -Listavailable
if there is no Veeam Sanpin, you are probably on the wrong machine if you installed it. Or the Snapin is not installed.
If it is not installed try this: http://www.veeam.com/kb1489
If that did not fix the error try to repair the Powershell Profile. How this works you have to google.
P.S.: You have to check which Script you are using, some of them (like i have posted, needs a CopyJob Name as parameter).
-
- Enthusiast
- Posts: 26
- Liked: never
- Joined: Feb 07, 2013 8:49 pm
- Full Name: Tom Scott
- Contact:
Re: Veeam 7 Copy Job - Transform
My failed job with a blank USB drive after it worked on previous blank one:
So I have my backup job and my copy to usb job.. The script is added to the copy to usb job, right? And it's also set to continuous.. If that needs changed please let me know too..
Thanks
What I get when I manually run the ps1:11/28/2013 12:02:21 AM :: Processing 'CCA-PROPERTY' Error: Client error: File does not exist. File: [E:\USB_Backup\USB_Backup2013-11-27T000000.vib].
Failed to restore file from local backup. VFS link: [summary.xml]. Target file: [MemFs://Tar2Text]. CHMOD mask: [0].
This is so frustrating.. Why can this not just be a built in function of Veeam..Add-PSSnapin : Cannot add Windows PowerShell snap-in VeeamPSSnapin because it is already added. Verify the name of the
snap-in and try again.
At C:\BackupCopy.ps1:1 char:5
+ asnp <<<< VeeamPSSnapin
+ CategoryInfo : InvalidArgument: (VeeamPSSnapin:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
Exception calling "Delete" with "0" argument(s): "Couldn't perform the operation while backup job is running."
At C:\BackupCopy.ps1:14 char:19
+ $backup.Delete <<<< ()
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
So I have my backup job and my copy to usb job.. The script is added to the copy to usb job, right? And it's also set to continuous.. If that needs changed please let me know too..
Thanks
-
- Influencer
- Posts: 11
- Liked: 2 times
- Joined: Sep 04, 2013 2:09 pm
- Full Name: Thomas Voß
Re: Veeam 7 Copy Job - Transform
You have to add the Script to the Backup Job not to the copy job
I try to explain:
1.) You do a Backup of a VM with BackupJob1
2.) @ the End of BackupJob1 the Script checks for correct vbk of CopyJob1 and USB Disk. If not the same, it will delete VBK File and delete CopyJob1 Restore Points in DB of Veem
3.) Then the CopyJob1 will run, and do a new Restore piont to USB (depending if VBK is Present then a VIB or if VBK not present a VBK)
Thats all.
Just modify the Script on top:
asnp -Name VeeamPSSnapin
To
asnp -Name VeeamPSSnapin -ErrorAction SilentlyContinue
The ErrorAction will suppress the Error.
The Second modification on the Script is the Name of the COPYJOB. Every Backup may have it's OWN CopyJob. If you run the Script the Script has to know the COPYJOB NAME! If it does not know it, it can not do anything.
As you mentioned that you have attached the Script to the CopyJob i think that it has deleted everything on the USB Drive. Or Prevents to create something on the USB Disk.
Try the following:
Everything without the Script
1.) Do a Backup of a VM
2.) Setup a NEW CopyJob to USB destination (Or if you don't want to add a NEW one, delete the Restore Points in Veeam under: Backup & Replication ->Backup->Disks right click on your copyjob->remove from Disk (That is what the Script is doing)
3.) Run the Copy Job
4.) You will see a new Restore Point of your CopyJob (on USB you have 1 * vbk)
5.) Do another Backup of that VM
6.) Run Copy Job
7.) You see 2 Restore points (on USB you have 1 * vbk and 1 * VIB file) OR If you came from 12.) You have 1 Restore point (on Disk a VBK)
7.1) repeat Steps 5.) - 7.) as often you like
To change the Media you would do MANUALLY this:
8.) Detach USB1 (You have here VBK + VIB Restore point)
9.) Attach USB2 (maybe empty or not) but same DriveLetter!
10.) If it is FULL you have to delete the content (job of the Script)
11.) Delete CopyJob Restore Points mentioned above
The Second USB2 Copy
12.) Start on 5.) You have no Restore Points you have nothing on Disk it should work!
So now with Script.
1.) Attach Script to the Backup Job (Pay attention to modify the name of the CopyJob in Script!) It will not WORK on the same DAY! VBK Files will have the SAME Name, in this case you have to delete the files by manually or rename them.
2.) Run Backup Job
3.) Script on Backup Job will check if VBK File is the "same" (same Name) on Disk and in DB (CoypJob Restore point)
4.) If SAME it will DO NOTHING
5.) If not the SAME it will delete VBK, VIB etc. files AND delete Restore Points from COPYJOB (This happens usually when you change USB DISKS)
6.) Run CopyJob
7.) CopyJob will create VBK or VIB File depending on VBK Present or not.
8.) You are fine now.
Please pay attention CopyJob will ONLY copy the latest Restore Point from Backup. So if you done 5 Backups during the day. It will only copy the LAST one, maybe not ALL.
Maybe that explanation will help and not confusing you.
To everyone else: If i am wrong just correct me.
And after ALL i attach my Script again, in Backup Job you have to run it with:
powershell.exe C:\PathtoScript\CopyJobCleanup.ps1 -Job 'CopyJobName'
I try to explain:
1.) You do a Backup of a VM with BackupJob1
2.) @ the End of BackupJob1 the Script checks for correct vbk of CopyJob1 and USB Disk. If not the same, it will delete VBK File and delete CopyJob1 Restore Points in DB of Veem
3.) Then the CopyJob1 will run, and do a new Restore piont to USB (depending if VBK is Present then a VIB or if VBK not present a VBK)
Thats all.
OK, your Veeam Powershell Snapin is there. This error indicates that you have run the script twice or in the Veeam Powershell (here the Sanpin is loaded by default) or in normal Powershell if you run it twice it will be loaded only once.Add-PSSnapin : Cannot add Windows Powershell snap-in VeeamPSSnapin because it is already added. Verify the name of the
snap-in and try again.
At C:\BackupCopy.ps1:1 char:5
+ asnp <<<< VeeamPSSnapin
Just modify the Script on top:
asnp -Name VeeamPSSnapin
To
asnp -Name VeeamPSSnapin -ErrorAction SilentlyContinue
The ErrorAction will suppress the Error.
The Second modification on the Script is the Name of the COPYJOB. Every Backup may have it's OWN CopyJob. If you run the Script the Script has to know the COPYJOB NAME! If it does not know it, it can not do anything.
As you mentioned that you have attached the Script to the CopyJob i think that it has deleted everything on the USB Drive. Or Prevents to create something on the USB Disk.
Try the following:
Everything without the Script
1.) Do a Backup of a VM
2.) Setup a NEW CopyJob to USB destination (Or if you don't want to add a NEW one, delete the Restore Points in Veeam under: Backup & Replication ->Backup->Disks right click on your copyjob->remove from Disk (That is what the Script is doing)
3.) Run the Copy Job
4.) You will see a new Restore Point of your CopyJob (on USB you have 1 * vbk)
5.) Do another Backup of that VM
6.) Run Copy Job
7.) You see 2 Restore points (on USB you have 1 * vbk and 1 * VIB file) OR If you came from 12.) You have 1 Restore point (on Disk a VBK)
7.1) repeat Steps 5.) - 7.) as often you like
To change the Media you would do MANUALLY this:
8.) Detach USB1 (You have here VBK + VIB Restore point)
9.) Attach USB2 (maybe empty or not) but same DriveLetter!
10.) If it is FULL you have to delete the content (job of the Script)
11.) Delete CopyJob Restore Points mentioned above
The Second USB2 Copy
12.) Start on 5.) You have no Restore Points you have nothing on Disk it should work!
So now with Script.
1.) Attach Script to the Backup Job (Pay attention to modify the name of the CopyJob in Script!) It will not WORK on the same DAY! VBK Files will have the SAME Name, in this case you have to delete the files by manually or rename them.
2.) Run Backup Job
3.) Script on Backup Job will check if VBK File is the "same" (same Name) on Disk and in DB (CoypJob Restore point)
4.) If SAME it will DO NOTHING
5.) If not the SAME it will delete VBK, VIB etc. files AND delete Restore Points from COPYJOB (This happens usually when you change USB DISKS)
6.) Run CopyJob
7.) CopyJob will create VBK or VIB File depending on VBK Present or not.
8.) You are fine now.
Please pay attention CopyJob will ONLY copy the latest Restore Point from Backup. So if you done 5 Backups during the day. It will only copy the LAST one, maybe not ALL.
Maybe that explanation will help and not confusing you.
To everyone else: If i am wrong just correct me.
And after ALL i attach my Script again, in Backup Job you have to run it with:
powershell.exe C:\PathtoScript\CopyJobCleanup.ps1 -Job 'CopyJobName'
Code: Select all
# Get Parameters
param( $job )
# Import Veeam Snapin and we do not want Errors
asnp -Name VeeamPSSnapin -ErrorAction SilentlyContinue
# If we have a JobName then we go further
if ( $job ) {
# JobName here
$jobName = $job
# Get Backup Specs
$backup = Get-VBRBackup -Name $jobName
if ( $backup.JobName ) {
# Get FilePath
$backupfilepath = ( $backup.GetStorages() | ?{$_.GetStorageType() -eq "vbk"} ).FilePath
# Get Directory for deleting
$backupdirpath = ( $backup.GetStorages() | ?{$_.GetStorageType() -eq "vbk"} ).DirPath
# If current active VBK is found on media then media has not been rotated
if ( -not( Test-Path "$backupfilepath" ) ) {
# Current active VBK was not found indicating media has been changed
# First DisableScheduler, If not then the Copy Job will Create a new Directory like $Jobname_1
# Get-Job Object
$CopyJob = Get-VBRJob -Name $jobName
# Disbale Scheduler
$CopyJob.DisableScheduler()
# then Wait until Job is Stopped (and is not running anymore)
while ( -not( $CopyJob.IsStopped() ) ) {
# Do Nothing
}
# If stopped then Delete from VeeamGUI
$backup.Delete()
# Remove Backup Files from Media
if ( Test-Path "$backupdirpath" ) {
# Remove whole Directory
Remove-Item -Path "$backupdirpath" -Recurse
}
# Enable Scheduler
$CopyJob.EnableScheduler()
}
} # UPPS NOT RIGHT JOBNAME - BUT WE ARE SILENT
} # NO JOBNAME given - WE ARE SILENT
-
- Influencer
- Posts: 13
- Liked: never
- Joined: Oct 18, 2013 7:01 pm
- Contact:
Re: Veeam 7 Copy Job - Transform
Do you mind sharing how you scheduled the task for the ps script file?Regnor wrote:FYI; Backup Copy to USB works great with this script.
I have just created it as an scheduled task instead of a post job activitiy. With post job activity I had some problems like the script not being executed or just not working.
-
- Veeam Software
- Posts: 21139
- Liked: 2141 times
- Joined: Jul 11, 2011 10:22 am
- Full Name: Alexander Fogelson
- Contact:
Re: Veeam 7 Copy Job - Transform
This can be done via Windows Task Manager, for example.
-
- Influencer
- Posts: 11
- Liked: 2 times
- Joined: Sep 04, 2013 2:09 pm
- Full Name: Thomas Voß
Re: Veeam 7 Copy Job - Transform
Pay attention to Powershell execution policy!
You have Three Options here:
1.) Set Execution-policy to "allsigned" or "remotesigned" <- best one
2.) Start Script with: powershell -executionpolicy bypass -file c:\my\scrip.ps1 <- easiest one
3.) Set Execution-policy to "unrestricted" <- worse one
You have Three Options here:
1.) Set Execution-policy to "allsigned" or "remotesigned" <- best one
2.) Start Script with: powershell -executionpolicy bypass -file c:\my\scrip.ps1 <- easiest one
3.) Set Execution-policy to "unrestricted" <- worse one
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 65 guests