A highly modified Reflect Powershell file with added facilities


Author
Message
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
Please feel free to use as you desire.

The script does not require an administration enabled account. Macrium Reflect will pop up a UAC prompt when it is invoked from the script. Everything else the script does does not require admin privs.

PS D:\> D:\Reflect\Manual_Backup.ps1 -help

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,
           provided that a full backup is not required due to file naming options or
           limitations imposed by Macrium Reflect.
-diff      Will override the default action and carry out a differential backup,
           provided that a full backup is not required due to file naming options or
           limitations imposed by Macrium Reflect.
-shutdown  Will execute a shutdown at the end of the backup just carried out
           regardless of what else is happening.
-hibernate Will cause the system to hibernate at the end of the backup just carried out
           regardless of what else is happening.
-suspend   Will cause the system to suspend at the end of the backup just carried out
           regardless of what else is happening.
-Modify    Will allow you to modify the settings that were applied when the script was
           first run against a backup XML definition.
-RunOncePerDay
           Will check the last successful run date and exit, doing nothing if that date
           is todays date.
-Comment "<string>"
           This will add your comment to the backup file as a reminder of why the
           backup was run Macrium Reflect will manage the maximum length of the string.
-DefaultComment "<string>"
           This is a default and will always be added to the comment field of a backups
           Macrium Reflect will manage the maximum length of the combined comment strings.
           Entering a null string e.g. "" will clear the existing default comment.
-FileName "<string>"
           Will add the <string> to the backup file name. At the same time this will force
           the next backup to be a full backup. A maximum of 40 Characters is allowed.
           The default backup file name is the XML file name without the .XML plus the date
           and time of the last full backup e.g. MyBackup #YYYY-MM-DD-HH-MM#-nn-nn.mrimg.
           The -FileName option will change the name to:
           MyBackup #YYYY-MM-DD-HH-MM <string>#-nn-nn.mrimg.
           This name will be the base for any incrementl or differential until the next
           full backup when the default name is re-instated.
-Delay "<option>"
           This will add a delay before the script processes the backup request. This is to
           allow a boot time schedule to run, but giving the system time to start before adding
           an additional startup load by running a backup while the system is still booting.
           The <option> is in the format of: "<m>:<s>" where <m> and <s> are: "Minutes:Seconds",
           There is no check on the size of the values entered but they must be integers.
-DriveAdd "<drive path>"
           This allows you to add another drive to the XML defintion file and the same backup will
           be carried out to that device. All the parameters regarding file retention will be unique
           to that device. The option should be entered in this format: -DriveAdd "Z:\"
           i.e. it must be in the form of a valid path
-DriveRemove "<drive letter>"
           This will remove a previously defined drive in this XML file. e.g. -DriveRemove "Z"
-DriveChange "<drive letter>"
           This will set as the default a previously defined drive in this XML file. e.g. -DriveChange "Q"
-DriveList This will list the currently defined drives that exist in this XML file
-EventLog "<option>"
           Requires a formatted string and outputs the events according to the option contents.
           [-EventLog Newest:2] will show the last two days of events for this task's backups.
           [-EventLog Date:21-01-2016] will show the events on this date for this task's backups.
   -Format Specifically applies to -EventLog and causes the output to be formatted in a different way.
           e.g. -EventLog Newest:2 -Format or -EventLog Date:21-12-2015 -Format.
-ResetXML  Will remove all the additional items added by this script, returning it to its original state
           as near as possible but you may still want to review the settings by editing the XML definition
           in Macrium Reflect.
-Help      Will output this information.

You can also use "get-help <your path>\Manual_Backup.ps1" to get a detailed explanation of
Which parameters can be used together and which cannot.

No parameters are required by default. If none are given the script will carry out the next logical
backup, be that a Full, Differential or Incremental depending on the settings.

Script completed with an exit code of: [0]
PS D:\

I have tested this script and it works just fine with MR V6, that said there may be issues that I have no catered for due to the configuration of your system. One things it does not cater for at this time is backup up to a share where the path is a UNC path e.g. \\server\dir... So long as it is a drive letter it should work OK. You will need to rename the content of the zip file to the same name as your xml file so if your xml file is called data.xml then rename manual_backup.ps1 to data.ps1. When it runs for the first time it will output some information and ask questions. It will make a copy of the original XML file.

Please let me know if you have any issues and post the error (if that is the issue) that powershell outputs along with the XML file if appropriate.

I am open to additions but I do have limited time and cannot promise how long it may take to implement them.

An example of the first run output and questions:
PS D:\> D:\Reflect\MacriumTesting.ps1

This is the first time this script has been run against this backup definition XML file
since the file was either initially created or subsequently modified by Macrium Reflect.

You will be asked some questions that will require some extra values to be added
to the backup definition XML File, in order that this script can carry out your
requirements each time it is run. A copy of the original XML File will be created.

You will need to know how many incremental backups you would like after a full
backup has been completed, before a differential backup is executed. You will then
need to say how many differential backups you would like before the next full backup
is created.

The next question will be to ask how many full backups you would like to keep.
There will be at least this number of full backup files when a sufficient number of
backups (Fulls, Incrementals and Differentials) have been run.

You will then need to say how many full sets should be kept. This is a full backup
plus all the incrementals and differentials have taken place. However once subsequent
full backups have been completed and the total number of incrementals has been
exceeded, this will cause the oldest incremental to be deleted/merged. As things progress
differentials will also be deleted.

You can set zero values for the Incrementals and/or Differentials.
If set to zero no backups of that type will be executed.

Setting both incrementals and differentials to zero will result in full backups only
being created.

The current backup storage location is: [V:\Macrium\MacriumTest\]

Where a default is shown you can just hit "return" to accept the default value.

How many Incremental backups before the next Differential backup (default is: [0]) [0-50]?: 2
How many Differential backups before the next Full backup (default is: [0]) [0-50]?: 2
How many Full backups do you want to keep (default is: [0]) [1-20]?: 4
How many complete backup sets do you want to keep every Full, Diff and Inc (default is: [0]) [0-4]?: 2
Do you want to save a text files with the backup details in the backup folder (Y/y, N/n)?: y
Do you wish to add a default comment?
Note: This comment will be added to all backups and e-mails regardless of any other comments (Y/y, N/n)? : n
Your backup Free Space management is currently off, would you like to turn it on (Y/y, N/n)?: y
The Average file size of your full backups is: [3.6 MB]
Your Free Space Threshold is currently: [2]GB, Do you want to adjust this value (Y/y, N/n)?: n

These settings will mean that there will be a full backup to start with, followed by
2 incremental backups, followed by a differential backup. This will be repeated
2 times and then a new full backup will be created.

You want to keep 2 complete sets, every Full, Differential and Incremental.
This will require: 4 Differentials and 8 Incrementals to be kept
in addition to 4 Full backup files.

Free Space Management is turned on with a threshold of 2 GB.

When free space goes below the defined value the oldest backup file(s)/file sets will
be deleted recursively until sufficient space is available.

Your default comment is: []

Your text file required is: [Y]

The above (in green) is the result of the answers you have given.

If acceptable type [Y]es to continue, otherwise type [N] to try again.
Type [Q]uit to exit with no changes. (Y/y, N/n, Q/q)?: y

The necessary changes have been made.

Please run the script again to execute a backup.


====================


1). Drive: [V] Label: [Video] Directory: [V:\Macrium\MacriumTest\]
    UniqueID: [4f004956-23dc-2c43-aedd-301bf783b090]
    Last run date and time: 2016-04-30 15:23

====================

Backup destination drive and directory is: [1). Drive: [V] Label: [Video] Directory: [V:\Macrium\MacriumTest\]]

To change the current default please run the script with "-DriveChange <letter>" option

Note: The date and time for a newly added drive will be the current date and time
      and not the date and time of the last backup run

Script completed with an exit code of: [0]
Press Enter to continue...:
PS D:\>


Note: to use -DriveChange there must be more that one defined drive in the XML file -DriveAdd <drive> will add a second drive to the XML. e.g.
PS D:\> D:\Reflect\MacriumTesting.ps1 -drivelist

====================


1). Drive: [V] Label: [Video] Directory: [V:\Macrium\MacriumTest\]
    UniqueID: [4f004956-23dc-2c43-aedd-301bf783b090]
    Last run date and time: 2016-04-16 18:17


2). Drive: [R] Label: [Macrium F&F] Directory: [R:\Macrium\MacriumTest\]
    UniqueID: [a3aa9702-c12d-11e5-861f-00019510a995]
    Last run date and time: 2016-04-07 16:59


3). Drive: [E] Label: [FC 500GB(3)] Directory: [E:\Macrium\MacriumTest\]
    UniqueID: [7fa49166-29e2-11e4-82bd-00019510a995]
    Last run date and time: 2016-04-14 09:25


4). Drive: [E] Label: [FC 500GB(1)] Directory: [E:\Macrium\MacriumTest\]
    UniqueID: [f2c3cb0e-6111-11e4-832f-00019510a995]
    Last run date and time: 2016-04-17 15:23

====================

Backup destination drive and directory is: [4). Drive: [E] Label: [FC 500GB(1)] Directory: [E:\Macrium\MacriumTest\]]

Script completed with an exit code of: [0]
PS D:\>

So the same backup will run to the currently selected drive with all its own values and retention settings, select the correct destination using -DriveChange


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

Attachments
Manual_Backup_V0-9-3-6.zip (4 views, 28.00 KB)
Edited 30 April 2016 4:34 PM by RayG
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