Unmounting drive after the image is done


Author
Message
Albator56
Albator56
Junior Member
Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)
Group: Forum Members
Posts: 44, Visits: 147
I don't know much about xml, but how could we unmounting drive after the image is done.
jphughan
jphughan
Most Valuable Professional
Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)
Group: Forum Members
Posts: 3.2K, Visits: 22K
It's not XML you'd need to know.  The XML file is the Reflect backup job description and isn't touched.  The scripting comes in when you right-click the definition file and choose to generate either a VBScript or PowerShell script that CALLS that file, and then you can add whatever you want before or after that call as long as you know VBScript or PowerShell.  However, you may want to take a look at the reply I posted in the Features section before you go too far down this path.  If the answer there isn't enough and you still want to do something like this, I may be able to come up with something useful on the PowerShell side, but first can you confirm you're backing up to a locally attached disk rather than a network location?  If you're going to the network via mapped drive letter, you could simply switch to a UNC path so you'd never need it mounted at all.  If you're going to a physical disk and want to unassign the drive letter after the job completes (and obviously reassign it before the job begins), I can probably help with that, although I'd need to tinker around myself for a bit to figure out the correct syntax for finding the right partition based on ID.

Albator56
Albator56
Junior Member
Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)Junior Member (82 reputation)
Group: Forum Members
Posts: 44, Visits: 147
jphughan - 11 August 2017 4:25 PM
It's not XML you'd need to know.  The XML file is the Reflect backup job description and isn't touched.  The scripting comes in when you right-click the definition file and choose to generate either a VBScript or PowerShell script that CALLS that file, and then you can add whatever you want before or after that call as long as you know VBScript or PowerShell.  However, you may want to take a look at the reply I posted in the Features section before you go too far down this path.  If the answer there isn't enough and you still want to do something like this, I may be able to come up with something useful on the PowerShell side, but first can you confirm you're backing up to a locally attached disk rather than a network location?  If you're going to the network via mapped drive letter, you could simply switch to a UNC path so you'd never need it mounted at all.  If you're going to a physical disk and want to unassign the drive letter after the job completes (and obviously reassign it before the job begins), I can probably help with that, although I'd need to tinker around myself for a bit to figure out the correct syntax for finding the right partition based on ID.

Thanks, it's a external hdd on USB. but I did set in device management a drive letter assigned to it. letter "M". But there is no rush on this. 
jphughan
jphughan
Most Valuable Professional
Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)
Group: Forum Members
Posts: 3.2K, Visits: 22K
EDIT: Got it.  See below.

Edited 11 August 2017 6:01 PM by jphughan
jphughan
jphughan
Most Valuable Professional
Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)
Group: Forum Members
Posts: 3.2K, Visits: 22K
SIMPLER VERSION -- for people not using a disk rotation. If you are, see next post.

Requirements:
- Must be running Windows 8 / Server 2012 or newer.
- Destination must reside on storage classified as a fixed disk (i.e. hard drive/SSD, including USB-attached), not on storage classified as removable media (most USB flash drives), due to a limitation in the Get-Partition cmdlet.

1. Get the Volume ID of your destination by opening PowerShell Console and entering this, substituting your target's drive letter where I have X:
Get-Volume -DriveLetter X | select UniqueID

2. Copy/paste that Unique ID string somewhere temporarily -- not the heading and the line of hyphens, just the line with the ID.

3. In Reflect, right-click your definition file and choose to generate a PowerShell script. The default settings here should be fine.

4. You'll find your new script under the PowerShell Files tab.  Go over there, right-click it, and select Edit.  This should open PowerShell ISE or Notepad. If not, manually open the script file in Notepad.

5. Find this block in the script:
function Main()
{
Write-Host 'PowerShell script for Macrium Reflect Backup Definition File';
Write-Host "BDF: $strXmlFilePath";
Elevate;

$iExitCode = Backup;


6. In the convenient blank line underneath "Elevate;", add the line below, substituting the Volume ID you grabbed in Step 2 for the one I have below AND substituting the correct drive letter for X.  Make sure you do NOT remove the single quotes around the volume ID path, NOR the accent character after the drive letter:
Get-Volume -UniqueID '\\?\Volume{e996321a-d723-4197-b4b3-fbaf45d50d52}\' | Get-Partition | Add-PartitionAccessPath -AccessPath "X`:" -ErrorAction SilentlyContinue

(NOTE: The "-ErrorAction SilentlyContinue" parameter is there because this command would otherwise fail with an error if the destination already had a letter assigned when it ran, e.g. if non-Reflect access had been required or if the PC was restarted and the automatically assigned letter had not been manually removed. I would rather have this command fail silently and then potentially cause the Reflect job to fail due to an incorrect/missing drive letter instead of introducing a new possible error source into Reflect's pre-made script.)

7. In the convenient blank line underneath "$iExitCode = Backup;", add the line below, again substituting your drive letter in both places where I have X.  Again, make sure to maintain all extra punctuation around the second occurrence:
Remove-PartitionAccessPath -DriveLetter X -AccessPath "X`:\" -ErrorAction SilentlyContinue

8. Save your changes and close PowerShell ISE/Notepad.

9. You will now need to associate your backup schedule entries to this SCRIPT file in Reflect, NOT your definition file.  Do that by right-clicking the script file in Reflect, selecting "Schedule", and setting everything up.  Then go over to the Definition Files tab, right-click the definition file, select "Schedule", and remove all of those.  You do of course need to keep the definition file itself since the script refers to it.

10. To make sure this works, manually remove your target's drive letter using Disk Management, and then either wait for a scheduled Reflect job or open Reflect, right-click the script file (not definition file!) and select "Run Now".

NOTE: If you restart your PC, the partition will be assigned a drive letter again.  If you want to DEFAULT your backup destination partition to not receiving a drive letter when the disk is mounted, there is a way to do that using diskpart.  The process is a slightly different depending on whether the partition resides on an MBR or GPT disk, but this can obviously create some confusion/convenience issues if any less technical users will ever need to use this disk and just expect it to work.

Enjoy!

Edited 11 August 2017 8:32 PM by jphughan
jphughan
jphughan
Most Valuable Professional
Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)Most Valuable Professional (4.6K reputation)
Group: Forum Members
Posts: 3.2K, Visits: 22K
DISK ROTATION VERSION -- if you are not using a disk rotation, the post above has a simpler setup

Requirements:
- Must be running Windows 8 / Server 2012 or newer.
- Destination must reside on storage classified as a fixed disk (i.e. hard drive/SSD, including USB-attached), not on storage classified as removable media (most USB flash drives), due to a limitation in the Get-Partition cmdlet.
- I believe this will work regardless of whether or you use the "Alternative locations" feature or have been ensuring that each disk is always assigned a specific drive letter when connected through other means, and also regardless of whether you use Reflect's default drive letter targeting or volume ID-based targeting.

1. Get the Volume IDs of all of your possible destinations by opening PowerShell Console and entering the command below, substituting the drive letter assigned to each target where I have X. Run the command as many times as necessary to gather all Volume IDs:
Get-Volume -DriveLetter X | select UniqueID

2. Copy/paste those Unique IDs somewhere temporarily -- not the heading and the line of hyphens, just the line with the ID.  Optionally, note which Volume ID corresponds to which target, e.g. "Monday disk", because you will have an opportunity later to include those notes in the script to ease management going forward, e.g. if you add/remove disks from your rotation.

3. In Reflect, right-click your definition file and choose to generate a PowerShell script. The default settings here should be fine.

4. You'll find your new script under the PowerShell Files tab.  Go over there, right-click it, and select Edit.  This should open PowerShell ISE (far preferable) or Notepad. If not, manually open the script file in Notepad

5. Find this block in the script:
function Main()
{
Write-Host 'PowerShell script for Macrium Reflect Backup Definition File';
Write-Host "BDF: $strXmlFilePath";
Elevate;

$iExitCode = Backup;


6. In the convenient blank line underneath "Elevate;", add the lines below, substituting your Volume IDs from Step 2 for the ones I've shown below. If you need to add or subtract lines, make sure that each Volume ID is encased in single quotes as shown and that a comma is placed just after the closing single quote on each line EXCEPT for the last Volume ID line.  The # I've included at the end of each line indicates that everything to the right is a comment, so this is where you can add descriptions for each of the Volume IDs to help keep track of which ID corresponds to which disk in your rotation if you'd like -- just make sure to preserve the #.  Finally, in the last line beginning "Get-Volume", substitute the letter X for the drive letter you wish to use, making sure to preserve the accent character after the drive letter. If you're using Volume ID targeting in Reflect, this choice is arbitrary, but you must choose something that will be available.
[string[]]$AllUniqueIDs =
'\\?\Volume{4a08dd5d-d782-4508-94b6-2719d252f8f7}\', #Monday disk
'\\?\Volume{584fb5c3-946b-4f21-a7d7-214b3e0e9b52}\', #Wednesday disk
'\\?\Volume{e996321a-d723-4197-b4b3-fbaf45d50d52}\' #Friday disk

$UniqueID = (Get-Volume | where {$AllUniqueIDs -contains $_.UniqueID} | select -first 1).UniqueID

Get-Volume -UniqueID $UniqueID | Get-Partition | Add-PartitionAccessPath -AccessPath "X`:" -ErrorAction SilentlyContinue

(Notes: The "select -first 1" command above ensures that only one target is selected.  If multiple disks in your rotation are available, the first one enumerated by the Get-Volume cmdlet will be used, NOT necessarily the first disk in your list of Volume IDs. There's probably a way to achieve the latter, but typically disk rotations only ever have one disk connected at a time, so I'm opting for simplicity here. The "-ErrorAction SilentlyContinue" parameter is on the last line because that command would otherwise fail with an error if the destination already had a letter assigned when it ran, e.g. if non-Reflect access had been required or if the PC was restarted and the automatically assigned letter had not been manually removed. I would rather have this command fail silently and then potentially cause the Reflect job to fail due to an incorrect/missing drive letter instead of introducing a new possible error source into Reflect's pre-made script.)

7. In the convenient blank line underneath "$iExitCode = Backup;", add the line below, again substituting the drive letter you chose above for both places on this line where I have X.  Again, make sure to maintain all extra punctuation around the second occurrence:
Remove-PartitionAccessPath -DriveLetter X -AccessPath "X`:\" -ErrorAction SilentlyContinue

8. Save your changes and close PowerShell ISE/Notepad.

9. You will now need to associate your backup schedule entries to this SCRIPT file in Reflect, NOT your definition file.  Do that by right-clicking the script file in Reflect, selecting "Schedule", and setting everything up.  Then go over to the Definition Files tab, right-click the definition file, select "Schedule", and remove all of those.  You do of course need to keep the definition file itself since the script refers to it.

10. To make sure this works, manually remove your target's drive letter using Disk Management, and then either wait for a scheduled Reflect job or open Reflect, right-click the script file (not definition file!) and select "Run Now".

NOTE: If you restart your PC, the partition will be assigned a drive letter again.  If you want to DEFAULT your backup destination partition to not receiving a drive letter when the disk is mounted, there is a way to do that using diskpart.  The process is a slightly different depending on whether the partition resides on an MBR or GPT disk, but this can obviously create some confusion/convenience issues if any less technical users will ever need to use this disk and just expect it to work.

Enjoy!

Edited 11 August 2017 8:32 PM by jphughan
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