I'm using robocopy to move data. I want to achieve this
IF Source File data (Newer or Same) move/overwrite data
Else skip file
I need a switch or a way to just excluded newer not newer or same data. I'm using Robocopy to clean and move a lot of data to a big storage device.
A line to delete files from the source with matching date with target would be useful too
/XO
excluded files Same date or Newer files in the target
/XN
excluded files older in the source and newer in the target
Some of the data are already on that source.
My issue that I want to just excluded older not same date. I want to make sure to move (and overwrite so source get clean) the data with new or same data as the source.
I'm using /XO
switch
/XO : eXclude Older – if destination file exists and is the same date or newer than the source – don’t bother to overwrite it.
The issue is I also want to move the same date data not just the newer.
Is there a way to do that?
Best Answer
To complete this use Robocopy with the example batch script I provided below sytax and all.
Since by default Robocopy will only copy a file if the source and destination have different time stamps or different file sizes, you have to use the
/IS
switch for it to also copy the same data over too, and then if you use the/MOVE
switch, it'll also remove those files and folders from the source.Robocopy Options Used
(I used these switches in particular but you should test to confirm all works as expected just in case.)
For the below variables of:
SET SRCRoot="\\Server\Share\Source"
SET DESTRoot="\\Server\Share\Destination"
The
SET SRCRoot
andSET DESTRoot
are the root\parent directories you'll be copying to and from at the topmost level all the way down recursively. You can set either one of these to a drive letter path (e.g.C:\Path
) or you can keep as UNC path (i.e.\\server\share\folder
) and it'll work either way.SET LOG=C:Path\Log.txt
The
SET LOG
is your appended log file name and location. It can also point to a drive full path or a UNC path. This is the file you can review to get all the detail of what copied, what did not, error messages, etc. This is strictly optional but I'd suggest using it always and review as-needed for troubleshooting or confirmation.Robocopy Batch Script Example
If you need to also copy over the file level security of the files and folder you copy to source from destination (the ACLs), please let me know as you'll probably want to include the
/SEC
or/COPYALL
swithces.Optional Robocoy Switches
(If you need any of these, let me know and I'll be glad to update my answer if you need an example including any)
Scheduling for Unattended Automation
Refer to my answer Scheduled Tasks for the options, gotchas, etc. you'll want to select when scheduling a batch script with Task Scheduler to run as expected. Screen shots and all are provided and feel free to upvote that answer if you find it useful and worthy as such—no pressure just an additional resource you may find useful.
Further Resources and Reading