Simple script to copy the backup to another drive when done?


Author
Message
Architekt
Architekt
New Member
New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)New Member (14 reputation)
Group: Forum Members
Posts: 3, Visits: 23
I'd like to just simply copy the backup that was finished to another external drive I have. What's the simplest easiest way to do this? I attempted a test by making a VB script based off my current XML backup definition and just selected "Enable directory synchronization" in the options and setting the path to my drive, but I noticed that this copied EVERY backup file I had ever made to the drive (which didn't work because the drive ran out of space). I'm looking to only copy the backup that was JUST created. The reason for this is that I back up to my NAS which has 20TB of storage. But if I have to restore an image to my PC, it can take a long time, between the 7200RPM drives and the gigabit connection. So I wanted to only maintain the most recent backup set on my 2TB external M.2 NVMe disk that's sitting around doing nothing, directly connected to my PC via USB 3.2 gen 2. Obviously I would manually have to manage deleting files on this external drive once I make a new backup set or exceed the 2TB threshold, but that's a trivial matter.

Anyway, long story short: I just simply want to copy the last actual backup created, i.e. the last file that Macrium created, to another drive when done instead of copying/synchronizing ALL the backups/files Macrium has created. Is this possible via any of the 3 script types? And if so, how?

Edit: I think I found a way that actually might be faster overall. I set up a test using a much smaller drive, my USB thumb drive with only 500MB on it. I created a new XML file to back up this thumb drive to my external drive. I created a VB script for it and chose the directory synchronization option to sync to my NAS. But then I edited the VB script and removed the /purge option from the "robocopy" line, that way the script won't delete files on the destination directory if they don't exist on the source. So I suppose I solved my problem, albeit in a different way. Still would like to know though the answer to my question as to if it's possible to just copy solely the backup file created when done rather than sync directories. 
Edited 27 January 2022 6:54 PM by Architekt
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
Reliably copying only the backup file that was created would probably require Reflect to programmatically return the name of the file it generated during that job as a property that could be captured and used as a parameter for a file copy command, but Reflect to my knowledge doesn't do that.  Short of that, I guess you could compare the directories filtering the output to include only "source-side unique" files with the appropriate extension for the type of Reflect backup files you're generating, although that wouldn't necessarily copy ONLY the newly created backup file.  Another option might be to try parsing the generated log file to extract the name of the new backup file, but that's even uglier.

However, copying only the most recently created backup file can be very risky.  What if you were making Incremental backups and your previous copy job had failed for whatever reason?  If the next copy operation only copied the new Incremental backup generated by that specific run, then you would end up with a broken Incremental chain at the replication destination and therefore would be unable to actually USE that new Incremental over there.

Another reason it can be useful or even crucial to sync the entire directory (or at least all Reflect files) is the fact that some backup strategies involve modifying existing backup files, specifically those that use Incremental consolidation or Synthetic Fulls.  If you run a backup that uses one of those techniques and only copy the new backup to the destination without replicating the changes made to "upstream" backups, then you'll end up with an invalid set at the replication destination.

Edited 27 January 2022 10:02 PM by jphughan
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
Another option if you really wanted to do this would be to simply enumerate the contents of your destination folder and look for the Reflect backup file with the newest Date Created timestamp.  That's trivial to do in PowerShell.  It may also be trivial in VBS, but I don't write VBS.  You could add some sanity checks to make sure that the Date Created timestamp was within a certain time of the current time in order to avoid potentially grabbing a pre-existing backup in a scenario where the latest backup job had failed and therefore not generated a new file.  Or you could simply check whether the newest file in your "regular" destination folder already existed in your replication destination.

But as I said above, your overall idea has risks that would lead me to caution against it, regardless of whether you can find a reliable method to achieve what you want.

Edited 27 January 2022 10:07 PM by jphughan
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
Ok, in case you're willing to accept the risks I called out in light of the fact that this replication appears intended to create a "convenience set" for you, in which case a problem in the set wouldn't be a catastrophic, I took this on as a hack-a-thon challenge.  If you want to experiment with this, have Reflect generate a PowerShell script, specify the desired replication destination in the Synchronize Directories option, then open up the script.  Find the line that looks like this:
SynchroniseDirectories $strBackupDir '[YourReplicationDestination]';


Replace it with the snippet below, changing "mrimg" to "mrbak" if you're using F&F backups instead of image backups, and also changing the path to your replication destination as needed:
$NewestBackup = Get-ChildItem $strBackupDir -file | where {$_.Name -like "*.mrimg"} | sort CreationTime -Descending | select -first 1
$ReplicationDest = 'D:\MyBackups'


Finally, mostly for fun, I wrote snippets for each of the options I described above.  You'll only need to use one or the other.  Option 1 checks whether the newest backup is less than 8 hours old and copies it to the replication destination if it is, or does nothing if it's older than that.  (The assumption is that a backup older than 8 hours would be a pre-existing backup if the latest backup job failed.  If you use auto-verify on your backups, make sure you consider how long the verification will take.)  Option 2 checks whether the newest backup at your regular destination already exists at the replication destination.  If it doesn't, then it copies it.  If it does, then it does nothing.  Note that if the file DOES already exist at the replication destination, my snippet does NOT compare sizes or contents of those two copies to determine whether they are identical.  It's a pure check for a file of the same name.

Add the script lines from ONE of the two options below to the snippet from above:

Option 1
if ($NewestBackupDate.CreationTime -gt ((Get-Date).AddHours(-8)))
{
  Copy-Item $NewestBackup $ReplicationDest
}


Option 2
if ($NewestBackup.Name -NotIn (Get-ChildItem $ReplicationDest -File).Name)
{
  Copy-Item $NewestBackup $ReplicationDest
}


Edited 27 January 2022 10:47 PM by jphughan
JK
JK
Macrium Hero
Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)
Group: Forum Members
Posts: 1.5K, Visits: 6K
JP, I'm starting to dip my toes into the replication/scripting space, and thought this topic presented an opportunity to learn more, so I would appreciate your take on the following:

Is it possible to identify/filter source backup files based on their IMAGEID?  It seems that a more robust way to accomplish OP's goal would be something like robocopy using /XO and maybe /MIR options, if one could filter the files to include only the most recent backup set (Disclaimer: I know very little about robocopy, so my proposal may be way off).  If this is possible to do, I think it would reduce (eliminate?) the risk of ending up with an unusable backup set at the destination, while achieving the original goal of copying only the most recent backup file each time.



                                
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
Unless you find a way to parse the metadata of the backups themselves, how reliably you'd be able to identify all and only files that are part of a common set would depend on your backup file naming convention.  That's especially true with Reflect V8's significantly expanded naming options and the ability to disable the image set ID, in which case there could conceivably be no file name commonality between backups of the same set at all.  But if you DID have the image set ID in your file names, you could extend what I did above to identify the newest backup, extract the Image ID portion of its name, and then select all OTHER files with names that contained that string.  But then you'd have to feed that to Robocopy.  I don't know if Robocopy supports receiving a string array as a source parameter to specify a list of files to copy (the Copy-Item cmdlet does), but if not, I suppose you could write a loop that ran Robocopy as many times as needed to copy one file at a time.

This incidentally would be another use case that would greatly benefit from my Wish List thread requesting a Reflect PowerShell module.

Edited 27 January 2022 11:51 PM by jphughan
JK
JK
Macrium Hero
Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)
Group: Forum Members
Posts: 1.5K, Visits: 6K
I believe that robocopy would be able to use a file name inclusion mask of the form EC397FD071CF7957*.mrbak, for example, so it seems like my idea would be workable if the IMAGEID prefix is enabled.  However, I was hoping for a way to access the ID from metadata.  I had (naively) assumed that any metadata accessible by Windows Explorer would also be accessible programmatically through batch, powershell, or VBS script commands.

                                
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
There may be a way to do it, especially in PowerShell where you have .NET available, but if there is, I don't know how to do it.  If memory serves, I think @RayG found a way to retrieve at least some of the data available in the Macrium Reflect tab of the Windows Explorer Properties dialog in a PowerShell session, but I can't find that right now, and I don't remember how much of that content was retrievable or how much complexity it involved.

JK
JK
Macrium Hero
Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)Macrium Hero (2.4K reputation)
Group: Forum Members
Posts: 1.5K, Visits: 6K
Are you referring to the posts by RayG, RefDM and Froggie towards the end of the following thread?
https://forum.macrium.com/42676/RE-Please-publish-a-way-to-catch-the-backup-method-used-for-an-existing-backup-file

Looks promising, but a bit intimidating.

                                
jphughan
jphughan
Macrium Evangelist
Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)Macrium Evangelist (22K reputation)
Group: Forum Members
Posts: 14K, Visits: 85K
That’s the one, and yes that was my recollection as well. Smile
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Reading This Topic

Login

Explore
Messages
Mentions
Search