Automate Windows Server Backup using DiskShadow and Rsync …

We have a number of Netgear ReadyNAS devices across our offices. All of these run nightly Rsync backup jobs back to a ReadyNAS 516 in head office. The 516 device also does a daily snapshot of the shares. Note that as most of our offices utilise ADSL, we had to manually transport a copy of the data to head office. Now the backup jobs just synchronise changes. This works reasonably well and provides some rudimentary historical offsite backup for the remote offices.

It proved somewhat more difficult to work out how to achieve the same result with our Windows Servers. These are primarily 2008R2 but we still have 1 x 2003 and 1 x 2012R2.

I had a look at variety of programs such as DeltaCopy and Yintersync but could not seem to get them to talk to the ReadyNAS Rsync server. Or get the ReadyNAS to talk to them. Yintersync looked really interesting but did not seem to suit my set up with the NAS devices. Also, I was not sure how these would work with open files such as Exchange and SQL Server database files.

Eventually, I stumbled across this page:

This seemed to offer an interesting option. Not having done much with shadow copies, i soon discovered that since Server 2008 (i think), DiskShadow is now the command-line tool for working with shadow copies.

Anyhow, to cut a long story short, I ended up with this DiskShadow script, imaginatively called “DiskShadowScript.cmd”:

#DiskShadow script file
set context persistent nowriters
set metadata C:\BW\DiskShadowBackup\
set verbose on
begin backup
add volume c: alias SystemVolumeShadow
expose %SystemVolumeShadow% x:
exec C:\cwRsync\BackupScript.cmd
unexpose x:
end backup
#End of script

You will notice that this calls an rsync script to synchronise the shadow copy with the rsync server. This is the rsync script minus the incriminating details:

C:\cwRsync\rsync.exe -rltv --exclude-from="/cygdrive/C/cwRsync/ExcludePatterns.txt" --log-file="/cygdrive/C/Logs/Rsync/BackupScript.log" "/cygdrive/X/" "ip-address::backup-mel/sp1/C/"

Obviously, we replace ‘ip-address’ with an actual ip address like

You will also see that I am using rsync from cwRsync. This is the free version available here:

I’m tossing up whether to purchase the other one but not sure if I need the extra features and support etc.

I then wrapped this up in a PowerShell script that sends me an email when finished, with the backup log attached. I schedule this to run daily using the Windows Task Scheduler. Here is the PowerShell script:

Import-Module C:\BW\Powershell\Modules\SendMail
# Create a disk shadow and rsync to Melbourne
DiskShadow /s "C:\BW\DiskShadowBackup\DiskShadowScript.cmd"
# Set up email
$dtToday = ((Get-Date).dateTime).tostring()
$strSubject = "SP1 Rsync Report - $dtToday" 
$strBody = "report attached."
$strSender = "noreply@domain"
$strRecipient = "me@domain"
$Attachment = "C:\Logs\Rsync\BackupScript.log"
# Send the email
SendMail $strSubject $strBody $strSender $strRecipient $Attachment

The ‘SendMail’ is a function defined in a module. Here is the module:

Function SendMail($strSubject, $strBody, $strSenderEmail, $strRecipientEmail, $AttachFile)
 $strSMTP = "smtp-server" #Change this to your SMTP/Exchange server
 $MailMessage = New-Object System.Net.Mail.MailMessage
 $SMTPClient = New-Object System.Net.Mail.smtpClient
 $ = $strSMTP
 $Recipient = New-Object System.Net.Mail.MailAddress($strRecipientemail, "Recipient")
 $Sender = New-Object System.Net.Mail.MailAddress($strSenderemail, "Sender")
 $MailMessage.Sender = $Sender
 $MailMessage.From = $Sender
 $MailMessage.Subject = $strSubject
 $MailMessage.Body = $strBody
 if ($AttachFile -ne $null) {$MailMessage.attachments.add($AttachFile) }

The PowerShell scripts were basically copied from these pages with some modification:

Thanks again to all those that take the time to blog or post on the internet.


One comment

  1. It looks like SMB 3.0 supports remote differential compression. I’m not sure how it works in practice, though.

    SMB 3.0 has some very nice features:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: