Robocopy Batch Script
@ECHO OFF SETLOCAL SET _source=\\Server1\Share1 SET _dest=D:\Shares\Share2 SET _what=/ZB /E :: /COPYALL :: COPY ALL file info :: /ZB :: Use restartable mode; if access denied use Backup mode :: /SEC :: copy files with SECurity :: /E :: Copy Subfolders, including Empty Subfolders. :: /PURGE :: Delete dest files/folders that no longer exist in source. :: /MIR :: MIRror a directory tree - equivalent to /PURGE plus all subfolders (/E) SET _options=/R:5 /W:5 /XO /TEE /ETA /NDL /NP /LOG:RoboCopyLog.txt :: /R:n :: number of Retries :: /W:n :: Wait time between retries :: /LOG :: Output log file :: /TEE :: Output to console window, as well as the log file :: /NFL :: No file logging - don’t log file names :: /NDL :: No dir logging - don’t log directory names ROBOCOPY %_source% %_dest% %_what% %_options%
Robocopy Powershell Script
# Define paths
$source = "\\Server1\Share1"
$destination = "D:\Shares\Share2"
$logFile = "$PSScriptRoot\RoboCopyLog.txt"
# Robocopy options
$robocopyOptions = "/ZB /E /R:5 /W:5 /XO /TEE /ETA /NDL /NP /LOG:`"$logFile`""
# Run Robocopy
Start-Process -FilePath "robocopy.exe" -ArgumentList "`"$source`" `"$destination`" $robocopyOptions" -Wait
# Email parameters
$EmailParams = @{
To = "receiver@mail.com"
From = "robocopy@mail.com"
Subject = "Robocopy Backup Completed"
Body = "The Robocopy backup has completed. See attached log."
SmtpServer = "smtp.int.aller.eu"
Port = 25
UseSsl = $true
Attachments = $logFile
}
# Send email
Send-MailMessage @EmailParams