Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run robocopy bat to copy entire drive to another drive [closed]

I'm trying to run a simple backup (mirror) of one entire drive (d:) to another drive (k:). I've created a .bat file ('backup.bat') defining the source (d:) and destination (k:) and placed this batch file within a folder on the d drive (d:\temp). When I double-click on the batch file it defines the source as d:\temp, instead of what I've defined it as in the batch file; d:.

Here is the text in the .bat file:

@echo off
echo To begin backing up data:
pause
robocopy "D:" "K:" /L /v                 
echo.
pause
exit

And this is what shows up when I double-click on the backup.bat

enter image description here

As you can see, source is defined as d:\temp. This is where the batch file is located, but in the batch file I defined it as D:. For some reason, the destination is defined correctly.

Any ideas?

-al

EDIT: If I add the '/' to the source and destination location, see code below, I see even more odd behavior (see screenshot). The source is now both the defined source and destination combined, w/ no destination.

@echo off

echo To begin backing up data:
pause

robocopy "D:\" "K:\" /L /v


echo.            
pause
exit

enter image description here

And, if I remove the "" from the source and destination....IT WORKs!

@echo off

echo To begin backing up data:
pause

robocopy D:\ K:\ /L /v
echo.            
pause
exit

enter image description here

like image 466
cherrytree Avatar asked Apr 25 '14 20:04

cherrytree


People also ask

Can you Robocopy an entire drive?

robocopy C:\src D:\dst /E /COPYALL This syntax will copy all NTFS ACLs, file owners, subfolders (including empty folders) and all file attributes from one drive to another. C:\src refers to the source drive, D:\src is the target drive, /E selects to include all empty subfolders and /COPYALL to catch the rest.

How do I use Robocopy to copy all files and folders?

Copy examples The easiest way to copy a folder with all files and subfolders is to run this command: robocopy c:\temp\source c:\temp\destination /E /DCOPY:DAT /R:10 /W:3. The /E switch tells Robocopy to copy all subfolders, including empty ones. If you don't want to copy empty subfolders, use the /S switch.

Can you automate Robocopy?

Robocopy with Scheduled Tasks. You can create a scheduled task to automatically run your robocopy script at a specified time.

Does Robocopy copy files that already exist?

Excludes existing files with the same timestamp, but different file sizes. Source directory files newer than the destination are excluded from the copy. Source directory files older than the destination are excluded from the copy.


1 Answers

with "D:" you are not specifying the root directory of the D drive (D:\) but the current directory of D instead, (D:\temp in your example).

To solve this problem, just add \ to the source spec (and while there, to the dest spec as well)

robocopy d:\ k:\ /L /v                 
like image 168
PA. Avatar answered Oct 21 '22 23:10

PA.