PowerShell script exchange
joergr
Expert
Posts: 386
Liked: 39 times
Joined: Jun 08, 2010 2:01 pm
Full Name: Joerg Riether
Contact:

backup naming when using reversed incremental

Post by joergr » Oct 26, 2010 1:58 pm

Hi,

an important question for me personally, with 4.x i used to Backup a fullbackup (the latest vbk) to tape every night. I did this by just telling my tape software to backup the "backupjob.vbk" file, because even if i made full backups during some weekdays, the final and most actual backup would always has THIS name.

Now with v5 i have a little problem here: Even if i select reversed increment (which is what i want and which is the v4 way), it would add the date and the time to the latest vbk backup file. Thus I cannot tell my tape backup software to backup THIS special file every night because every time a backup runs this name will change.

Is there some way out for me? ;-) Any idea to tell a tape software to backup the latest full backup without storing all the reverse increments? Or any tweak to have the naming convention fall back to the v4 way?

best regards,
Joerg

Gostev
SVP, Product Management
Posts: 24915
Liked: 3615 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: backup naming when using reversed incremental

Post by Gostev » Oct 26, 2010 3:34 pm

Hi Joerg, you can use the following PowerShell script as post-backup action, this will work for any backup mode, and will copy the latest backup file to tape (whatever the latest backup file is) and set archive bit on it. Just put the backup job name, and customize path and any arguments for tape backup EXE.

Code: Select all

Add-PSSnapin VeeamPSSnapIn

$jobName = "Put Backup Job Name Here"

if ((Get-VBRJob | where {$_.Name -eq $jobName}).GetLastResult() -eq "Success")
{
   $latestOib = Get-VBRBackup | where {$_.JobName -eq $jobName} | Get-VBRRestorePoint | sort CreationTime -Descending | select -First 1
   $latestOib
   $storage = $latestOib.GetStorage()
   $storage.FilePath

   $file = get-item $storage.FilePath
   if ($file.Attributes -band ([System.IO.FileAttributes]::Archive))
   {
     $path_to_tape_backup_exe $storage.FilePath
      
      $file.Attributes = ($file.Attributes -bxor [System.IO.FileAttributes]::Archive) 
   }  
}

joergr
Expert
Posts: 386
Liked: 39 times
Joined: Jun 08, 2010 2:01 pm
Full Name: Joerg Riether
Contact:

Re: backup naming when using reversed incremental

Post by joergr » Oct 26, 2010 4:12 pm

muchas gracias ;-)

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » May 31, 2011 4:04 pm

Hi,

Did anyone managed to use the above script?

I am finding some troubles running this script, i have changed the job name and the backup exec file path but when i run the backup then backup complete fine but thats it, no backup exec job running.

i have modified the script as follow

Code: Select all

Add-PSSnapin VeeamPSSnapIn

    $jobName = "DMZ-test"

    if ((Get-VBRJob | where {$_.Name -eq $jobName}).GetLastResult() -eq "Success")
    {
       $latestOib = Get-VBRBackup | where {$_.JobName -eq $jobName} | Get-VBRRestorePoint | sort CreationTime -Descending | select -First 1
       $latestOib
       $storage = $latestOib.GetStorage()
       $storage.FilePath

       $file = get-item $storage.FilePath
       if ($file.Attributes -band ([System.IO.FileAttributes]::Archive))
       {
         "d:\Program Files\Symantec\Backup Exec\bemcmd" -o1 -jdmztest $storage.FilePath
         
          $file.Attributes = ($file.Attributes -bxor [System.IO.FileAttributes]::Archive)
       } 
    }
this script was saved as powershell .ps1

i have tested the following line from the command line and the backup exec job starts fine
"d:\Program Files\Symantec\Backup Exec\bemcmd" -o1 -jdmztest

but if i open the Windows Powershell Module window and type the full path to the script file then i have the following error

"

You must provide a value expression on the right-hand side of the '-' operator.
At D:\copytotape.ps1:18 char:58
+ "d:\Program Files\Symantec\Backup Exec\bemcmd" - <<<< o1 -jdmztest $storage.FilePath
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : ExpectedValueExpression

"

i don't understand why it is complaining about the arguments whereas if i run it through the DOS CMD then it is fine.

can anyone help?

Thanks

Vitaliy S.
Product Manager
Posts: 23062
Liked: 1582 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup naming when using reversed incremental

Post by Vitaliy S. » Jun 01, 2011 8:56 am

Could you please modify your script in the following way:

Code: Select all

...
"d:\Program Files\Symantec\Backup Exec\bemcmd -o1 -jdmztest"
...
Does it work?

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » Jun 01, 2011 9:19 am

No did not work - it was complaining about the next variable $storage.FilePath so i included it to the quote so my line now looks like
"d:\Program Files\Symantec\Backup Exec\bemcmd -o1 -jdmztest $storage.FilePath"

This i think has worked although no Backup Exec job has started but the output of the Powershell widows indicates that could not add veeam snap-in
see below

Code: Select all

PS C:\Windows\system32> D:\copytotape.ps1
Add-PSSnapin : Cannot add Windows PowerShell snap-in VeeamPSSnapIn because it is already added. Verify the name of
snap-in and try again.
At D:\copytotape.ps1:2 char:13
+ Add-PSSnapin <<<<  VeeamPSSnapIn
    + CategoryInfo          : InvalidArgument: (VeeamPSSnapIn:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand



Info              : Veeam.Backup.Model.COibInfo
Id                : a373ad08-1f5b-4e39-bba4-74dac094dd1a
CreationTime      : 31/05/2011 16:44:55
CreationTimeUtc   : 31/05/2011 15:44:55
Type              : Increment
Algorithm         : Increment
PointId           : e92ae8aa-7238-4645-b384-dfa325e7d90d
ObjectId          : 2e4ff73a-de8a-4615-ba70-deecffea4dc6
StorageId         : d7c0b65e-631c-4f2c-b05e-38f143b85b11
InsideDir         : ff7bb930-f879-4a76-8173-11b05dba566a (vm-797)
IsFailoved        : False
IsCorrupted       : False
IsConsistent      : True
ApproxSize        : 42949672960
VmName            : DMZ-test
EffectiveMemoryMb : 4096
GuestInfo         : Veeam.Backup.Model.CGuestInfo
ProcessID         : -1
AuxData           : Veeam.Backup.Core.COibAuxDataVmware

D:\test\DMZ-test\DMZ-test2011-05-31T164449.vib

Vitaliy S.
Product Manager
Posts: 23062
Liked: 1582 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup naming when using reversed incremental

Post by Vitaliy S. » Jun 01, 2011 9:37 am

Nile,

In order to avoid such errors, you may want to modify your script with something like this. As to the BE job not running, try to execute any other simple script just to check whether it is triggered or not.

Thanks.

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » Jun 01, 2011 9:55 am

I am assuming that the error is not important as the link you have send me is just define it as Silent continue in other word just ignore the error. As long as veeam snap in is started then i don't care but how do i check if the snap-in has started.

As per the BE - you suggestion to try simple script; do you mean PowerShell script (which i have no experience but will try) or did you mean .bat files cus as i said before i can start backup exec job from the DOS-CMD by just calling
"d:\Program Files\Symantec\Backup Exec\bemcmd" -o1 -jdmztest
as you can see the ending quotes is in differen place than the one in PowerShell script.

If the problem is with the powerShell script then i am just wondering has this been tested before been published or is there anyone was successfull with this Powershell script?

Thanks for your help.

Vitaliy S.
Product Manager
Posts: 23062
Liked: 1582 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup naming when using reversed incremental

Post by Vitaliy S. » Jun 01, 2011 10:52 am

As far as I see it from the forums this functionality has been used pretty often and so far we've received no negative feedback.

The reason why I've asked you to perform a simple script check (bat file will be enough) is that your BE script might not be executed as a post backup job script due to these reasons (even if you are able to launch it interactively).

If this is not the case and everything looks good, please reach our technical team for further troubleshooting steps.

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » Jun 01, 2011 11:30 am

i can confirm the Post backup job script (bat file) runs good and the BE job runs as well. As i mentioned before It seems to me that the PowerShell Script has problems or my environment is missing something - i am running the backup exec 2010R2 on windows server 2008R2 and veeam running on the same server.

I am afraid that if i contact Veeam support i will be turned down as this is to do with the Powershell script and BE.

have we reached a closed door in this forum? is there anyone else can add something?

Vitaliy S.
Product Manager
Posts: 23062
Liked: 1582 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup naming when using reversed incremental

Post by Vitaliy S. » Jun 01, 2011 1:40 pm

I'm not a PS expert, but I've googled further...

Could this issue be related to arguments with spaces and quotes triggering in a different way with PowerShell?
http://stackoverflow.com/questions/1673 ... and-quotes
http://www.powershell.nu/2009/12/16/run ... owershell/

Another way out might be specifying a batch file or another PS script (which will trigger BE job) instead of using BE job cmdlet directly, worth trying...

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » Jun 01, 2011 3:42 pm

Hi Vitaliy,

I have found the above link as well but the problem is the missing &

the line should be like this

& "d:\Program Files\Symantec\Backup Exec\bemcmd.exe" -o1 -jdmztest $storage.FilePath

i am surprise no one has spotted this syntax error!!

However this has fixed the problem if i run the PS file from the PS command, But if i added to the Post backup job in veeam then it does not do anything!!!

I am just going to try to run it from bat file as i dont know if veeam can run PS1 files

Vitaliy S.
Product Manager
Posts: 23062
Liked: 1582 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup naming when using reversed incremental

Post by Vitaliy S. » Jun 01, 2011 3:55 pm

Nile, thanks for an update and for catching a syntax error! Just fixed it. Let me know how the bat file works for you.

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » Jun 02, 2011 10:33 am

This script unfortunately is still not working; after fixing the syntax error, i am still not able to run this script from within veeam (Post job), this probably due to Veeam not able to run PS files.
So I tried to get the PS file to run from BAT file - This also has failed due to using Veeam custom functions like (Get-VBRBackup) that bat file does not understand.

so i am really stuck with this and i hope that Gostev (who wrote the script) or any other member who is using this script that works for them to share with all of us

Many thanks

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » Jun 02, 2011 1:06 pm

Ok guys - got it working!!

I can now confirm that Veeam is not able to run PS file from its post-backup script.
what you need to do is the following
1. Create the PS (e.g. test.ps1)file that was mentioned above (dont forget to get the Syntax write - you need the & for the file to work see above)
2. Create a BAT (e.g test2.bat)file that should include the following
powershell.exe FileNameIncludePath e.g assuming the PS file is in the root of C:\ then your code should be powershell.exe c:\test1.ps1
3. On veeam Post-job activity browse to the test2.bat

all done - this should backup the file then runs the post script which in turn will run BE job

Regards,

Nile

Vitaliy S.
Product Manager
Posts: 23062
Liked: 1582 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup naming when using reversed incremental

Post by Vitaliy S. » Jun 02, 2011 2:46 pm

Nile, glad that you've been able to figure it out. Nice job!

Yes, that's right. Seems like it has slipped out of my mind that currently we do not support triggering PowerShell scripts directly from the backup console.

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » Jun 03, 2011 8:11 am

I was so happy when the script ran successfully from within Veeam that i actually forgot to check the most crucial outcome of this script that is; The Latest Backup File will be backed up on a tape. This has disappointedly failed which indicates there is a fundamental issue with the script. i'll explain below

The steps of the script is as follow

1. Extract the latest Veeam backup file (VIB,VRB or VBK)
2. Pass this file to backup exec and run a predefined job on BE so that it can ONLY backup the passed veeam file from step 1
3. Set the Archive attribute again on the file

step 2 and step 3 don't work; to understand why; you need to analyse the script line where bemcmd.exe is used and also you will need the knowledge of how bemcmd works.
The line in step 2 is:
& "d:\Program Files\Symantec\Backup Exec\bemcmd.exe" -o1 -jJobName $storage.FilePath

bemcmd takes the following switches
-o1 this tells backup exec to start a job
-j this tells backup exec the job name
$storage.FilePath This supposed to tell backup exec the file path so that it can be backed up.

But bemcmd does not allow any think to be passed after you specify the job name therefore the file name is not passed as a result the tape is empty.

step 3 does not work
$file.Attributes = ($file.Attributes -bxor [System.IO.FileAttributes]::Archive)

I am not sure if i am doing something wrong but i hope that someone can shed some light to this problematic script

Thanks

gshaw
Enthusiast
Posts: 51
Liked: never
Joined: Apr 07, 2011 2:25 pm
Full Name: Gerrard Shaw
Contact:

Re: backup naming when using reversed incremental

Post by gshaw » Jun 03, 2011 12:28 pm

Hmm this looks like a frustrating issue as I wanted to offload the reverse incremental .vbk to tape each week... is there no way to change the behaviour of the file naming or is there a working solution to the script?

Only other way I'll be able to get around it is to run an extra full backup but that's not ideal as it'll take some time to complete as opposed to using what's already there...

Vitaliy S.
Product Manager
Posts: 23062
Liked: 1582 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup naming when using reversed incremental

Post by Vitaliy S. » Jun 03, 2011 12:51 pm

Hello Gerrard,

Actually you can apply the following registry key to go back to our previous naming convention. But please be aware that that the workaround provided will change a VBK name after a Full run only.

Hope this helps.

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » Jun 03, 2011 1:42 pm

Hi Vitaliy,

I have managed to fix step 2- the new line should look like this
& "d:\Program Files\Symantec\Backup Exec\bemcmd.exe" -o2 -jJobName -s:$storage.FilePath -mMediaName -r

But please i need help with step 3 - this line is setting the attribute to Normal and not Archive (it is probably to do with the switch -bxor)
$file.Attributes = ($file.Attributes -bxor [System.IO.FileAttributes]::Archive)

But if i change the line to $file.Attributes = ($file.Attributes -bxor [System.IO.FileAttributes]::Normal)
then everything is fine but just the line now does not read logically. So please if you provide me with the right witches for the $file.Attributes -bxor this will probably fix it.


Please provide me with some documentation on Veeam cmd.

thanks,

Vitaliy S.
Product Manager
Posts: 23062
Liked: 1582 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup naming when using reversed incremental

Post by Vitaliy S. » Jun 03, 2011 2:45 pm

Ok, let me consult with our PowerShell developer, he should be able to shed some light on this.

Vitaliy S.
Product Manager
Posts: 23062
Liked: 1582 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup naming when using reversed incremental

Post by Vitaliy S. » Jun 06, 2011 9:54 am

Nile, here you go, this should help you in setting up proper attributes for the backup files:
http://stackoverflow.com/questions/4647 ... powershell

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » Jun 08, 2011 9:32 am

Hi Vitaliy,

thanks for the link, everything is working now.

gshaw
Enthusiast
Posts: 51
Liked: never
Joined: Apr 07, 2011 2:25 pm
Full Name: Gerrard Shaw
Contact:

Re: backup naming when using reversed incremental

Post by gshaw » Jun 08, 2011 10:28 am

Does this mean the script is working OK now? Is the updated code available?

itldn
Influencer
Posts: 24
Liked: never
Joined: Mar 29, 2011 9:54 am
Contact:

Re: backup naming when using reversed incremental

Post by itldn » Jun 09, 2011 9:12 am

Hi gshaw,
yes the script is working now.

Here it is for all of you. You need to call this powershell script from within a bat file
Remember to create a BE job before you run this script

Code: Select all

	if ( (Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null )
	{
    		Add-PsSnapin VeeamPSSnapIn

	}

    $VeeamJobName = "jobname"
    $backupExecJob   = "jobname" 


    if ((Get-VBRJob | where {$_.Name -eq $VeeamJobName}).GetLastResult() -eq "Success")
    {
       $latestOib = Get-VBRBackup | where {$_.JobName -eq $VeeamJobName} | Get-VBRRestorePoint | sort CreationTime -Descending | select -First 1
       $latestOib
       $storage = $latestOib.GetStorage()
       $storage.FilePath

       $file = get-item $storage.FilePath


       if ($file.Attributes -band ([System.IO.FileAttributes]::Archive))
       {		
         & "d:\Program Files\Symantec\Backup Exec\bemcmd.exe" -o2 -j:$backupExecJob -s:$storage.FilePath -mTapes-Weekdays -r -w

	 $file.Attributes = 'Archive'
       } 
    }
Thanks,

Nile

gshaw
Enthusiast
Posts: 51
Liked: never
Joined: Apr 07, 2011 2:25 pm
Full Name: Gerrard Shaw
Contact:

Re: backup naming when using reversed incremental

Post by gshaw » Jun 11, 2011 7:24 pm

Thanks for this, good work 8)

I remember somewhere there was some info about how to pre-create the BE job but can't remember the thread, can someone copy back here for reference? Would be good to have the info all in one place :)

Vitaliy S.
Product Manager
Posts: 23062
Liked: 1582 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: backup naming when using reversed incremental

Post by Vitaliy S. » Jun 13, 2011 8:39 am

Here you go -> Writing to Tape Help

MCoppola
Lurker
Posts: 1
Liked: never
Joined: Jul 27, 2011 6:46 pm
Full Name: Mark Coppola
Contact:

Upgradeing Veeam 4 to 5 broke my backup strategy

Post by MCoppola » Jul 27, 2011 8:05 pm

[merged]

My backup strategy used Veeam 4 with reverse incremental backups. This worked out nice for me because I would retain the current file and past 4 increments (M-F) in a shared folder.

Every weeknight I would just copy the latest file after Veeam ran to get my current data backed up, and every weekend I would get the whole folder so I could restore to any point in the week.

Now that I am on Veeam 5, it appends the date and other metadata to the file name so I can no longer target the newest backup for my weeknight backups because the file name changes every backup run. Is there a way I can force it to use a clean file name for the base backup like Veeam 4 did?


===
Visual aides (can you tell I am used to writing paint by numbers type documentation for my users? lol)

Backups of the server Paris using Veeam 4:
Image

When setting up my Daily job in BackupExec I can just backup the main file and always have the latest backup:
Image


Now that I am on Veeam 5, the filenames all have metadata attached:
Image

It doesn’t matter if I pick the .VBK file in the selection list because tomorrow the name will change:
Image

I looked around BackupExec and could not find an option to do something like *.VBK so I need to figure out how to standardize the file names, or I need to rethink my strategy

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: backup naming when using reversed incremental

Post by ThomasMc » Jan 20, 2012 6:44 pm

This was requested over twitter but thought I would update this thread incase anyone else find themselves in the same situation

Version: 5
Purpose: Send commands to remote BackupExec Server

Code: Select all

# Remoting must be enabled on the BackupExec Server 
# And user must have access to complete task on Veeam and BE

if ((Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue) -eq $null) {
	Add-PsSnapin VeeamPSSnapIn
}

$veeamJobName = "Veeam Job 01"
$backupExecJob = "BackupExec Job 01" 
$backupExecSvr = "BackupExec01"
$backupExecPath = "C:\Program Files\Symantec\Backup Exec"

if ((Get-VBRJob | ?{$_.Name -eq $veeamJobName}).GetLastResult() -eq "Success") {
	$latestOib = Get-VBRBackup | ?{$_.JobName -eq $veeamJobName} | Get-VBRRestorePoint | Sort CreationTime -Descending | Select -First 1
	$latestOib
	$storage = $latestOib.GetStorage()
	$storage.FilePath

	$file = Get-Item $storage.FilePath
	if ($file.Attributes -band ([System.IO.FileAttributes]::Archive)) {   
		Invoke-Command -ComputerName $backupExecSvr -ScriptBlock {
			param (
				[PSObject]$storage,
				[PsObject]$file,
				[String]$backupExecJob,
				[String]$backupExecPath
				)
			
			& "$backupExecPath\bemcmd.exe" -o2 -j:$backupExecJob -s:$storage.FilePath -m Tapes-Weekdays -r -w
			$file.Attributes = 'Archive'
		} -ArgumentList $storage, $file, $backupExecJob, $backupExecPath
	}
}

lcfc
Novice
Posts: 3
Liked: never
Joined: May 18, 2011 2:11 am
Full Name: Gary Davidson
Contact:

Re: backup naming when using reversed incremental

Post by lcfc » Jun 26, 2012 1:08 am

Raising an old post here but it's relevant to my problem.

I need to backup the last months veeam files of my D2D to tape using BE 2010. I can't use the last accessed date in BE as the files show a recent date and I'd still end up backing up TB's of data that I don't need.

I'm no expert in Powershell but can this script be modified to select say the first 20 files? I did make a quick change to test and it failed - probably because it's only exepecting 1 file?

Method invocation failed because [System.Object[]] doesn't contain a method named 'GetStorage'.
At C:\veeam_scripts\myjob.ps1:9 char:36
+ $storage = $latestOib.GetStorage <<<< ()
+ CategoryInfo : InvalidOperation: (GetStorage:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

Get-Item : Cannot bind argument to parameter 'Path' because it is null.
At C:\veeam_scripts\myjob.ps1:12 char:20
+ $file = get-item <<<< $storage.FilePath
+ CategoryInfo : InvalidData: (:) [Get-Item], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.GetItemComm
and

Any help to get this working would be great.
Thanks
Lcfc

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests