MatthewL Posted August 21, 2014 Posted August 21, 2014 I currently have a batch file like this but with a few more folders in 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
jonawd Posted August 21, 2014 Posted August 21, 2014 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. /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: $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: ********************** 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
Arthur Posted August 22, 2014 Posted August 22, 2014 (edited) 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. @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 \\[color="#FF0000"]Source[/color]\e$\_Software \\192.168.1.109\Software /MIR /NP /DCOPY:DAT /SEC /TEE /R:5 /W:3 /V /LOG+:"\\[color="#FF0000"]Source[/color]\e$\LogFiles\Software_%dt%.log" 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. Edited August 22, 2014 by Arthur
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now