+ Post New Thread
Results 1 to 3 of 3
How do you do....it? Thread, Robocopy in Technical; I currently have a batch file like this but with a few more folders in Code: net use z: \192.168.1.109\Software ...
  1. #1

    Join Date
    Oct 2008
    Location
    Lincolnshire
    Posts
    2,344
    Thank Post
    13
    Thanked 240 Times in 228 Posts
    Rep Power
    70

    Robocopy

    I currently have a batch file like this but with a few more folders in

    Code:
    net use z: \\192.168.1.109\Software
    Robocopy E:\_Software Z:\ /mir
    What I want to do is preserve the dates on the original files rather than the time it has copied over, also I want it to create a log file for each folder i.e. E:\logfile\software.txt

    I will then run this on a weekly basis and it will copy over any new files but will this replicate any changes if I delete folders?

    Cheers

  2. #2
    jonawd's Avatar
    Join Date
    Dec 2009
    Location
    Hayfield, High Peak
    Posts
    45
    Thank Post
    4
    Thanked 8 Times in 7 Posts
    Rep Power
    12
    Its been a while since I used RoboCopy in ernest, but I think the below /COPY switch is the one you need for you to manage what to copy along with the data.

    This should copy the Data and the Timestamps.
    Code:
    /COPY:DT
    Robocopy /? has more information around this.

    Outputting the log
    For outputting the log, I use PowerShell with the "| Out-Host" and "Transcript" functions.

    In short, you could do something like this in a PowerShell Script to Start a Transcript to a file (using today's date) and RoboCopy Outputting to host:
    Code:
    $a = Get-Date -format d.M.yyyy
    $b = "g:\blah-" + $a + ".txt"
    
    
    Start-Transcript -path $b -append
    Robocopy E:\Blah G:\Blah /mir /copy:DT | Out-Host
    Stop-Transcript
    This would result in the log file (called G:\Blah-22.8.2014) looking like this:

    Code:
    **********************
    Windows PowerShell transcript start
    Start time: 20140822004658
    Username  : MainPC\Jon 
    Machine      : MAINPC (Microsoft Windows NT 6.3.9600.0) 
    **********************
    Transcript started, output file is g:\blah-22.8.2014.txt
    
    -------------------------------------------------------------------------------
       ROBOCOPY     ::     Robust File Copy for Windows                              
    -------------------------------------------------------------------------------
    
      Started : 22 August 2014 00:46:58
       Source : E:\Blah\
         Dest : G:\Blah\
    
        Files : *.*
            
      Options : *.* /S /E /DCOPY:D /COPY:DT /PURGE /MIR /R:1000000 /W:30 
    
    ------------------------------------------------------------------------------
                           4    E:\Blah\
    ------------------------------------------------------------------------------
    
                   Total    Copied   Skipped  Mismatch    FAILED    Extras
        Dirs :         1         0         0         0         0         0
       Files :         4         0         4         0         0         0
       Bytes :         0         0         0         0         0         0
       Times :   0:00:00   0:00:00                       0:00:00   0:00:00
       Ended : 22 August 2014 00:46:58
    
    **********************
    Windows PowerShell transcript end
    End time: 20140822004658
    **********************
    The "| Out-Host" is important as without it, the Robocopy is not picked up by the Transcript.

    Other ways
    There are many other ways to do this I'm sure, but this is the way that I have my Home Backup's configured (backing up my Web and File Servers to another desktop, which is then ultimately backed up to SugarSync)

    Attached
    Here is the PowerShell script used above:blah.ps1

  3. #3


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,778
    Thank Post
    262
    Thanked 2,963 Times in 2,178 Posts
    Rep Power
    838
    Quote Originally Posted by MatthewL View Post
    Code:
    net use z: \\192.168.1.109\Software
    Robocopy E:\_Software Z:\ /mir
    Instead of mapped drives use UNC paths instead because if the Z: drive fails to be mapped, your robocopy job will fail too.

    It's also worth specifying the retry and wait times since the default for these is 1 million (!!!) and 30 respectively.

    The following should do what you want.

    Code:
    @echo off
    
    :: Get date/time in YYYY-MM-DD_HH.MM format
    for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set dt=%%j
    set dt=%dt:~0,4%-%dt:~4,2%-%dt:~6,2%_%dt:~8,2%.%dt:~10,2%
    
    :: Start backup
    robocopy \\Source\e$\_Software \\192.168.1.109\Software /MIR /NP /DCOPY:DAT /SEC /TEE /R:5 /W:3 /V /LOG+:"\\Source\e$\LogFiles\Software_%dt%.log"
    Quote Originally Posted by MatthewL View Post
    I will then run this on a weekly basis and it will copy over any new files but will this replicate any changes if I delete folders?
    With /MIR, any files or folders that are added/deleted in the source will also be added/deleted in the destination.
    Last edited by Arthur; 22nd August 2014 at 07:35 AM.



SHARE:
+ Post New Thread

Similar Threads

  1. Robocopy
    By acrobson in forum How do you do....it?
    Replies: 16
    Last Post: 22nd December 2007, 02:41 PM
  2. Robocopy Gone Wrong
    By fawkers in forum Windows
    Replies: 2
    Last Post: 17th September 2007, 07:50 AM
  3. RoboCopy users.
    By tosca925 in forum Windows
    Replies: 3
    Last Post: 20th May 2007, 12:58 PM
  4. Robocopy questions...............!
    By Kyle in forum Windows
    Replies: 3
    Last Post: 28th January 2006, 08:20 PM
  5. Backup Script for NT backup and Robocopy
    By ChrisH in forum Scripts
    Replies: 12
    Last Post: 20th October 2005, 02:01 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •