robocopy and windows 2008 r2

Posted on 2011-02-28
Medium Priority
Last Modified: 2012-05-11

I have been playing around with Windows 2008R2's built-in robocopy command line tool to handle by "file sync" from local machine onto a remote machine.

It all works fine, but I am confused as to how I would get a few other things to work..

Below is the command I am using:

robocopy "E:\SQL Backups\VAN-SQL02" "\\VAN-BACKUP\Automated Backup\VAN-SQL02" /E /COPY:DAT /DCOPY:T /MIR /V /NP /LOG:"E:\SQL Backups\BackupSync.log" /NDL /NC /TS /B /R:3 /W:60 /MT:3

Open in new window

I added the /NDL switch for No Directory List, but it still shows up in the log?

Also, is there a way to rotate the log file? Anyone have this working? I don't want to appent; but rather overwrite each time the back-up runs.. however I would like to preserve a set amount of logs (7 days or so).

This is used to move the local SQL backups (database and transaction logs), to a remote server which then is copied to tape.

One thing I would also like to experiment with is having the script run on a Windows Task Scheduler every 15 minutes, and sync any new changes to the source directory (which would be transactions that are backed up every 20 minutes by a stored procedure, and back-ups once a night).

Having the Scheduling Manager run on a 15 minute timer ensures me that the transaction logs are being moved off the server continuously and also the nightly back-ups.

Which robocopy option is best for that? /MOT:20 or ?

Finally, should would it be better to schedule two jobs and making use of /XF to exclude databases in one, and transactions in the other; so that they are discreet (transaction sync and backup sync).

Thanks for your help in this matter.
Question by:mirde
  • 3
  • 2
LVL 23

Accepted Solution

Malli Boppe earned 1000 total points
ID: 35004249
change the script as below so that a seperate log is generated every day.

rem      ### Set Date Format ###
FOR /f "tokens=2-4 delims=/ " %%a in ('DATE /T') do set Date=%%c-%%b-%%a
set datenow=%date%
robocopy "E:\SQL Backups\VAN-SQL02" "\\VAN-BACKUP\Automated Backup\VAN-SQL02" /E /COPY:DAT /DCOPY:T /MIR /V /NP /LOG:E:\SQL Backups\%datenow%.log /NDL /NC /TS /B /R:3 /W:60 /MT:3

I wouldn't use /MOT switch but just schedule to run every 20 minutes.
I don't think you need 2 jobs one job should be fine.But I don't think you can copy the SQL databases through robocopy as if the file is in use the robocopy job fails.

Expert Comment

ID: 35005855
I too use a 'for' statement to grab today's date in order to write out log files in a similar manner.

If you want to clean logs up after 7 days, try the small resource kit tool 'forfiles.exe' with the following command:

>forfiles /p pathname /D -7 /c "cmd /c del /s /q @file"

Author Comment

ID: 35010011

Thanks for that I will try it, I am backing up the "backed-up" files of our SQL Server, I have a script that goes in and does the back-up; and places them in a directory; robocopy is used only to transfer the files to another server.

I could of used SQL SSIS to do this, but robocopy seems to have all the bells I need for the job.

The back-up files will not be locked, they only way I can see it fail is if robocopy tries to copy while back-up is in progress; in which case it will fail but succeed in the next run (20min).
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.


Author Comment

ID: 35010044
mboppe, anyway to have a notification sent to the exchange server through the batch?
LVL 23

Expert Comment

by:Malli Boppe
ID: 35012432
These are the scripts that I am using.But need to make sure that the copy process finishes off on the same day.I mean to say uf you start the job on 02/03 it shoudl finish of on the same day.
Also you need to allow email relay for the server which is running the script.So in your case your SQL server should be able to relay emails.

Author Closing Comment

ID: 35112603
Works just as I wanted it, thanks for your help.

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
"Any files you do not have backed up in at least two [other] places are files you do not care about."
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question