Skip to content

Instantly share code, notes, and snippets.

@tylerapplebaum
Created October 24, 2019 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerapplebaum/0520bd4281a2d6c4b0acce72b160b89d to your computer and use it in GitHub Desktop.
Save tylerapplebaum/0520bd4281a2d6c4b0acce72b160b89d to your computer and use it in GitHub Desktop.
Robocopy wrapper to mirror directory to backup drive. Includes path validation.
#https://social.technet.microsoft.com/wiki/contents/articles/1073.robocopy-and-a-few-examples.aspx
#http://www.luisrocha.net/2008/12/robocopy-error-error-5-0x00000005.html
#Robocopy switches used:
#/MIR - mirror directory structure (including empty)
#/COPY:DT - excludes copying permissions
#/XA:H - excludes hidden files
#/W:5 - wait 5 seconds on a failure
#/XJD - exclude junction points
Function Sync-Documents {
param(
[Parameter(HelpMessage="Specify the source path to data you wish to copy",Mandatory=$True)]
[ValidateScript({Test-Path $_ -PathType Container})]
[string]$SourceDir,
[Parameter(HelpMessage="Specify the destination path of data to be copied to",Mandatory=$True)]
[System.IO.FileInfo]$DestDir
)
robocopy.exe $SourceDir $DestDir /MIR /COPY:DT /XA:H /W:5 /XJD
}
Sync-Documents -SourceDir "C:\Users\$env:username\Documents" -DestDir "W:\My Documents\Documents-Backup"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment