Group: Forum Members
I took this up as a hack-a-thon challenge for another user who wanted a way to specify a pattern of backup types to run, but did not wish to use a formal schedule. The user wanted to be able to run backups purely on-demand but have Reflect know what type of backup should be run next. I'm sure that from a programming standpoint this isn't the most ELEGANT way to achieve that end result, but what I built is nonetheless easy to set up, manage, and adjust/override as needed. Implementation instructions below:
- Create a simple text file defining at least one full iteration of your desired backup type pattern/sequence. Use "Full", "Diff", and "Inc" as the type names, and place exactly one backup type per line. Reflect will loop through this pattern. Place a ">" (no quotes) at the beginning of the line that you would like to define as the NEXT backup to run, e.g. in case you have existing backups and want to start this off in the middle of your pattern. The example pattern file below will have Reflect create a Full, then a Diff, then 4 Incs before returning to creating a Full -- but the NEXT job that runs will be the first Incremental in the pattern, based on the position of the >:
- Save this file somewhere that Reflect will have access to it. I recommend saving it in the same folder as the XML definition file with which you'll be using it. Name it whatever you want, e.g. "MyPatternFile.txt".
- Open the Before-iExitCode.txt file attached to this post. Customize the first line beginning $PatternFilePath to specify the path to the pattern file you just created, then just keep that open for a moment.
- In Reflect, go to the Backup Definition Files tab, right-click the desired definition file, and select "Generate a PowerShell Script File". There's no need to adjust any of the default settings in this dialog, though you can if you want to. Choose to save the script it in a location that will be convenient for you to access, since you will use this script to run your backups, then click OK.
- Right-click that newly generated PS1 script file and select Edit to open PowerShell ISE.
- Find the line in the script that reads "$iExitCode = Backup;", then copy the contents of that Before-iExitCode attachment (with the modified $PatternFilePath line) and paste it all into the empty line directly ABOVE that $iExitCode line in the script.
- Open the After-iExitCode.txt file attached to this post. Copy its contents and paste it all into the empty line directly BELOW that $iExitCode line in the script.
- Save your updated script.
- Run backups as desired by right-clicking the script file and selecting "Run with PowerShell" and accepting the UAC prompt (which occurs because Reflect itself requires admin privileges). The script will check the pattern file to determine what type of backup should be created next, tell Reflect to create that backup, and then if the backup completes successfully, it will move the ">" to the next line down in the pattern file, or to the top line if the ">" was already at the bottom line.
- If you ever wish to adjust your pattern, simply edit your pattern file as desired. And if you ever wish to deliberately jump to a different point in your pattern, simply move the ">" to the desired location. Just make sure that there is only ever one ">" anywhere in the file.
- If Reflect itself overrides your backup type selection, e.g. you wanted an Incremental and it decided it had to create a Full, then the script will still simply move the ">" in your pattern file as it would have if Reflect had performed the backup type you actually requested. This might mean that your ">" is no longer at the point in your pattern that you might want based on the backups that you now actually have. In that case you will have to manually move the ">" within your pattern file to put Reflect "back on track". There isn't an easy way to detect when Reflect performed a different backup type than requested, and even if there were, trying to guess what custom behavior the user might want for repositioning the ">" in their pattern file in such a situation would be impractical.
I wrote the script so that if there is a problem with the pattern file, e.g. it cannot be found or its contents are invalid, then the script will exit, in which case no Reflect backup would be performed. I did this because if the desired backup type cannot be determined, then assuming any particular type could be dangerous because it could trigger purges based on your retention policy that you may not have wanted to occur at that time. If you would prefer the script NOT to exit in cases of problems with the pattern file, then you can remove or comment out the 3 occurrences of the "exit 1" lines in the Before-iExitCode portion of the script. In that case, manually running the script as I described in Step 9 when there is a problem with the pattern file would result in Reflect performing a Full backup.
If you encounter any problems, it's best to open PowerShell Console and start the script that way so that the PowerShell window remains open even after the script exits, giving you a chance to see any error messages. I built some sanity checks and error reporting into the script modifications that should hopefully assist in any troubleshooting, although this is fairly straightforward.