Automated Backup with Robocopy, PowerShell and Symcon

Some time ago I started to learn PowerShell a little more and when it comes to dealing with copy processes, I stumbled upon Robocopy, again. This time I decided to get familiar with it and use Robocopy together with PowerShell to automate my backups.

I got rid of my high power consuming server as a 24/7 machine and built a power saving server while using the old one for virtualization and backup purposes. So the goal was a two step backup approach: from the clients to the 24/7 machine (where IP Symcon is hosted) on a daily basis and on weekly basis from the 24/7 machine to the archive server which also has two HBAs.

The automation was supposed to include boot and shutdown of the target archive server.

Additionally I wanted to log into IP Symcon in order to trace the backup status (last backup, success timestamp, error message). For this purpose I already created a blog post dealing with JSON RPC from PowerShell to Symcon.

Having the backup information available in IP Symcon does not only provid
e an overview but could also be used to push messages to mobile devices on backup success. I will write another post about this soon…

 

I tried to illustrate the process in the following figure:

 

Backup from Client to 24/7 Server

I am using a very simple PowerShell script here and this is rather minimalistic than advanced:

Any errors which may occur during the copy process are logged to the .log file but it is not further handled. This could definitely be scripted better though.

I used a computer group policy to start the script on a shutdown/restart as described here: http://stackoverflow.com/a/18747578

  1. Run gpedit.msc (Local Policies)
  2. Computer Configuration -> Windows Settings -> Scripts -> Startup or Shutdown -> Properties -> Add

 

Backup from 24/7 Server to Archive

Here comes the main part where all the pieces are put together.

First we need to wake the archive server if it is not online yet.

I found a very good working PowerShell snippet on Jeff Wouters’s blog here , so all the credit belongs to him.

The script we will need is the one I used in one of my previous blog posts and which can be used to make JSON Remote Procedure Calls. As mentioned before, the approach is based on a script I found here.

The two scripts above are the dependencies for the main script which is scheduled through IP Symcon, these are dot-sourced in the BackUps.ps1 . I leave the comments I wrote when dealing with Robocopy as well as the witch case for the error codes. Maybe it is useful for others.

You need to adjust all the parameters in the first two regions, such as the Symcon URL, user name, password, Symcon variable IDs and paths.

 

Scheduling the Backups with IP Symcon

The Powershell script could be executed with the windows task planner for instance. I used IP Symcon however, to keep things in one place and learn something new.

As you see, the IPS_ExecuteEx method is starting a .bat process instead of the PowerShell script directly. Unfortunately I couldn’t execute the .ps1 directly in this method.

The first boolean value of the IPS_ExecuteEx method determines whether a window of the program to be started should be shown or not. This is helpful when it comes to debugging/testing.

For the sake of completeness, here is the no brainer line of the .bat:

Now you can just use the IP Symcon default methods for scheduling the backups on regular base such as weekly or daily.

This is how it looks like in the WebFront…you could also schedule the backup through the frontend 🙂

 

P.S. I know there are a lot of different possibilities when it comes to backups but as I wanted to learn more PowerShell I decided to go this way combined with Robocopy (as this provides sync capabilities compared to new-item copy method of PS)

Hope it may be useful for some others.

Cheers!

No Comment

You can post first response comment.

Leave A Comment

Please enter your name. Please enter an valid email address. Please enter a message.