How to use Robocopy to run differential copies once a full backup is completed?

llarava
llarava used Ask the Experts™
on
Hi,

I have two USB disk attached to a server. I have copied all the data from disk E: to disk F: I want now to setup Robocopy in order to run diferential copies from E: to F:

The goal would be to use a batch or vbs to run robocopy and the right switches in order to copy all the changes.  Once I have the script I will run a scheduled task.

Could someone help me out.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017

Commented:

the same definition you use to copy the entire data first,

robocopy e:\ F:\ * /E /copy:dat

You could use the /mon:number_of_changes or /mot:numberof_minutes_before_retries

http://www.mydigitallife.info/2007/05/07/robocopy-syntax-command-line-switches-and-examples/

Author

Commented:
I have copied the data with copy/paste. Would this "robocopy e:\ F:\ * /E /copy:dat" copy the incremental changes that will occur on a daily basis on disk F: to disk F: ?

incremental changes from disk e: to f:

robocopy e:\ F:\ * /XO  (as in eXclude Older)
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Distinguished Expert 2017

Commented:
The copy and paste altered the timestamps such that F: will likely reflect all files as being on the copy date.

robocopy will automatically check whether the source file is newer than the file at the destination and will overwrite it when it is.

I do  not believe you need to use the /XO option.
Try a test  run by adding a /L to the command provided earlier.
It will list what it would do but without performing the copying task.

The main question deals with /COPY i.e. what are the security settings that you want to maintain for the copy.

Author

Commented:
I found this script which is perfect to do what I wanted to do. I ran it and ALL the data was copied from E: to F:\backups as expected.

I would like to modifiy the switches so that only incremental changes are copyed over once the script is executed.

Any idea on how to add the switches that were suggested to the script?

@ECHO OFF
SETLOCAL
 
SET _source=E:\
 
SET _dest=F:\backups
 
SET _what=/COPYALL /B /SEC /MIR
:: /COPYALL :: COPY ALL file info
:: /B :: copy files in Backup mode.
:: /SEC :: copy files with SECurity
:: /MIR :: MIRror a directory tree
 
SET _options=/R:0 /W:0 /LOG:MyLogfile.txt /NFL /NDL
:: /R:n :: number of Retries
:: /W:n :: Wait time between retries
:: /LOG :: Output log file
:: /NFL :: No file logging
:: /NDL :: No dir logging
 
ROBOCOPY %_source% %_dest% %_what% %_options%

Open in new window

Distinguished Expert 2017

Commented:

Remove the /B option.
Run with the /L option the example I provided and you should see that only modified files will be copied.

No purging of deleted files will take place.

Author

Commented:

I have adde the /L to the script but it does not work, however just forget about the script.

For simplicity I will just use the command you have suggested.  

Here is what I have done:

1.) Copy the data over from E: to F: (copy/paste)
2.) Create a new file on the source E:  
3.) Run the following command "robocopy e:\test F:\backups\test * /L"

This is the output that I am getting (see the file attached)

I am not sure if the output indicates that there is a new file it does not look clear to me.

/L seems to list but not to copy how do I run the incremental copy?

Thank you
7-2-2010-10-56-28-AM.jpg

Author

Commented:
robocopy e:\test /MIR /NP F:\backups\test

So far this seems to work. The first time it copies all the files and the next time it runs it copies only those that have been changed on the source to the target.  

Author

Commented:
Does someone know how can I get the output from the command line window copied to a log file once the job is completed.
Distinguished Expert 2017

Commented:
You can use the /LOG:"path_and_filename"

To test you should run
robocopy e:\ f:\backup * /E /L

The output will include all the files in E:\ that are already on F:\backup but will not copy them. The new entries will be referenced as new directory new file, etc.
The problem with the test you tried is that you went into a subdirectory with a single file which means that it only needs to create the directory and then copy the file.

Note the use of the /MIR option will remove files that are not in the source but are at the destination.

Author

Commented:
I have made done the setup as follows:

robocopy e:\test /MIR /NP F:\backups\test /LOG:C:\logs\logfile.txt

However this will overwrite the existing log from previous jobs

Is there a way to keep the existing logs? I think this will do it however I am not sure how does the switch works.

/LOG+:file : Output status to LOG file (append to existing log).
Distinguished Expert 2017

Commented:
You can use system variables i.e. %date% %time% as part of the name
/MIR will remove files that are present at the destination, but not at the source.
Try:
robocopy e:\test /MIR /NP F:\backups\test /LOG:"C:\logs\logfile-%date% %time%.txt"

Author

Commented:
Here is output I get when I run the command:

robocopy e:\ /MIR /NP F:\backups /LOG C:\logfile-%date% %time%.txt"

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
-------------------------------------------------------------------------------

  Started : Tue Jul 06 16:24:55 2010

   Source - e:\
     Dest - F:\backups\

    Files :
  Options : /S /E /COPY:DAT /PURGE /MIR /NP /R:1000000 /W:30

------------------------------------------------------------------------------

ERROR : Invalid Parameter #5 : "/LOG"

       Simple Usage :: ROBOCOPY source destination /MIR

             source :: Source Directory (drive:\path or \\server\share\path).
Distinguished Expert 2017

Commented:
The format should be:
robocopy source destination pattern [options]

The below deals with reformating the %date% output string to replace the space with an underscore as well as converting the / which is being interpreted by robocopy as options into -
within your script prior to calling robocopy:
set date_variable=%date:/=-%
set date_variable=%date_variable: =_%
The above will convert the Tue 07/06/2010 into Tue_07-06-2010
then run
robocopy e:\  f:\backups * /MIR/NP /L /LOG:c:\logfile-%date_variable%.log

note the addition of /L just to make sure it works before you run it.
This will generate a new log file as long as the script is run once a day.

Author

Commented:
Hi,

This is what I the bat file contains:

set date_variable=%date:/=-%
set date_variable=%date_variable: =_%
robocopy e:\ f:\backups * /MIR/NP /L /LOG:c:\logfile-%date_variable%.log

However I am still getting the same error message.

C:\Documents and Settings\Administrator.SYRACUSE\Desktop>robocopy e:\ f:\backups
 * /MIR/NP /L /LOG:c:\logfile-Wed_07-07-2010.log

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows     ::     Version XP010
-------------------------------------------------------------------------------

  Started : Wed Jul 07 09:25:38 2010

   Source - e:\
     Dest - f:\backups\

    Files : *

  Options : /COPY:DAT /R:1000000 /W:30

------------------------------------------------------------------------------

ERROR : Invalid Parameter #4 : "/MIR/NP"

       Simple Usage :: ROBOCOPY source destination /MIR

             source :: Source Directory (drive:\path or \\server\share\path).
        destination :: Destination Dir  (drive:\path or \\server\share\path).
               /MIR :: Mirror a complete directory tree.

    For more usage information run ROBOCOPY /? or read Robocopy.Doc.

NOTE: Read "True Replication" in Robocopy.Doc prior to first use of /MIR !
****  /MIR can DELETE files as well as copy them !

Any ideas of what am I doing wrong?
Distinguished Expert 2017
Commented:
Yes, you are missing the space between the /MIR and /NP options.
ERROR : Invalid Parameter #4 : "/MIR/NP"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial