Copy Data Script

Reading Time: < 1 minute

Copy the below script to a notepad and amend paths and exclusions. Rename file to .bat e.g. Copy.bat

Test before applying to a real environment. The below script will only COPY. For additional switches see https://cloudbuild.co.uk/?p=1224

:START

SET robo_path=C:\Windows\System32\robocopy.exe
SET source_dir=”\\server\share
SET dest_dir=”\\server\share
SET log_fname=\\server\share\BackupReportLog.txt

REM See the robocopy documentation for what each command does.
REM /COPY:DAT :: COPY file data, attributes, and timestamps
REM /COPYALL :: COPY ALL file info
REM /B :: copy files in Backup mode.
REM /MIR :: MIRror a directory tree
REM /L :: Just list the info, don’t actually do it
SET what_to_copy=/COPY:DAT

REM Exclude some files and directories that include transient data
REM that doesn’t need to be copied.
SET exclude_dirs=/XD “Temporary Internet Files” “Cache” “Recent” “Cookies” “iPod Photo Cache” “MachineKeys” “All Users” “Default User” “LocalService” “NetworkService” “Application Data” “Local Settings” “My Recent Documents” “NetHood” “PrintHood” “SendTo” “Templates”
SET exclude_files=/XF *.bak *.tmp index.dat usrclass.dat* ntuser.dat* *.lock *.swp

REM Refer to the robocopy documentation for more details.
REM /R:n :: number of Retries
REM /W:n :: Wait time between retries
REM /LOG :: Output log file
REM /NFL :: No file logging
REM /NDL :: No dir logging
REM /E   :: Include Empty Subdirectories
REM /XA:H :: Excludes files with hidden attribute
REM /XJ :: Exclude Junction Points (prevents recursive Application Data loop in Vista)
SET options=/R:1 /W:1 /LOG+:%log_fname% /NFL /NDL /E /XJ

REM Execute the command based on all of our parameters
%robo_path% %source_dir% %dest_dir% %what_to_copy% %options% %exclude_dirs% %exclude_files%

:END