Use PowerShell to run XML Backup Definition Files in Sequence


Author
Message
warrenrh
warrenrh
New Member
New Member (18 reputation)New Member (18 reputation)New Member (18 reputation)New Member (18 reputation)New Member (18 reputation)New Member (18 reputation)New Member (18 reputation)New Member (18 reputation)New Member (18 reputation)
Group: Forum Members
Posts: 7, Visits: 26
I would like to use PowerShell to run about a dozen XML Backup Definition Files in sequence (one after the other).  Each of the Backups would perform an Incremental Backup. 
Here is an early partial attempt.
For each of my XML Backup Definition Files - I used Reflect to create a a PowerShell file.
Then I have a PowerShell script to run each of those PowerShell scripts.

Invoke-Expression "C:\RHWMain\MacriumReflectfiles\RHWMain.ps1 -inc" 
Invoke-Expression "C:\RHWMain\MacriumReflectfiles\RHWThunderbirdProfiles.ps1 -inc"
Invoke-Expression "C:\RHWMain\MacriumReflectfiles\RHWInfrequent.ps1 -inc"
Invoke-Expression "C:\RHWMain\MacriumReflectfiles\RHWSeldom.ps1 –inc"

I would like to use PowerShell to run each of my dozen or so XML Backup Definition Files directly instead of a ps1 PowerShell script, which was created from the XML.
I suspect I can use PowerShell to execute Reflect.exe and passing to it the XML file,
and perhaps an argument such as –inc , indicating the type of backup.  
But I don't know how.  This is my first attempt at using PowerShell. Can you help me?
RayG
RayG
Advanced Member
Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)
Group: Forum Members
Posts: 241, Visits: 1.1K
I have just written a script which will allow you to pass the parameters you want and run the XML file it applies to you can pass the following as show by the help it will output. You are welcome to give it a try.

The following command line switches can be passed to this script:
-full      Will override the default action and carry out a full backup
-inc       Will override the default action and carry out an incremental backup
-diff      Will override the default action and carry out a differential backup
-shutdown  Will execute a shutdown at the end of the backup just carried out
    -force can be given along with -shutdown to force a shutdown regardless of
           what else is happening
-hibernate Will cause the system to hibernate at the end of the backup just carried out
-suspend   Will cause the system to suspend at the end of the backup just carried out
-modify    Will allow you to modify the settings that were applied when the script was
           first run against a backup XML definition
-comment   This will add your comment to the backup file as a reminder of why the
           backup was run
-help      Will output this information

As for running a script to run all your other scripts etc. You can have a Powershell files with lines like this:
=====
D:\Reflect\Data.ps1 -diff
D:\Reflect\OtherBackup -inc -comment "anything you want to write"
D:\Reflect\Win10-x64.ps1 -shutdown
=====
Where the PS1 files it invokes are the script I have written with a name the same as the XML file you defined in MR - both need to be in the same directory.
If you pass my script no parameters with respect to inc/diff/full it will run the next appropriate backup given the answers you supplied when it was run against the XML file for the first time.



Regards
RayG
Windows10 X64 V1803 B17134.228 MR v7.1.3317

Edited 22 January 2016 5:49 PM by RayG
RayG
RayG
Advanced Member
Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)
Group: Forum Members
Posts: 241, Visits: 1.1K
A better way of doing this is:
$StrArgs=""
$Proc=New-Object System.Diagnostics.ProcessStartInfo "PowerShell.exe"
$Proc.Arguments = "-ExecutionPolicy Bypass & '" + "D:\Reflect\Data.ps1" + "' $StrArgs";
[System.Diagnostics.Process]::Start($Proc)

The code block above should be in a Powershell file and point at the Powershell file that can be exported from Macrium Reflect
If you want to run multiple backups repeat the code block and change the target file (
D:\Reflect\Data.ps1).
If you want to pass parameters change the $StrArgs to define the parameters e.g.
$StrArgs="-param1 value -param2 value"

adding as many parameters as required to carry out your required actions.
If a parameter requires quotes (") around it preceed each " with with a single backquote (`)

$StrArgs="-param1 value -param2 `"value`""

Alternatively surround the whole string with single quotes (')
$StrArgs='-param1 value -param2 "value"'





Regards
RayG
Windows10 X64 V1803 B17134.228 MR v7.1.3317

Edited 30 April 2016 4:47 PM by RayG
Richard V.
Richard V.
Most Valuable Professional
Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)
Group: Forum Members
Posts: 2K, Visits: 8K
I may be wrong, but my impression is that the proposed solutions are all much more complicated than they really need to be.

Unless I missed something, Reflect's own user interface can be used to create a script (either PowerShell or VBScript) based on the first backup task definition to be run.  You can then simply edit that script (again, within the Reflect user interface) to add other task definitions in whatever sequence you wish using the same syntax that invokes the first backup task call.  The backup function contained in the script that Reflect creates also includes the required 'wait on completion' parameters for each backup task.

If you wish, you can also schedule that single script to run the entire sequence specifying whatever backup type (Full, Diff, or Inc) is wanted within the scheduled command.


Regards, Richard V. ("Arvy")
https://forum.macrium.com/uploads/images/afc5d4fe-5d25-4e25-be94-185e.png

Edited 30 April 2016 5:09 PM by Arvy
RayG
RayG
Advanced Member
Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)Advanced Member (497 reputation)
Group: Forum Members
Posts: 241, Visits: 1.1K
Arvy, I found that MR did not do quite what I wanted so invested some time in trying to achieve what I wanted. Scheduling is fine but in my experience it nearly always got in the way of what I was doing. I like to run a backup when I want and if it is at the end of the day I can run a script and walk away knowing that the system will shutdown when its done. I can sort out what if any issue there are later.


Regards
RayG
Windows10 X64 V1803 B17134.228 MR v7.1.3317

Richard V.
Richard V.
Most Valuable Professional
Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)Most Valuable Professional (4.1K reputation)
Group: Forum Members
Posts: 2K, Visits: 8K
I understand that you may have some special requirements necessitating greater complexity, but the issue here is what will best meet the OP's needs keeping in mind his last line which I took as a plea for something as uncomplicated as possible:
But I don't know how.  This is my first attempt at using PowerShell. Can you help me?

If the capabilities provided by Reflect itself can do what warrenrh requires, he'd be well advised to stay within those bounds IMO.


Regards, Richard V. ("Arvy")
https://forum.macrium.com/uploads/images/afc5d4fe-5d25-4e25-be94-185e.png

Edited 30 April 2016 5:55 PM by Arvy
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