Robocopy help

Associate
Joined
31 May 2014
Posts
521
I am going to test a batch file to run at shutdown to backup my documents to an external drive. I have the following syntax -

Robocopy c:\source c:\ destination /e /copy:dat /dcopy:t /log+:<LogFile>

I need some help though with the "/copy" flag. Seeing this is for a simple backup option I just want to keep the files in the destination the same as they are in the source. Is there any reason why I would want to use the /copy:dat over the /sec option or even the /copyall flag?
 
I didn't want to use the mirror switch as I want to delete files from the source and have them remain in the destination, will check out the linky though :)
 
Do you want to retain the files NTFS permissions? If you do then you need to use the /SEC or /COPY:DATS (you probably don't need to do this, unless you've configured a complex series of permissions on your files which you need to retain)

You can most likely just leave it with /COPY:DAT which will copy all the useful information, and the files will then just inherit the NTFS permissions of where ever you're copying them to.
 
You want this to run at shutdown? Shutdown will commence while this copy is in place, or you'll have to add a wait command to the batch file which may or may not be long enough.

Much better to do this with PowerShell in this day and age. You can set a flag file too so that when that file is copied (the last file to be copied), the machine shuts down, or better yet, use PS for the logic to call the robocopy process
 
You can most likely just leave it with /COPY:DAT which will copy all the useful information, and the files will then just inherit the NTFS permissions of where ever you're copying them to.

I think the issue is I don't really understand the implications of NTFS permissions or why I would want to copy them. Will take your suggestion that is probably isn't necessary.

You want this to run at shutdown? Shutdown will commence while this copy is in place

Aah I thought that it might run the batch file and shutdown once complete. I'll look into powershell and think in the meantime I may end up running the file copy manually from desktop, waiting until its done, and then shutting down.

Thanks for the tips.
 
you could easily add a shutdown command at the end of the script.

I seem to remember with NTFS you needed to be careful you had correct permissions on the destination drive, like running as an administrator - normal read/write wasn't enough for some operations.
 
If you're running this each time at shutdown, it may be worth adding the /XO flag.

That will just copy any files that have changed (or are newer) since the last copy. Might save you some time in comparison to copying the whole contents of the folder each time.

You could have quite a simple batch file that runs the robocopy command followed by a shutdown command.

Maybe with /f and /t to force and set a timeout.
 
there is also richcopy which is a multithreaded gui version of robocopy - also from Microsoft.

Richcopy has several bugs and is no longer supported. Robocopy is still the preferred option for scripting etc.

Probably also want to add /r:3 to change the number of retries for files that can't be copied(e.g. locked files) otherwise it will retry a million times :)
 
yeah i still use robocopy to be fair :) Richcopy was good for on offs, but these are pretty rare these days... wasn't aware it was no longer supported :(
 
Code:
@echo off
title Robocopy backup - Starting
color cf
robocopy "c:\source folder" "d:\destination folder" /e /r:3 /w:3
color a0
title Robocopy backup - Finished
ping 127.0.0.1 >nul
shutdown /s

Put that into a bat file, call it 'Backup and Shutdown.bat'

Run this when you want to run the backup and shutdown task

It will title the box and give it red backround with white font as it's backing up. Once it's done, it will go green and back, wait about 5 second, then shut down :)
 
Robocopy still remains the most robust way to copy files between computers over poor links so I use it all the time. It's a great tool.
 
Great stuff, thanks all. I have a couple further q's from all the advice -

it may be worth adding the /XO flag

From reading various online resources it says that when copying files this is the default option and thus not reqd, is this correct?

Probably also want to add /r:3

I'm only backing up personal docs, pics as opposed to anything system related so I'm assuming these shouldn't be locked?

I'm still confused whether upon shutdown, the pc will shutdown whilst robocopy is still copying files or wait until its finished? I assumed that I would need to start any script with shutdown /a to stop the shutdown and add the shutdown command at the end to end of the script to start it again but looking at bledd's script the /a switch isn't used.
 
Great stuff, thanks all. I have a couple further q's from all the advice -



From reading various online resources it says that when copying files this is the default option and thus not reqd, is this correct?



I'm only backing up personal docs, pics as opposed to anything system related so I'm assuming these shouldn't be locked?

I'm still confused whether upon shutdown, the pc will shutdown whilst robocopy is still copying files or wait until its finished? I assumed that I would need to start any script with shutdown /a to stop the shutdown and add the shutdown command at the end to end of the script to start it again but looking at bledd's script the /a switch isn't used.


You're probably right about the XO, I've always added it but when I've been copying things before I've always added it as a 2nd pass style copy. So i guess i could have left it off for the past however many times I've done it.

As for shutdown, the way batch files work it it will do the first command, then once complete run the next command. Unless you use something like Start robocopy Start shutdown, they will both run at the same time.

Put the script on your desktop, then rather than a traditional shutdown from the start menu, click the icon for the batch file it will run robocopy then shutdown once completed.
 
Yup. You could make two of them..

One called

'Backup'

The other called

'Backup and Shutdown'.

This is how I manage my robocopy backups at home.
 
Back
Top Bottom