Script to back up latest backup image


Author
Message
boshiume
boshiume
New Member
New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)
Group: Awaiting Activation
Posts: 3, Visits: 8
Hello everyone,
as I am not familiar with scripting at all I would like to ask the experts in this forum if they could offer me a solution for the following situation:
Via backup definition files in Macrium Reflect v7, I am running a couple of simple back routines. Those routines generally cover folders and certain files which are then stored as *.mrbak-files in a different partition.

My idea is to take only the latest backup image and to move it to an external storage. So basically I would like to create another backup definition file which targets the latest backup image (timestamp-wise) and copy it to my external storage.

Is this possible to do with a script?

Thank you very much in advance!
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
It's trivial to write a script that says, "Find the MRBAK file with the most recent Date Created/Modified timestamp and copy that to somewhere else."  The problem is that there are several backup strategies where doing that won't achieve what you want and might not even get you a usable backup set on the destination.  These backup strategies are the ones that involve Incremental retention policies that trigger "consolidation" of older backups when newer backups are created.  Consolidation involves modifying the contents of previous backups on which the new backup would depend, so a) just copying the new backup to another location wouldn't be sufficient to make it usable, and b) the most recently modified backup could be the updated version of that older backup, not the new backup that was just created.  And then there's the issue that a simple copy script won't ever delete anything at the destination.

One option you might want to consider and that Reflect already supports is to simply sync the entire backup destination folder to another location.  This is called directory synchronization, and it's handy because it ensures that your entire set of backups is replicated, which avoids dependency problems I just described, and it also causes any deletions to be replicated as well rather than new backups just piling up forever at the secondary location.  If you want to look into this setup, simply right-click your existing definition file and select "Generate PowerShell script".  In the wizard that pops up, select Directory Synchronization, and in there specify the path to the secondary target you want to replicate your backups over to.  From that point on, make sure you run scheduled or on-demand backups by calling the SCRIPT (which you'll find under the PowerShell Scripts tab), not the definition file.  If you have multiple definition files, I'd suggest setting up a corresponding script for each one, even if you've got all of them backing up to the same destination folder.

boshiume
boshiume
New Member
New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)
Group: Awaiting Activation
Posts: 3, Visits: 8
Hi jphughan,

thank you very much for your detailed explanation. I think I can follow your thoughts, but I am uncertain if the offered solution is what I am really looking for.

I am backing up my photo archive and they need to be secured as a full back up. In my understanding the synchronization strategy that is explained in Macrium's help file "Backup Folder Synchronization", and I think you are refering to that, is not what I am trying to achieve.
The second option is some sort of mirroring two directories, I guess. The problem with that is the amount of space reserved in both of the destinations.

- Source A
- Destination 1 for Backup A (Destination 1 only keeps one full backup file)
- Destination 2 for Back A-Z (Destinatin 2 keep all full backup files)

I would like to have a method that automizes the step between Destination 1 to Destination 2.

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, got it.  Well if you'll only be making Full backups and you really just want the latest Full to be copied over from the original backup destination to the secondary destination, without ever deleting anything on the destination, here's a PowerShell script that will check the source folder, select the most recently created Full F&F backup, and copy it to a specified destination.  Note that if you run it multiple times and it selects the same file each time, the source file will be copied each time, overwriting the destination file each time.  It won't do anything fancy like check whether a copy of that file already exists at the destination, then check whether they're identical, and skip the copy if so.  All of that is technically possible, but it's more complicated.  But if this is all you want, just copy/paste the snippet below into Notepad, enter the correct source and destination paths for your setup, and save the file with a PS1 extension rather than the default TXT.  If you want to get to a point where this runs automatically after each Reflect backup, you could either have Reflect generate a PowerShell script that calls your definition file and then drop this snippet into the correct location of that script, or else save this as its own PowerShell script, then during the wizard where Reflect generates a script, provide this script as a post-backup application to run.  I can help with either if you'd like, but first I'd suggest verifying that this does what you want on its own.

$SourceFolderPath = "C:\MyBackups"
$DestinationFolderPath = "D:\MyBackups"
$LatestFullBackup = Get-ChildItem $SourceFolderPath -File | where {$_.Name -like "00-00.mrbak"} | sort CreationTime -Descending | select -First 1
Copy-Item $LatestFullBackup $DestinationFolderPath


Edited 31 December 2020 7:52 PM by jphughan
boshiume
boshiume
New Member
New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)New Member (12 reputation)
Group: Awaiting Activation
Posts: 3, Visits: 8
Hi again, jphughan,

thank you so much! This is exactly what I needed, pretty primitive, but works perfectly for me. Many thanks!

A good start into the new year for you!

Cheers

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
Happy to help!  Let me know if you need anything else, and Happy New Year to you 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