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

http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en

 

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

http://support.microsoft.com/kb/968929

http://www.microsoft.com/downloads/details.aspx?FamilyId=f002462b-c8f2-417a-92a3-287f5f81407e&displaylang=en

 

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 = "192.168.3.10"

## 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