Using BEMCLI to automate restores

We use Symantec Backup Exec for backups are some of our larger clients. Of course we have monitoring set up on these backup sets and jobs. We monitor when they fail, we have a verification phase to check if the content in the backup is correct and matches the data from the snapshot of the server, But of course this is not enough.

If you need absolute certainty that a backup is correct there is only ONE true way of testing it. Restore the backup to a different location and test if the restore jobs are able to run, For this we use the BEMCLI. The BEMCLI is a set of Powershell cmdlets that you can import on the backupexec machine itself and send powershell based commands to the server.

Lets build a very simple restore test, First we import the module BEMCLI to make sure we get all the BEcommands, a complete list of commands and a help file can be found here

import-module BEMCLI
Submit-BEFileSystemRestoreJob -FileSystemSelection C:\RestoreFolder -AgentServer Testserver.testdomain.local -NotificationRecipientList me@mycompany.com -RedirectToPath \\BACKUPEXECSERVER\Restore

Lets dissect the command a little:

  • ***S****ubmit-BEFileSystemRestoreJob*** simply means we want to start a restore job, as we do not have any date filter we want to try the restore from the latest backup set.
  • -FileSystemSelection C:\RestoreFolder is the folder we would like to restore data from.
  • -AgentServer is the server where C:\RestoreFolder is located.
  • -NotificationRecipientList me@mycompany.com I think this speaks for itself. What contact should be notified about this job. šŸ™‚ Please note that this needs to be an existing recipient within the backupexec notification options!
  • -RedirectToPath \\BACKUPEXECSERVER\Restore And of course, we want to put the files in a different location and not overwrite our existing copy, To do this I always create a ā€œRestoreā€ share to dump the files on.

Of course you can schedule this script using task schedulder and be done with it, you always restore C:\RestoreFolder…But that doesn’t sound like a good test does it? Always restoring the same file in a backup…Of course not! šŸ˜‰ So that why we’ll now select a random file(not folder!) to restore.

import-module BEMCLI
$file = Get-ChildItem -Recurse -File \\Testserver.domain.local\c$\ Get-Random -count 1
Submit-BEFileSystemRestoreJob -FileSystemSelection $file.fullname -AgentServer Testserver.testdomain.local -NotificationRecipientList me@mycompany.com -RedirectToPath \\BACKUPEXECSERVER\Restore

Of course the command is mostly the same as before, but the file selection is now random by using get-childitem and get-random. We select 1 random file from the server using its UNC path.(\\Testserver.domain.local\c$\). All you have to do is make sure the account you run this script under has the correct permissions, and of course that the FilesystemCollection object is in your backup selection list.

Happy restoring!

Recent Articles

The return of CyberDrain CTF

CyberDrain CTF returns! (and so do I!)

It’s been since september that I actually picked up a digital pen equivalent and wrote anything down. This was due to me being busy with life but also my side projects like CIPP. I’m trying to get back into the game of scripting and blogging about these scripts. There’s still so much to automate and so little time, right? ;)

Monitoring with PowerShell: Monitoring Acronis Backups

Intro

This is a monitoring script requested via Reddit, One of the reddit r/msp users wondered how they can monitor Acronis a little bit easier. I jumped on this because it happened pretty much at the same time that I was asked to speak at the Acronis CyberSummit so it kinda made sense to script this so I have something to demonstrate at my session there.

Monitoring with PowerShell: Monitoring VSS Snapshots

Intro

Wow! It’s been a while since I’ve blogged. I’ve just been so swamped with CIPP that I’ve just let the blogging go entirely. It’s a shame because I think out of all my hobbies it’s one I enjoy the most. It’s always nice helping others achieve their scripting target. I even got a couple of LinkedIn questions asking if I was done with blogging but I’m not. Writing always gives me some more piece of mind so I’ll try to catch up again. I know I’ve said that before but this time I’ll follow through. I’m sitting down right now and scheduling the release of 5 blogs in one go. No more whining and no more waiting.