How do you run a batch file before the backup begins using Reflect scheduled backups?


Author
Message
RAKooistra
RAKooistra
New Member
New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)
Group: Forum Members
Posts: 5, Visits: 50
I have a simple batch file I want to execute before the backup actually begins.  I have added it to the "Reflect Defaults -> Scripts -> Run Programs -> Run a program or script at start". 
I have the backups (full, differential, incremental) scheduled under the "Backup -> Scheduled Backups".  When they launch though they are not executing the task?
What am I missing here?

jphughan
jphughan
Most Valuable Professional
Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)
Group: Forum Members
Posts: 2.2K, Visits: 14K
That seems like the right way to do it since I don't see any options at the definition file level to specify pre-/post-execution scripts.  Have you verified that the script runs as expected when you run it manually?  And is the script file stored in a location that the user account under which Reflect jobs run can access it?

RAKooistra
RAKooistra
New Member
New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)New Member (8 reputation)
Group: Forum Members
Posts: 5, Visits: 50
Yes, that's why I am at a loss as to why it will not work.  I debugged the script before hand and placed it in the Public User's folder since there is nothing confidential in it.

jphughan
jphughan
Most Valuable Professional
Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)
Group: Forum Members
Posts: 2.2K, Visits: 14K
I wonder if scripts that run before/after the job are expected to be mentioned in the job log file.... Unfortunately I'm not sure.  Are there any spaces in the folder path or file name just in case that matters?  Can you maybe try replacing the contents of that batch file (keeping the same name) with something extremely simple like "Echo hello world > C:\Users\Public\Hello.txt" and see if that works when the Reflect job runs, just in case there's some issue with your real script that prevents it from running properly or at all when called as another user?

Gork
Gork
Guru
Guru (1.2K reputation)Guru (1.2K reputation)Guru (1.2K reputation)Guru (1.2K reputation)Guru (1.2K reputation)Guru (1.2K reputation)Guru (1.2K reputation)Guru (1.2K reputation)Guru (1.2K reputation)
Group: Forum Members
Posts: 563, Visits: 1.5K
I've never used this feature, but I'm wondering...  If you created the Backup Definition File BEFORE changing the Reflect Default to run the script perhaps editing the script in order to re-save it might make it work?  Just a guess at this point.

EDIT:
And though I don't remember the details, I have had problems running scripts from other programs in the past and my solution has been to run a batch file that only runs another batch or VBS file which contains the actual script I wanted to run and this solved my problem.


OPs can help other forum searchers by highlighting (✔) an answer that resolves the issue.

Edited 10 August 2017 7:21 AM by Gork
Nick
Nick
Macrium Representative
Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)
Group: Administrators
Posts: 1.3K, Visits: 6.9K
@RAKooistra

Thanks for posting. 

To run a batch file before your backup you need to set up a script per backup definition:  http://knowledgebase.macrium.com/display/KNOW7/Generating+scripts+and+batch+files

This generates a full script, either VBScript or Powershell (don't use DOS .bat in this context) that can be used launch pre and post backup processes. There's a Wizard that'll prompt you you for this. This also involves scheduling the scripts rather than the backup definition.

However, there is a much easier way that will fill fit your requirements better.  In the same folder as your backup definition xml file, create a batch file called:

<definition file name>_before_snapshot_wait.bat

Where 'definition file name' is the same name as your xml file (without .xml). When the backup runs it will execute the bat file prior to the backup starting and wait until it finishes before continuing.   You can also use .vbs or .ps1 rather than .bat if you wish.

More info here: http://knowledgebase.macrium.com/display/KNOW7/Stopping+a+SQL+Server+service+automatically+when+backing+up

Although the above KB is specific to stopping the Windows SQL service the same logic can be used to run any batch file. 

Kind Regards

Nick - Macrium Support

Edited 10 August 2017 11:04 AM by Nick
jphughan
jphughan
Most Valuable Professional
Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)
Group: Forum Members
Posts: 2.2K, Visits: 14K
@Nick, then what does the "Run program/script at start" setting under Edit Defaults do, and why is that unsuitable for the OP's purposes? If I needed this functionality, then given that the start/end options are not available under a definition file's Advanced Options, I absolutely would have expected that I could specify an exe/bat/ps1/vbs file in that Edit Defaults area and have it run before every Reflect job -- although then I'd wish that there was a way to specify this on a per definition file basis rather than only (apparently) application-wide.  It might actually be nice to have those "Script at start/end options" also exist at the definition file level, with the Edit Defaults fields then just defaulting new definition files to those settings, rather like the encryption/compression/email settings.  But the mechanism in the first KB article you linked in order to have Reflect make a script that calls your definition file seems more like a corollary to the OP's desire of having the definition file call a script, not so much an equivalent substitution, even though I grant that identical end results can be achieved if you can integrate a call to your definition file into your existing batch file.

Edited 10 August 2017 1:57 PM by jphughan
Nick
Nick
Macrium Representative
Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)
Group: Administrators
Posts: 1.3K, Visits: 6.9K
@Nick, then what does the "Run program/script at start" setting under Edit Defaults do


It's the default setting that's used when you actually generate a script and scripts can only be generated per xml def.  So, the default settings won't run anything. There is no way to specify application wide scripts. 

To generate a script you need to right click on an xml def and select 'Generate VBScript' (or PowerShell or DOS Bat). Scripts are run independently of xml defs so, if you use them then you'll need to schedule them instead of xml defs. 

Example generated base VBScript:  http://knowledgebase.macrium.com/display/KNOW7/_Example_VBScript_Source
Example modifying a script to run sequential backups:  http://knowledgebase.macrium.com/display/KNOW7/Using+VBScript+to+run+sequential+backups

Scripts are flexible but It's much easier for the OP to simply name a batch file '<definition file name>_before_snapshot_wait.bat'. There will be no need to schedule scripts instead of xml defs and the batch file will run prior to running the backup. 

So, in summary...

1. A script is another way of running one or more xml defs. It replaces scheduling and/or running xml defs independently.
This effectively adds xml defs to scripts.

2. Using '<definition file name>_before_snapshot_wait.bat' is much simpler and allows you to run a batch file prior to running an xml def in the normal way.
This effectively adds scripting to the xml def.


Kind Regards

Nick - Macrium Support

Edited 10 August 2017 2:35 PM by Nick
jphughan
jphughan
Most Valuable Professional
Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)Most Valuable Professional (3.1K reputation)
Group: Forum Members
Posts: 2.2K, Visits: 14K
Ok, I see the functionality to generate scripts from definition files (very cool, btw), but I'm only able to get the Edit Defaults setting to work properly with VBS script generation. The PS1 script generation UI did not import the Edit Defaults settings, which appears to be a bug, and the BAT script generation didn't even have this option, nor did the generated BAT file call the files I specified under Edit Defaults.  Here's what I did:

1. Created a batch file called "Hello.bat" on my desktop with a simple line "Echo Hello World > C:\Users\Public\Hello.txt"
2. Went to Edit Defaults and pointed both the start and end settings to that Hello.bat file.  I left the Parameters fields blank.
3. Duplicated my existing Reflect definition file just in case a "new" definition file was required after making the Edit Defaults change.
4. Right-clicked the duplicated definition file and selected "Generate an MS-DOS Batch File"
5. Saved the batch file at the default location and left the default Full backup.
6. Repeated 4 and 5 to select VBS and PowerShell files.

Based on your explanation above, I would have expected my Hello.bat file to have been called at the start and end of each script type I generated. Instead, only the VBS file called my Hello.bat file by default; the PS1 file did so only after I manually configured it in the script generation UI; and the BAT file offered no way to choose whether to call my Hello.bat file.

A couple of other suggestions/notes:
- I would strongly recommend a small comment over the settings in Edit Defaults > Scripts > Run Programs, just as you have for many other settings in the UI, e.g. "The program/script specified below will be included in any script files generated from definition files".  If this is only intended to work for generated VBS and PS1 scripts, that too should be noted in this proposed comment. With the current UI, the wording of the settings "Run a program or script at the start/end" is enormously ambiguous, which is uncharacteristic of Reflect -- at the start/end of what, exactly?  Absent any clues, I would have assumed either the start/end of a job or even the launch/closure of Reflect (even if no job ran), but both would be wrong, and there's nothing on that UI page to suggest that it pertains to scripts generated by definition files. I think most users would expect that Edit Defaults would either apply application-wide or would serve to pre-populate the same setting under the definition file's Advanced Options, until they discover that the latter doesn't exist.  That was certainly my own assumption, and I consider myself intuitive and rational with things like this.

- It might be worth clarifying under Edit Defaults UI and the script generation UI whether the "end" program/script will run at the end of a Reflect job regardless of outcome or only at the end of a successful Reflect job.  Or better yet, enhance this to provide options for each, e.g. "Run after successful job", "Run after unsuccessful job", "Run after all jobs, regardless of outcome".

- Minor cosmetic bug: The comment blocks of all 3 script types that were generated say they were generated by Reflect v6, even though I did this from v7.

Edited 10 August 2017 3:49 PM by jphughan
Nick
Nick
Macrium Representative
Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)Macrium Representative (2.3K reputation)
Group: Administrators
Posts: 1.3K, Visits: 6.9K
Thanks for getting back and for your comments.

There are separate defaults for VBS and PS1 and the function could definitely be made clearer. There are no options for legacy MSDOS .BAT files that's why there aren't any defaults. Additionally,  there is no parameter passing for .bat files, unlike vbs or ps1, so backup types cannot be dynamically chosen at run time. We strongly advise against using .bat files for automation. 

Example generated .bat file:  http://knowledgebase.macrium.com/display/KNOW7/_Example_MS-DOS_Batch_File
Example generated .ps1 file: http://knowledgebase.macrium.com/display/KNOW7/_Example_PowerShell_Source_File

The generated scripts are templates to then modify/fine tune and are used extensively by some of our enterprise customers.  As I mentioned previously, the OP is better served by using '<definition file name>_before_snapshot_wait.bat' logic as this is much less involved and allows xml defs to run a script rather than the other way round. 


Kind Regards

Nick - Macrium Support

Edited 10 August 2017 4:48 PM by Nick
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search