My Technical Notes

Thursday, 8 June 2017

One-way Sync (Mirror) using Robocopy

Before mirroring one directory with another, you want to first check how long the mirroring will take, if you think it will be a big job. To only check what will be copied across and not actually do it, add a flag `/L` to the options.

Example  The following statement does a sync from the source location `C:\_todo` to the destination `Z:\_todo`:


robocopy C:\_todo\ Z:\_todo /MIR /NJH /XF *.org~ *.org# /XD .git

The first argument is the source location, second the destination. Here are the remaining arguments:

  • `/MIR` tells it to mirror a location.
  • `/NJH` tells it to not produce a job header, which contains information like the source and destination directories. This is only needed if you log this information to a file that will be later viewed.
  • `/XF` is a list of file name patterns to exclude. Separate them by space.
  • `/XD` is a list of directory name patterns to exclude. As with `\XF`, separate them by space.

Information Produced  In the information produced, you have a list of items that will be copied across, and the most important bit, especially if you run it with the `/L` for logging, is the Bytes Copied in the footer, which is `22.6 K` (kilobytes) in the output below:


$>
                          17    C:\_todo\
            New File                  30        .#30-May-2017-Onwards.org
            New File               13014        30-May-2017-Onwards.org
            New File                  94        compare.bat
            New File                  28        google.txt
            New File                1660        gregg.org
            New File                 317        May2017.org
            New File                  36        myday-1235.org
            New File                 229        myuol.org
            New File                   0        printertile.org
          New Dir          0    C:\_todo\Archive\
          New Dir          1    C:\_todo\NdorChangesv2\
            New File                7782        NdorChangesv2.org

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

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         4         2         2         0         0         0
   Files :        18        10         8         0         0         0
   Bytes :    51.6 k    22.6 k    28.9 k         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00

   Ended : Thu Jun 08 15:00:29 2017

No comments: