Created
October 24, 2019 21:18
-
-
Save tylerapplebaum/0520bd4281a2d6c4b0acce72b160b89d to your computer and use it in GitHub Desktop.
Robocopy wrapper to mirror directory to backup drive. Includes path validation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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