robocopy delete-before copy

is there a way to have robocopy delete changed destination files before it copies?

this is my script so far:
"C:\Program Files (x86)\Windows Resource Kits\Tools\robocopy.exe" E:\shares F:\shares-backup /PURGE /E /SEC /R:5 /W:60 /NP > "C:\scripts\logs\shares_backup.txt"

thanks
Andrea_JennisonAsked:
Who is Participating?
 
oBdAConnect With a Mentor Commented:
Then you need to make two runs; in the first, you just purge, in the second, you copy:
C:\Program Files (x86)\Windows Resource Kits\Tools\robocopy.exe" E:\shares F:\shares-backup /nocopy /PURGE /E /R:5 /W:60 /NP
C:\Program Files (x86)\Windows Resource Kits\Tools\robocopy.exe" E:\shares F:\shares-backup /E /SEC /R:5 /W:60 /NP

Which, of course, means that if the copy fails after the purge, your backup is gone ...
0
 
oBdACommented:
What exactly is it you're trying to do? robocopy will overwrite changed files, which is as good as deleting them.
0
 
Andrea_JennisonAuthor Commented:
The problem I am having is when robocopy(ing) one disk to another. For example, I have two disks of equal 100GB size, disk0 and disk1: disk0 is my source and disk1 is my destination. The contents of disk0 are folderA and folderB. The contents of disk0\folderA is 75GB in size, disk0\folderB is 0GB.

I run the following line: (all works ok)
C:\Program Files (x86)\Windows Resource Kits\Tools\robocopy.exe" E:\shares F:\shares-backup /PURGE /E /SEC /R:5 /W:60 /NP

After running the above line, disk0 and disk1 are effectively sync. All is good!

The problem occurs when I move the 75GB contents of disk0\folderA to disk0\folderB and run (again):
C:\Program Files (x86)\Windows Resource Kits\Tools\robocopy.exe" E:\shares F:\shares-backup /PURGE /E /SEC /R:5 /W:60 /NP

Robocopy first tries to copy the contents of disk0\folderB to disk1\folderB before deleting the contents of disk0\folderA. If I have explained this correctly, you will see that robocopy by first copying exceeds the total capacity of disk1.

Thoughts?
0
 
Andrea_JennisonAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.