Answered Robocopy Scripts

  • Tuesday, December 11, 2012 2:25 PM
     
     

    I have robocopy scripts that I am running to mirror files from one server to another server on a daily basis.  The script seems to be doing what it is intended to do, but for some reason the last run result always return a 1 0r 0x1. 

    Please see the script below


    @REM Script to copy Netbackup DR FILES to secondary server
    robocopy e:\NB_CATALOG /maxage:1 /MIR \\abcdefgh01\NB_CATALOG /log:e:\NB_CATALOG\RobocopyLog\DRfiles_copy.log /TS /FP
    robocopy e:\PHI_NB_CATALOG_Store /maxage:1 /MIR \\abcdefgh01\PHI_NB_CATALOG_Store /log:e:\PHI_NB_CATALOG_Store\RobocopyLog\Catalog_copy.log /TS /FP
    exit


    what am I doing wrong?

All Replies

  • Tuesday, December 11, 2012 2:36 PM
     
     
    Are there any errors or warnings in the Catalog_Copy.log file it generates?

    Sebastian Sajaroff Senior DBA Pharmacies Jean Coutu

  • Wednesday, December 12, 2012 9:47 PM
     
     
    I am getting this error in the last run result.  I am getting either 0x1 or 0x3
  • Wednesday, December 12, 2012 10:22 PM
    Moderator
     
     

    Please copy and paste the portion of the log file that contains the errors.

    Bill

  • Friday, December 14, 2012 10:03 PM
     
     

    What log are you referring to?


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

      Started : Fri Dec 14 05:30:02 2012

       Source : e:\PHI_NB_CATALOG_Store\
         Dest : \\123abcd\PHI_NB_CATALOG_Store\

        Files : *.*
        
      Options : *.* /TS /FP /S /E /COPY:DAT /PURGE /MIR /MAXAGE:1 /R:1000000 /W:30

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

                      262 e:\PHI_NB_CATALOG_Store\
         New File     231.2 m 2012/12/14 10:02:25 e:\PHI_NB_CATALOG_Store

    \654321zyxw_1355479213_C1_F1.1355479213.img
      0.0%
      0.4%
      0.8%
      1.2%
      1.7%
      2.1%
      2.5%
      3.0%
      3.4%

     3.8%
      4.3%
      4.7%
      5.1%
      5.6%
      6.0%
      6.4%
      6.9%
      7.3%
      7.7%
      8.2%
      8.6%
      9.0%
      9.5%
      9.9%
     10.3%

    10.8%
     11.2%
     11.6%
     12.1%
     12.5%
     12.9%
     13.4%
     13.8%
     14.2%
     14.7%
     15.1%
     15.5%
     15.9%
     16.4%
     16.8%
     17.2%

    17.7%
     18.1%
     18.5%
     19.0%
     19.4%
     19.8%
     20.3%
     20.7%
     21.1%
     21.6%
     22.0%
     22.4%
     22.9%
     23.3%
     23.7%
     24.2%

    24.6%
     25.0%
     25.5%
     25.9%
     26.3%
     26.8%
     27.2%
     27.6%
     28.1%
     28.5%
     28.9%
     29.4%
     29.8%
     30.2%
     30.6%
     31.1%

    31.5%
     31.9%
     32.4%
     32.8%
     33.2%
     33.7%
     34.1%
     34.5%
     35.0%
     35.4%
     35.8%
     36.3%
     36.7%
     37.1%
     37.6%
     38.0%

    38.4%
     38.9%
     39.3%
     39.7%
     40.2%
     40.6%
     41.0%
     41.5%
     41.9%
     42.3%
     42.8%
     43.2%
     43.6%
     44.1%
     44.5%
     44.9%

    45.4%
     45.8%
     46.2%
     46.6%
     47.1%
     47.5%
     47.9%
     48.4%
     48.8%
     49.2%
     49.7%
     50.1%
     50.5%
     51.0%
     51.4%
     51.8%

    52.3%
     52.7%
     53.1%
     53.6%
     54.0%
     54.4%
     54.9%
     55.3%
     55.7%
     56.2%
     56.6%
     57.0%
     57.5%
     57.9%
     58.3%
     58.8%

    59.2%
     59.6%
     60.1%
     60.5%
     60.9%
     61.3%
     61.8%
     62.2%
     62.6%
     63.1%
     63.5%
     63.9%
     64.4%
     64.8%
     65.2%
     65.7%

    66.1%
     66.5%
     67.0%
     67.4%
     67.8%
     68.3%
     68.7%
     69.1%
     69.6%
     70.0%
     70.4%
     70.9%
     71.3%
     71.7%
     72.2%
     72.6%

    73.0%
     73.5%
     73.9%
     74.3%
     74.8%
     75.2%
     75.6%
     76.0%
     76.5%
     76.9%
     77.3%
     77.8%
     78.2%
     78.6%
     79.1%
     79.5%

    79.9%
     80.4%
     80.8%
     81.2%
     81.7%
     82.1%
     82.5%
     83.0%
     83.4%
     83.8%
     84.3%
     84.7%
     85.1%
     85.6%
     86.0%
     86.4%

    86.9%
     87.3%
     87.7%
     88.2%
     88.6%
     89.0%
     89.5%
     89.9%
     90.3%
     90.8%
     91.2%
     91.6%
     92.0%
     92.5%
     92.9%
     93.3%

    93.8%
     94.2%
     94.6%
     95.1%
     95.5%
     95.9%
     96.4%
     96.8%
     97.2%
     97.7%
     98.1%
     98.5%
     99.0%
     99.4%
     99.8%
    100% 
         New File        1024 2012/12/14 10:02:25 e:\PHI_NB_CATALOG_Store

    \654321zyxw_1355479213_C1_F1.1355479213.info
      0% 
    100% 
         New File         512 2012/12/14 10:00:21 e:\PHI_NB_CATALOG_Store

    \654321zyxw_1355479213_C1_HDR.1355479213.img
      0% 
    100% 
         New File        1024 2012/12/14 10:00:21 e:\PHI_NB_CATALOG_Store

    \654321zyxw_1355479213_C1_HDR.1355479213.info
      0% 
    100% 
         New File       3.7 g 2012/12/14 10:05:21 e:\PHI_NB_CATALOG_Store

    \654321zyxw_1355479365_C1_F1.1355479365.img
      
         New File        1024 2012/12/14 10:05:21 e:\PHI_NB_CATALOG_Store

    \654321zyxw_1355479365_C1_F1.1355479365.info
      0% 
    100% 
         New File         512 2012/12/14 10:02:51 e:\PHI_NB_CATALOG_Store

    \654321zyxw_1355479365_C1_HDR.1355479365.img
      0% 
    100% 
         New File        1024 2012/12/14 10:02:51 e:\PHI_NB_CATALOG_Store

    \654321zyxw_1355479365_C1_HDR.1355479365.info
      0% 
    100% 
         New File      241664 2012/12/14 10:05:24 e:\PHI_NB_CATALOG_Store

    \654321zyxw_1355479365_C1_TIR.1355479365.img
      0% 
     54% 
    100% 
         New File        1024 2012/12/14 10:05:24 e:\PHI_NB_CATALOG_Store

    \654321zyxw_1355479365_C1_TIR.1355479365.info
      0% 
    100% 
                        1 e:\PHI_NB_CATALOG_Store\RobocopyLog\
         Newer              0 2012/12/14 10:30:02 e:\PHI_NB_CATALOG_Store

    \RobocopyLog\Catalog_copy.log
      0% 
    100% 

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

                   Total    Copied   Skipped  Mismatch    FAILED    Extras
        Dirs :         2         0         2         0         0         0
       Files :       263        11       252         0         0         0
       Bytes : 100.750 g   3.949 g  96.800 g         0         0         0
       Times :   0:01:11   0:01:10                       0:00:00   0:00:00


       Speed :            59843055 Bytes/sec.
       Speed :            3424.247 MegaBytes/min.

       Ended : Fri Dec 14 05:31:13 2012

  • Friday, December 14, 2012 10:13 PM
     
     

    I have robocopy scripts that I am running to mirror files from one server to another server on a daily basis.  The script seems to be doing what it is intended to do, but for some reason the last run result always return a 1 0r 0x1. 

    Return code from ROboCopy tell you if anything was synced or not.

    Look in th4e manual for teh result codes meanings.

    I think 1 means files updated and 0 means not files changed.


    ¯\_(ツ)_/¯

  • Friday, December 14, 2012 10:16 PM
     
      Has Code

    The return code from Robocopy is a bit map, defined as follows:

        Hex   Decimal  Meaning if set
        0×10  16       Serious error. Robocopy did not copy any files.
                       Either a usage error or an error due to insufficient access privileges
                       on the source or destination directories.
    
        0×08   8       Some files or directories could not be copied
                       (copy errors occurred and the retry limit was exceeded).
                       Check these errors further.
    
        0×04   4       Some Mismatched files or directories were detected.
                       Examine the output log. Some housekeeping may be needed.
    
        0×02   2       Some Extra files or directories were detected.
                       Examine the output log for details. 
    
        0×01   1       One or more files were copied successfully (that is, new files have arrived).
    
        0×00   0       No errors occurred, and no copying was done.
                       The source and destination directory trees are completely synchronized. 
    

    http://ss64.com/nt/robocopy-exit.html

    New WIndows users should learn to use a search engine.  It is a great time saver. 

    I know there is a lot to this Internet stuff and Windows administration is now so mindless with the new WIndows Servers.  It  is still a good idea to try a search engine.

    Hey - did you know that you can even search from a cell phone?

    Pretty cool isn't it.


    ¯\_(ツ)_/¯


  • Monday, December 24, 2012 10:39 PM
     
     
    Okay,  I understand now the exit codes.   But,  I  now have one problem.   I run robocopy in cmd file, but it seems tha the robocopy is not exiting.  The robocopy executable and the cmd script seems to be running continuously?
  • Monday, December 24, 2012 11:03 PM
     
     
    Okay,  I understand now the exit codes.   But,  I  now have one problem.   I run robocopy in cmd file, but it seems tha the robocopy is not exiting.  The robocopy executable and the cmd script seems to be running continuously?

    That is correct. Please read all of the instructions carefully.  When you ask toMirror RoboCopy runs and monitors the folders.

    ¯\_(ツ)_/¯

  • Tuesday, December 25, 2012 9:40 PM
     
     
    Okay,  I understand that, but that is an issue.  This is because I now have multiple robocopy processes running  (2 per day) each time the scheduler run.   How do I make it mirror, but ends as soon as the copying process is over.  I don't want a bunch of robocopy processes running on the server.
  • Wednesday, December 26, 2012 12:30 AM
     
     
    Okay,  I understand that, but that is an issue.  This is because I now have multiple robocopy processes running  (2 per day) each time the scheduler run.   How do I make it mirror, but ends as soon as the copying process is over.  I don't want a bunch of robocopy processes running on the server.

    Don't mirror.  Just do a copy update.

    I run multiple copies of very large folders once a day.  I have it set to synchronize the files and folders for multiple file sets.  I generate a log that is checeked to see that the sync was complete.  The log also is a summary report of the files syncs (it is the default log).  The copied foldewrs are backed uyp to teh cloud every night.  Th elog is copied too.  The cloud service keeps 7 versions of every file.

    All of this is done based on RoboCopy syncronizing the file changes.  Mirroring is something completely different.  Mirroring is designed to move all changes as tehey occur.  RoboCopy sits listening for "change" events on a folder structure and copies updated file between the folder sets  Mirroring can be bi-directional.

    The help for RoboCopy contains very good detail for how to use RoboCopy.  Dump it to a file or download RoboCopyGUI which comes with a nice MSWord documtent of teh same help.

    The following will update all files and folders even empty folders:

    robocopy e:\sourcefolder e:\targetfolder /e

    It is a very simpole command but very powerful.  The first time it is run it will update all files.  On subsequent runs it will only update changes even though it will, by default, list a folder summary.  You can change the log settings to tell RC to report at almost any level of granularity.

    Here are the summaries:
    Summary on initial copy:

                    Total    Copied   Skipped  Mismatch    FAILED    Extras
         Dirs :         8         7         1         0         0         0
        Files :        51        51         0         0         0         0
        Bytes :   24.86 m   24.86 m         0         0         0         0
        Times :   0:00:06   0:00:03                       0:00:00   0:00:03

        Speed :             7458335 Bytes/sec.
        Speed :             426.769 MegaBytes/min.

        Ended : Tue Dec 25 19:21:01 2012

    Summary on second copy:

                    Total    Copied   Skipped  Mismatch    FAILED    Extras
         Dirs :         8         0         8         0         0         0
        Files :        51         0        51         0         0         0
        Bytes :   24.86 m         0   24.86 m         0         0         0
        Times :   0:00:00   0:00:00                       0:00:00   0:00:00

        Ended : Tue Dec 25 19:22:09 2012

    Note that the 'Copied' count is zero on the second run.

    If any file or folder is changed the stats will log that and the changes will be copied.

    It is worth spending time to master RoboCopy.  For one thing you will learn much about how Windows and the Windows File System works. It will make you a better File Server Administrator and it will provide a powerfull tool to help solve many, but not all, problems of managing large file servers.

    You must always consider DFS/DFSR and other Windows systaems when trying to survive in large systems support.  RoboCopy is a great free tool that has been around for more than 10 years and is now getting the attention.


    ¯\_(ツ)_/¯

  • Wednesday, December 26, 2012 5:49 PM
     
     

    The reason I am using the mirror switch is because I am doing need have source directory compared with destination directory.   The source directory contains netbackup images.  Netbackup automatically expires the image after the retention period and deletes it from the file system.   I want the items in the destination directory to match the source.  Essentially, if the file was deleted from the source, it should automatically be deleted from the destination.

    thanks,

  • Wednesday, December 26, 2012 6:20 PM
     
     

    The reason I am using the mirror switch is because I am doing need have source directory compared with destination directory.   The source directory contains netbackup images.  Netbackup automatically expires the image after the retention period and deletes it from the file system.   I want the items in the destination directory to match the source.  Essentially, if the file was deleted from the source, it should automatically be deleted from the destination.

    thanks,

    Go back and carefully read all of the documentation.  Look closely at the reports. Try to understand how RoboCopy and WIndows work together to use advnaced features of teh WINdows file system.  This does not work like a Unix copy program or like the old DOS copy.

    Your quesztiopn is specific to understanding and usijng ROboCopy.  It is not a scriping question.  There are numerous forums and blogs with considerable information about how RoboCopy works and how to use it.  YOu should use your search engine to locate resoiurces that are appropriate to your needs and environment.

    Here is a resync command that will update deleted files.

    robocopy e:\sourcefolder e:\targetfolder /e /mir


    ¯\_(ツ)_/¯

  • Saturday, December 29, 2012 4:03 AM
     
     

    You are very interesting mr. Jrv.   Please do not  try to insult my intelligence, because I for one pay for this service just as you do.   I sure do understand how robocopy works.   I am running this cmd script that calls robocopy.  I run the script through task scheduler, and it is doing the work as intended.  However,  it seems that robocopy executables are not terminated  because I see multiple copies of robocopy in task manager.  I have used the MIR option as well the /E and /PURGE option, and I am still having the same issue where as the robocopy executable are not terminating.

  • Saturday, December 29, 2012 4:52 AM
     
     

    I have been running this command with RoboCopy for many years.  It dos not keep running.  If it does for you then you are doing something wrong or you have a system issues.  We cannot solve this for you.

    Issues of how RoboCopy works and how to use RoboCopy are not scripting questions.

    you do not pay for this service.  It is not a support site this is a site with all volunteers.  We can point you at possible solutions.  If you system is not working correctly or if  you do not post a script then there is little we can do to help you.

    Telling you to read the documentation more carefully and to look into forums that specifically support RoboCopy is not insulting your intelligence it is assuming you can accept a suggestion for obtaining more information.

    I am sorry we cannot help you.

    Once again - the following command is run by me in multiple places to synchronize files using the task scheduler:

    robocopy e:\sourcefolder e:\targetfolder /e /mir


    Happy New Year ¯\_(ツ)_/¯

  • Saturday, December 29, 2012 5:11 AM
     
      Has Code

    Here is a nother method I have in use under task scheduler:

    I use a JPOB file so I can aeeasily alter the arguments and not have to edit the scheduler.

    The job file looks like this:

    ::
    :: Robocopy Job C:\COMPANY\WFX32.RCJ
    ::
    :: Created by Administrator on Sat Jun 09 2012 at 14:53:20
    ::
    ::
    :: Source Directory :
    ::
    	/SD:\\server1\Company\wfx32\	:: Source Directory.
    ::
    :: Destination Directory :
    ::
    	/DD:c:\company\wfx32\	:: Destination Directory.
    ::
    :: Include These Files :
    ::
    	/IF		:: Include Files matching these names
    ::		*.*	:: Include all names (currently - Command Line may override)
    ::
    :: Exclude These Directories :
    ::
    	/XD		:: eXclude Directories matching these names
    ::			:: eXclude no names (currently - Command Line may override)
    ::
    :: Exclude These Files :
    ::
    	/XF		:: eXclude Files matching these names
    ::			:: eXclude no names (currently - Command Line may override)
    ::
    :: Copy options :
    ::
    	/S		:: copy Subdirectories, but not empty ones.
    	/E		:: copy subdirectories, including Empty ones.
    	/COPY:DAT	:: what to COPY (default is /COPY:DAT).
    	/PURGE		:: delete dest files/dirs that no longer exist in source.
    	/MIR		:: MIRror a directory tree (equivalent to /E plus /PURGE).
    ::
    :: Retry Options :
    ::
    	/R:1000000	:: number of Retries on failed copies: default 1 million.
    	/W:30		:: Wait time between retries: default is 30 seconds.
    ::
    :: Logging Options :
    ::
    	/NDL		:: No Directory List - don't log directory names.
    	/NP		:: No Progress - don't display % copied.
    	/LOG:c:\company\wfx32.log	:: output status to LOG file (overwrite existing log).

    The taks scheduker run line looks like thsi:

    "C:\Program Files\Windows Resource Kits\Tools\robocopy.exe" /job:wfx32

    The default folder is set to the folder wher ethe job file is located (usually at the root of the folder set) and the log file is dumped there too.

    I can reuse this task definition and just change the folder name.  The rest is in the JOB file.

    There is absolutely no need to use a script to do this.

    Your particualr situation and requirements will cause you to have to learn to use RoboCopy and to choose a method for doing your updates.  This is how I do it for this particular requirement.  Another folder set may require that I edit the JOB file to set different parameters.  Each job has its own settings and only you can determine what they are.

    I have never had RoboCopy run endlessly on any system so I do not understand what you are doing. 

    You are generating a very large log file.  This might be causing issues if you have disk problems.  Start be reducing  the complexity of the RoboCopy.  Do not run it as a batch but as a command in the scheduler.  Log only a summary which is the default.

    If you have problems troubleshooting your issue I recommend either Microsoft support or a consultant.

    MS Support is very good.  For a single low price they will stick with you until the problem is resolved to your satisfaction.

    This forum is free and has no guarantees.  We do not do troubleshooting of user systems and I only give this advice so you will have a next step to try.  I do not know if it is applicable to your situation since I cannot see your system, the event logs or anything else that this might depend on.

    One other thing you should know. If you are getting a last run result aand a a or 2 then the task is running and terminating.  The copies of Robocopy you see may be from some other experiment.  You cannot get an termination lastresult time or code if the task is still running.

    If you use "start" to execute robocopy then this might happen or appear to happen.

    I recommend running only one copy of RoboCopy in a task without a batch file. Pick a small test folder to copy and test until you get the robocopy command correct or have determined what is causing RoboCOpy to hang (if it really is hanging).


    Happy New Year ¯\_(ツ)_/¯

  • Saturday, December 29, 2012 9:45 PM
    Moderator
     
     
    ... because I for one pay for this service just as you do. ...

    (?) This is a free peer-to-peer support forum. Although hosted on a Microsoft-owned server, this is not an "official" forum in the sense that you are guaranteed an answer or a resolution. A peer-to-peer discussion group does not come with a service level agreement.

    Bill

  • Monday, December 31, 2012 1:59 AM
     
     

    My apologies,  my research were in errors.   There were some sites that referred to using command script, but I guess that you cannot use robocopy in cmd script with task scheduler.  I am testing now with the job file.  I am using Windows Server 2008 R2.  Is the extension for a robocopy job file .rcj or.jpob.  I am really appreciating all the helps that I have received so far.

    thank you, 

  • Monday, December 31, 2012 2:44 AM
    Moderator
     
     
    but I guess that you cannot use robocopy in cmd script with task scheduler.

    That guess is incorrect, but as previously noted you don't have a scripting question.

    Bill

  • Monday, December 31, 2012 2:55 AM
     
     Answered

    My apologies,  my research were in errors.   There were some sites that referred to using command script, but I guess that you cannot use robocopy in cmd script with task scheduler.  I am testing now with the job file.  I am using Windows Server 2008 R2.  Is the extension for a robocopy job file .rcj or.jpob.  I am really appreciating all the helps that I have received so far.

    thank you, 

    I hate to send anyone away dissatisfied but it is very hard to answer you issue. It is not a scriping issue but one of how to use ROboCopy ( Na ustility program) to update a folder set.  If the utility is not working as you expect then you will have to troubleshoot the issue.  I assure youthat ROboCopy works as described in the help except for a few minor issues which do not effect you. It is my strong belief that you are not settin up the task in the scheduler correctly.  The worst thing you could do is to name a batch fiel ROBOCOPY.BAT or ROBOCOPY.CMD.  This would be disastrous.


    Happy New Year ¯\_(ツ)_/¯

  • Monday, December 31, 2012 6:21 AM
     
     Proposed Answer

    I think the issue is that when you execute a robocopy command with the /MIRror switch, that that instance keeps running. Then when you run that command from within a batch script that is started by the task scheduler, you need to either modify your script to avoid running when an instance is already running, or to cancel the previous instance.


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

  • Monday, December 31, 2012 6:29 AM
     
     

    I think the issue is that when you execute a robocopy command with the /MIRror switch, that that instance keeps running. Then when you run that command from within a batch script that is started by the task scheduler, you need to either modify your script to avoid running when an instance is already running, or to cancel the previous instance.


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    Another great possibility.

    Eyes, ears and a good sense of how systems work is needed when these things happen.


    Happy New Year ¯\_(ツ)_/¯