Here’s a little powershell script I used to solve a problem where I needed to synchronize MILLIONS of files quickly and be notified about it promptly once the operation has complete.
Normally, I’d take machine snapshots or something but this backup is native and sadly, it happens at the file level; it also requires a Microsoft OS to run natively on bare-metal. rsync isn’t fast enough as-tested. However, 128 threads of robocopy flies right through it!
Robocopy starting with Windows Vista *SHOULD* support multiple concurrent threads with the /MT switch.
# PowerShell Robocopy script with e-mail notification # Created by Michel Stevelmans - http://www.michelstevelmans.com # needed moar variables and threads [http://jcph.am edit] # Change these values, name your job, configure the paths $job = "BLAH" $DateAndTime = get-date -UFormat "%Y%m%d_%H%M%S" $SourceFolder = "F:\REPORTS" $DestinationFolder = "\\UNC_PATH\TO\SHARE\REPORTS" $Logfile = "C:\LogFiles\$job-$DateAndTime.log" $EmailFrom = "email@example.com" $EmailTo = "firstname.lastname@example.org" $EmailBody = "Robocopy Job: $job completed successfully. See attached log: $Logfile for details" $EmailSubject = "Robocopy Summary: $job for $DateAndTime" $SMTPServer = "some.smtp.server" $SMTPPort = "25" # Copy Folder with Robocopy Robocopy $SourceFolder $DestinationFolder /R:1 /W:1 /MT:128 /MIR /XX /LOG:$Logfile /NP /nfl /ndl # Send E-mail message with log file attachment $Message = New-Object Net.Mail.MailMessage($EmailFrom, $EmailTo, $EmailSubject, $EmailBody) $Attachment = New-Object Net.Mail.Attachment($Logfile, 'text/plain') $Message.Attachments.Add($Attachment) $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, $SMTPPort) $SMTPClient.Send($Message)