Use Robocopy to copy files on Windows Server

Posted by

Robocopy is a robust file copy command for the Windows command line. It allows users to copy files, directories, and even drives from one location to another. It can be automated with Task Scheduler to run at specific times.

Robocopy example to copy a file from Source to Destination:

Format:

Robocopy [Src] [Dest] [filename] [options]

Src: Can be local or UNC path

Dest: Can be local or UNC path

Code Sample batch file:

SET DTVARYEAR=%Date:~10,4%
SET DTVARMONTH=%Date:~4,2%
SET DTVARDATE=%Date:~7,2%


echo Sync Started

Robocopy C:\Data\TestFolder C:\Data\Logs\TestFolder\%DTVARYEAR%-%DTVARMONTH%-%DTVARDATE%_TestFolder testlogfile.log /FFT /Z /XA:H /LOG+:C:\Data\SchedTasks\LogsTest\%DTVARYEAR%-%DTVARMONTH%_AppLogs.txt 

echo  Log synced

The above code will copy the testlogfile.log from Source to Destination.

Options:
/FFT Assumes FAT file times (two-second precision).
/Z Copies files in restartable mode.
/XA:H exclude hidden file
/LOG+ log output to file and append.

Additional useful options:
/MIR Mirrors a directory tree (equivalent to /e plus /purge).
/XF exclude specified file
/XD exclude specified directory

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.