Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: ROBOCOPY - Create Backup Script


18 Sep 2011   #19
Golden

Microsoft Community Contributor Award Recipient

Windows 7 Ult. x64 Windows 8.1 x64
 
 
ROBOCOPY - Create Backup Script

How to Create a Backup Script using ROBOCOPY Command


...

My System SpecsSystem Spec
21 Mar 2012   #20
Trapper

Windows 7 Professional 64bit
 
 

Thank you Golden, I have to report Progress, of sorts!

Below is copied from the screen shot after running the program.


C:\Users\Alans PC\Documents>robocopy C:\Users\Alans PC\TEST FOLDER F:\Outlook Data Files /e /np /tee /mt:4 /log:my_backup_log.txt

-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows

-------------------------------------------------------------------------------

Started : Wed Mar 21 10:12:08 2012

Source - C:\Users\Alans\
Dest - C:\Users\Alans PC\Documents\PC\TEST\

Files : FOLDER

Options : /COPY AT /R:1000000 /W:30

------------------------------------------------------------------------------

ERROR : Invalid Parameter #4 : "F:\Outlook"

Simple Usage :: ROBOCOPY source destination /MIR

source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
/MIR :: Mirror a complete directory tree.

For more usage information run ROBOCOPY /?

**** /MIR can DELETE files as well as copy them !

C:\Users\Alans PC\Documents>pause
Press any key to continue . . .

END.

The destination is as follows, copied from the address bar of my F: drive as text.

F:\Outlook Data Files

I note that the source and destination are both C:

Quote:
Source - C:\Users\Alans\
Dest - C:\Users\Alans PC\Documents\PC\TEST


The above does not agree with the script you wrote or I copied to notepad, I wondered if my original script was somehow corrupting this one so I deleted my original and tried again with the same result.

Perhaps you could shed some light on what maybe wrong.

Many thanks.

My System SpecsSystem Spec
21 Mar 2012   #21
JDobbsy1987

Windows 8.1 Pro x64
 
 

Whenever there is a space in the file path you need to put quotes around it.

e.g.
"C:\Users\Alans PC\Documents\PC\TEST"

Just to keep it simple for a second, does it work if you try:
Quote:
robocopy "C:\Users\Alans\" "C:\Users\Alans PC\Documents\PC\TEST"
Regards,
JDobbsy1987
My System SpecsSystem Spec
21 Mar 2012   #22
Trapper

Windows 7 Professional 64bit
 
 

Hi JDobbsy1987.

Thanks for that suggestion, I have added the quotation marks to my script which is now looking like:

Quote:
robocopy "C:\Users\Alans PC\TEST FOLDER" "F:\Outlook Data Files" /e /np /tee /mt:4 /log:my_backup_log.txt
pause
I put a File in my TEST FOLDER called 'calender 2012' on running the above script I now have a copy of the 'calender 2012' file in my F:\Outlook Data Files Folder.

I would have thought that I would be copying the whole folder, in my case TEST FOLDER to my F: Drive, as in the instruction: "C:\Users\Alans PC\TEST FOLDER".

The following is copied from the CMD prompt window.

Quote:
C:\Users\Alans PC\Documents>robocopy "C:\Users\Alans PC\TEST FOLDER" "F:\Outlook
Data Files" /e /np /tee /mt:4 /log:my_backup_log.txt

Log File : C:\Users\Alans PC\Documents\my_backup_log.txt

-------------------------------------------------------------------------------
ROBOCOPY :: Robust File Copy for Windows

-------------------------------------------------------------------------------

Started : Wed Mar 21 16:40:11 2012

Source : C:\Users\Alans PC\TEST FOLDER\
Dest : F:\Outlook Data Files\

Files : *.*

Options : *.* /TEE /S /E /COPY AT /NP /MT:4 /R:1000000 /W:30

------------------------------------------------------------------------------

*EXTRA Dir -1 F:\Outlook Data Files\Outlook - OLD Pre 2012\
*EXTRA Dir -1 F:\Outlook Data Files\Outlook Files - NEW 21 03
2012\
1 C:\Users\Alans PC\TEST FOLDER\
100% New File 120320 calendar 2012.xls

------------------------------------------------------------------------------

Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 1 0 0 2
Files : 1 1 0 0 0 0
Bytes : 117.5 k 1 17.5 k 0 0 0 0
Times : 0:00:00 0:00:00 0:00:00 0:00:00

Ended : Wed Mar 21 16:40:12 2012

C:\Users\Alans PC\Documents>pause
Press any key to continue . . .
If I wish to copy 'Folder XX' to my F: drive should I have put 'Folder XX' in my TEST FOLDER? I.e not the individual file.

Perhaps the headers showing;
...........Total Copied Skipped Mismatch FAILED Extras
Dirs : ......1 ......0 ........1 .........0 ..........0 .......2
Files : .....1 ......1 ........0 .........0 ..........0 .......0

May have something to do with it?

Anyway at last I have been able to copy a file with 2 key strokes instead of many strokes and less chance of errors.

Will this script automatically overwrite the preceding copy when the script is run again, replacing copy 1 with copy 2 etc?
My System SpecsSystem Spec
21 Mar 2012   #23
JDobbsy1987

Windows 8.1 Pro x64
 
 

Quote   Quote: Originally Posted by Trapper View Post
I would have thought that I would be copying the whole folder, in my case TEST FOLDER to my F: Drive, as in the instruction: "C:\Users\Alans PC\TEST FOLDER".
Robocopy copies the 'contents' of the folder you specify in the script as opposed to the actual folder itself.


Quote   Quote: Originally Posted by Trapper View Post
If I wish to copy 'Folder XX' to my F: drive should I have put 'Folder XX' in my TEST FOLDER? I.e not the individual file.
The answer is yes


Quote   Quote: Originally Posted by Trapper View Post
Will this script automatically overwrite the preceding copy when the script is run again, replacing copy 1 with copy 2 etc?
I'm pretty certain it will overwrite the preceding copy, it did when i tested before writing this reply.



Robocopy has a lot of features/switches to allow you to do quite a lot, you can take a look at these by running the following command in a command prompt:

Code:
robocopy /?
If you do want to make your script go that step further then please feel free to open a support thread in the forum and send me a pm and i will do my best to mentor you through as much as i can

Regards,
JDobbsy1987
My System SpecsSystem Spec
.


21 Mar 2012   #24
Golden

Microsoft Community Contributor Award Recipient

Windows 7 Ult. x64 Windows 8.1 x64
 
 

Hi,

Yes, Dobsy is correct : when source and/or destinations have spaced in them, enclose the folders with " ". I might add that to the tutorial.

Each time you run ROBOCOPY without the /MIR switch, it will always overwite the preceeding copy - in effect it operates like XCOPY. If you add the /MIR switch to your ROBOCOPY command, then only the newest information in that folder is copied to your backup. This is a great time-saving feature.

Regards,
Golden
My System SpecsSystem Spec
21 Mar 2012   #25
Trapper

Windows 7 Professional 64bit
 
 

Gentlemen.

Thank you both for your kind assistance with these problems of mine, I have printed off the Robocopy switches (A very long list!)

I will now have a play over the next day or so and see what I can achieve.

I will leave the /mir switch out until I am more confident, I have time but with my luck I will screw it up and lose the original files.

If I need to post into which forum would this come under, it could cover a few listed?
My System SpecsSystem Spec
21 Mar 2012   #26
Golden

Microsoft Community Contributor Award Recipient

Windows 7 Ult. x64 Windows 8.1 x64
 
 

Your very welcome Trapper.

If you need to post further, just post under the "Backup & Restore" section. I'm confident you will be using the /MIR switch in no time at all.

There is only one trick to remember with /MIR:

If you have a folder that is already backed-up and you no longer require it - always delete it at the source (NOT at the destination) and then run ROBOCOPY. This way, ROBOCOPY will take care of it (delete it) at the destination for you automatically (this is the mirroring effect). Follow that rule, and you will never go wrong with the /MIR switch

In summary:

1, Delete folder at source
2. Run ROBOCOPY with /MIR switch
3. Folder is automatically deleted for you at destination.

Regards,
Golden
My System SpecsSystem Spec
22 Mar 2012   #27
rschaef07

Windows 7 Pro
 
 
Excluding Folders that are many levels deep.

Golden;
In my folder structure, every project has subfolders named Archive, Inbox, Temp, etc. They are always 4 levels below the drive root, but the parent project name is unique. Is there a way to exclude these subfolders?

Thanks much,
Ron
My System SpecsSystem Spec
22 Mar 2012   #28
JDobbsy1987

Windows 8.1 Pro x64
 
 

Quote   Quote: Originally Posted by rschaef07 View Post
Golden;
In my folder structure, every project has subfolders named Archive, Inbox, Temp, etc. They are always 4 levels below the drive root, but the parent project name is unique. Is there a way to exclude these subfolders?

Thanks much,
Ron
Hi Ron

As long as you don't add one of these switches it should not copy subdirectories:

/e or /s

Example, change Golden's example from
Code:
robocopy E:\Data1 G:\Backups\Data1 /e /mir /np /log:backup_log.txt
to
Code:
robocopy E:\Data1 G:\Backups\Data1 /mir /np /log:backup_log.txt
Regards,
JDobbsy1987
My System SpecsSystem Spec
22 Mar 2012   #29
rschaef07

Windows 7 Pro
 
 
Some folders yes, some folders no

Understood. But at that same level (4 deep from the root) are the folders that are the core of our projects and need to be backed up...
Is there a way to not back up some that are identically named and located but not others at the same folder depth?

Thanks, Ron
My System SpecsSystem Spec
Comment

 ROBOCOPY - Create Backup Script




Tutorial Tools



Similar help and support threads for2: ROBOCOPY - Create Backup Script
Windows 7 Tutorial Category
Robocopy Backup - ERROR 5 (0x00000005) Backup and Restore
How to create batch script to lock workstation then log off. General Discussion
Robocopy backup for personal folders Backup and Restore
I Need Help To Create REG. Script With Admin. Priv. For Reg. Editor? Customization
Robocopy backup - file permissions General Discussion
Anyone use robocopy to backup? Backup and Restore
Create ErrorHandler.cmd script file General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 11:40 AM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33