Tuesday, August 7, 2012

Using Powershell and Robocopy to setup your Backup replication and email alerts

If you do not have Robocopy installed you will need to download and install it such as

-Windows 2003 Resource Kit Tools for a 2003 server or HomeServer



Next you need to install powershell 2.0 on the server you are using:




Next you need to allow unsigned scripts to do this:

C:\powershell.exe set-ExecutionPolicy unrestricted

To verify you can view the setting

C:\powershell.exe get-ExecutionPolicy


You then should copy or create your batch files and/or scripts that are easily modified

robocopy source destination /MIR /r:3 /w:1

dir destination > scripts location

here is an example:

robocopy e:\ f:\ /MIR /r:3 /w:1

dir "e:\*">c:\scripts\DriveCopy.txt

powershell.exe c:\scripts\RoboCopyEmail.ps1


here is an example of the RoboCopyEmail.ps1 script I use:

## Define the variables for smtp server, from address, to address, subject and message body

$emailFrom = "administrator@server.org"

$emailTo = "backup@server.org"

$subject = "Backup Mirroring Operation Complete"

$body = "Please confirm file dates below if no information below copy may not have completed properly"

$body = $body + "`r`n`r`n`r`n"

$body = $body + [string]::join([environment]::NewLine,(get-content c:\Scripts\DriveCopy.txt))

$smtpServer = ""

## Initiate sending a message to the IT group.

$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$smtp.Send($emailFrom, $emailTo, $subject, $body)


Shared credit: Tim Lewis, Daryl Hunter

No comments:

Post a Comment