1

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?

Ahmad Bahrani
  • 13
  • 1
  • 5
  • The reason why I want to copy over because files wont' get deleted in the source without actually copy over. I want do it without the need of using another application or code to compare similar files and delete them. the idea of cleaning the destination is useless because source have some files already which destination doesn't have. Thanks – Ahmad Bahrani Dec 20 '15 at 21:36
  • So I guess the one thing that I forget to mention is that I'm doing this continuously I have schedule that start robocopy batch file and move thing on regular bases. So, I don't want to do anything manually check or deleting. and user going to keep dumping file in the source and I need robocopy to move it to destination a script that check file by modify date different and delete them would work too – Ahmad Bahrani Jan 06 '16 at 21:35
  • Hi LMFAO_A_JOKE, and thank you so much for the replay. to answer your first comment. 1) "Move thing" actually meant moving things = files 2) That is correct only NEW 3)Exactly!! . So, I guess I'll wait for your update. if there is anything else that is not clear please let me know, I'll check the form more frequently – Ahmad Bahrani Jan 13 '16 at 04:14

1 Answers1

0

Robocopy replace same date file move

IF Source File data (Newer or Same) move/overwrite data Else skip file

To complete this use Robocopy with the example batch script I provided below sytax and all.

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.

The issue is I also want to move the same date data not just the newer.

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.)

/S         : Copy Subfolders, but not empty ones.
/NP        : No Progress - don’t display % copied. (for cleaner log file)
/R:n       : Number of Retries on failed copies - default is 1 million.
/MOVE      : Move files and dirs (delete from source after copying).
/IS        : Include Same, overwrite files even if they are already the same.
/TS        : Include Source file Time Stamps in the output. (for log file)
/FP        : Include Full Pathname of files in the output. (for log file)
/LOG+:file : Output status to LOG file (append to existing log).

For the below variables of:

  • SET SRCRoot="\\Server\Share\Source"
  • SET DESTRoot="\\Server\Share\Destination"

The SET SRCRoot and SET 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.

@ECHO ON
SET SRCRoot="\\Server\Share\Source"
SET DESTRoot="\\Server\Share\Destination"
SET LOG=C:Path\Log.txt

:: --// Robocopy Options
:::: --// If you do not want a log file, remove the "/LOG+:%LOG%" below
SET OPT=/MOVE /IS /S /NP /R:5 /LOG+:%Log% /TS /FP
SET CMD=Robocopy "%SRCRoot%" "%DESTRoot%" *.* %OPT%
%CMD%
EXIT /B

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)

/E       : Copy Subfolders, including Empty Subfolders.
/SEC     : Copy files with SECurity (equivalent to /COPY:DATS).
/DCOPY:T : Copy Directory Timestamps.
/COPYALL : Copy ALL file info (equivalent to /COPY:DATSOU)

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

Vomit IT - Chunky Mess Style
  • 40,038
  • 27
  • 84
  • 117
  • Thanks again for the code. However, this still will not solve the main issue that I'm facing which is delete files that are in source and older than distention. I'm not trying to make a mirror copy here. I'm trying to clean a source (which we use kinda like a buffer) by moving any files that are newer to destination, and delete same date or older files. and I'm running this on seclude. /PURGE option will not help because it's cleaning the distention which I absolutely don't wont to do. – Ahmad Bahrani Jan 13 '16 at 17:48
  • @AhmadBahran I just added the `/IS` switch and updated my answer one more time. Read it from the top to see the changes and notes, I think this will help you but please let me know either way. If you want to include empty subfolders from source over to destination, please let me know and I'll add the `/E` and take out the `/S`. – Vomit IT - Chunky Mess Style Jan 13 '16 at 18:22
  • Right, because I'll need what I mention in the previous comment plus this "delete files that are in source and older than distention". Move or mov, will delete only the data or files that have been copied by robocopy. in my case the data that are the same date as the destination will not copy by robocopy and thus will not get deleted from the source. and that is my dilemma. I want to delete files from the source that are Older or same date but didn't get copy(thus cleared) by robocopy – Ahmad Bahrani Jan 13 '16 at 18:25
  • That might be the awswer to my question. So what does /IS exactly do. I got this from a website. /IS : Include Same, overwrite files even if they are already the same. so would it overwrite files with the same date – Ahmad Bahrani Jan 13 '16 at 18:28
  • I'm going to test this now and get back to you – Ahmad Bahrani Jan 13 '16 at 18:29
  • @AhmadBahran It'll `Include Same, overwrite files even if they are already the same.` so with the `/MOVE` and `/IS` this will mean NEW and SAME data from source will be copied over to destination and then once those files are copied, it'll delete those from the source. – Vomit IT - Chunky Mess Style Jan 13 '16 at 18:29
  • Yup, That works. thank you so much. I've another issue that is tide with this application should I make new question or we can continue here it with " The given path's format is not supported" when robocopy face folder with illegal car like : or \\/:*? – Ahmad Bahrani Jan 13 '16 at 18:49
  • And for other reference. I needed this because I'm using /XO. and the good news is /XO with /IS works. so /XO /IS = copy file with newer and same date and cancel ( exculde same date from XO) – Ahmad Bahrani Jan 13 '16 at 18:53
  • sounds good. I'll do that – Ahmad Bahrani Jan 13 '16 at 18:54