The Computer Oracle

Robocopy to copy only new folders and files

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 5

--

Chapters
00:00 Robocopy To Copy Only New Folders And Files
00:52 Accepted Answer Score 14
01:38 Answer 2 Score 1
01:45 Answer 3 Score 8
03:15 Answer 4 Score 2
04:14 Thank you

--

Full question
https://superuser.com/questions/671244/r...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#commandline #robocopy

#avk47



ACCEPTED ANSWER

Score 14


You can add /S for that. You don't need the \E which is for copy empty directories. You won't even need the \XO which is done by the \MAXAGE.

/S :: copy Subdirectories, but not empty ones.

When no files are copied in a directory, the directory is not created on the destination.

robocopy c:\users\valery\documents j:\robocopy /S /MAXAGE:20131030 /XD {directories_to_exclude}

If you don't have directories to exclude you can just use:

robocopy c:\users\valery\documents j:\robocopy /S /MAXAGE:20131030

You can do a robocopy /? for all the help.

 /S :: copy Subdirectories, but not empty ones.
 /E :: copy subdirectories, including Empty ones.
 /XD dirs [dirs]... :: eXclude Directories matching given names/paths.
 /XO :: eXclude Older files.
 /MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.



ANSWER 2

Score 8


My simple commands that works wonderful is:

RoboCopy.exe  "\\\SourceServer\Folder" "X:\WEB" /copy:datso /mir /fft /r:0 /w:0 /secfix /mt:20 /xo /xf thumbs.db /log+:X:\TON-FS4.log /nc /ns /np /ndl /nfl /tee

Explanation:

  • X:\WEB is my destination folder.
  • Switches:
    • /copy:datso: Specifies the file properties to copy:
      • (d: Data, a: Attributes, t: Time stamps, s: NTFS access control list (ACL), o: Owner information)
    • /mir: Mirrors a directory tree
    • /fft: Assumes FAT file times, important when copying data
    • /r:0: Number of retries on failed
    • /w:0: Wait time between retries 0 seconds
    • /secfix: Fixes file security on all files, even skipped ones
    • /mt:20: Creates 20 threads copies
    • /xo: Excludes older files - if destination file exists and is the same date or newer than the source - don't bother to overwrite it.
    • /xf thumbs.db: Excludes "thumbs.db" files (path) you can use wild characters here (ei: *.mp3)
    • /log+:filename.log: Writes the status output to the specified log file
    • (appends to the existing log file) or to use a new log just /log:filename.log

Not this particular case but I hope that will help someone when they do file servers migration.




ANSWER 3

Score 2


robocopy.exe "Q:\TEST" "T:\TEST" /E /XO /LOG+:"T:test.log

Just to break this down for bertieb - this code is meant to run straight from command line and not in a bat script.

Set Source & Destinations:

robocopy.exe "Q:\TEST" "T:\TEST"

"Q:\TEST" = Sets The Source Directory to Mapped Drive "Q"

"T:\TEST" = Sets The Destination Directory to Mapped Drive "T"

OPTIONS USED:

/E /XO /LOG+:"T:test.log"
  1. /E : Copy Subdirectories Including Empty Ones
  2. /XO : Exclude older files
  3. LOG+ : This will log the robocopy process in a .log file named test that will be in the root directory of the destination (i.e. Above the "TEST" folder on T). LOG+ will append the output status to the test.log file rather than over write it.

SIDE NOTE:

The LOG+ option can be switched to the LOG option if you would like to only have the most recent session's information saved.

Easy to read version of more information on Robocopy or the Microsoft documentation.




ANSWER 4

Score 1


robocopy.exe "Q:\TEST" "T:\TEST" /E /XO /LOG+:"T:test.log"