Sunteți pe pagina 1din 6

29/04/14

ROBOCOPY - Create Backup Script - Windows 7 Help Forums


Join Forum | Login | Today's Posts | Tutorials | Vista Forum | Windows 8 Forum

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 Help Forums > Windows 7 help and support > Tutorials

Windows 7: ROBOCOPY - Create Backup Script


Recommended Fix: Download Here

Page 1 of 24 1 2 3 11 > Last

ROBOCOPY - Create Backup Script


How to Create a Backup Script using ROBOCOPY Command Published by Golden 18 Sep 2011

How to Create a Backup Script using ROBOCOPY Command

Published by

Information There are many paid and free software solutions available to backup critical data and files on a computer system. Many users, however, are unaware of an inbuilt Windows 7 command called ROBOCOPY (Robust File Copy) that allows users to create simple or highly advanced backup strategies.

Golden
In its simplist form, ROBOCOPY can be likened to an extension of XCOPY on steroids. Some of the more important features that make ROBOCOPY an attractive backup alternative are: multi-threaded copying mirroring or synchronisation mode between the destination and source automatic retry and copy resumption The examples shown below are primarily geared towards less experienced users, especially those that are unfamilar with batch file creation and running. More experienced users, however, are welcome to explore some of the advanced functionality offered by ROBOCOPY here: http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx and also here: http://www.theether.net/download/Mic...s/robocopy.pdf or by simply typing robocopy /? at a cmd window prompt.

Note ROBOCOPY is a FOLDER copier, not a FILE copier - the source and destination syntax arguments in ROBOCOPY can only be folder names.

Creating a BACKUP strategy


The easiest way to use the ROBOCOPY command to create a backup strategy is by creating a batch (.BAT) file. A batch file is a simple text file, that when executed, runs several commands one after the other.

Step 1
Click and in the search box, type notepad. Select Notepad to open up a new blank Notepad document.

Step 2
Type the ROBOCOPY commands into the Notepad document, save it as a .BAT file, and then execute it.

www.sevenforums.com/tutorials/187346-robocopy-create-backup-script.html

1/6

29/04/14

Type the ROBOCOPY commands into the Notepad document, save it as a .BAT file, and then execute it.

ROBOCOPY - Create Backup Script - Windows 7 Help Forums

In the example below, I have 3 folders (Data1, Data2, and Data3) containing some data that I wish to backup. One folder is located on E: drive and the other two are located on F: drive. I wish to back these up as follows: Data1 folder on E: backup to a folder called Backups on G: (external USB drive) Data2 folder on F: backup to a folder called Backups on G: (external USB drive) Data3 folder on F: backup to a folder called Backups on Q: (network storage drive) The general format of the ROBOCOPY command is:
C ode:

r o b o c o p y< s o u r c e >< d e s t i n a t i o n >< o p t i o n s >

In the empty Notepad document, the simplist form of the command would look like this:
C ode:

r o b o c o p yE : \ D a t a 1G : \ B a c k u p s \ D a t a 1 r o b o c o p yF : \ D a t a 2G : \ B a c k u p s \ D a t a 2 r o b o c o p yF : \ D a t a 3Q : \ B a c k u p s \ D a t a 3 p a u s e

Tip If source or destination paths contain spaces in them, enclose these in double quotes e.g. "C:\My Data\My Music"

Only the source E:\Data1 F:\Data2 F:\Data3 and the destination G:\Backups\Data1 G:\Backups\Data2 Q:\Backups\Data3 are mandatory inputs into the ROBOCOPY command. Tip The PAUSE command at the bottom of the .BAT file allows the cmd window to stay open after it has completed to allow me to see the output from ROBOCOPY.

If I save the .BAT file to my Desktop, and run it by double-clicking it, then a cmd window is opened and the .BAT file executes the three ROBOCOPY commands as shown below.

The same information is repeated for every ROBOCOPY line in the .BAT file.

In order to utilise some of the powerful functionality in ROBOCOPY, I need to utilise some options in the ROBOCOPY command line. In this next example I want to edit my existing backup strategy such that:

www.sevenforums.com/tutorials/187346-robocopy-create-backup-script.html

1. All sub-folders within my data folders are backed up, even if they are empty.

2/6

29/04/14

ROBOCOPY - Create Backup Script - Windows 7 Help Forums


1. All sub-folders within my data folders are backed up, even if they are empty. 2. The backup only copies newer files to my existing backup - this means a faster backup time. 3. The percentage progress counter for copying is not shown - this neatens the overall appearance of the ROBOCOPY information, and creates a smaller log file. 4. The information normally echoed to the cmd window is saved to a log file that I can examine at a later stage.

In order to do this, I need to specify some additional options in my ROBOCOPY commands like this:
C ode:

r o b o c o p yE : \ D a t a 1G : \ B a c k u p s \ D a t a 1/ e/ m i r/ n p/ l o g : b a c k u p _ l o g . t x t r o b o c o p yF : \ D a t a 2G : \ B a c k u p s \ D a t a 2/ e/ m i r/ n p/ l o g + : b a c k u p _ l o g . t x t r o b o c o p yF : \ D a t a 3Q : \ B a c k u p s \ D a t a 3/ e/ m i r/ n p/ l o g + : b a c k u p _ l o g . t x t p a u s e

Where: /e = copy all sub-folders, even empty ones /mir = mirror (check the files in the destination, and only copy newer files) /np = no progress counter /log: = create a logfile Tip Note the use of the /log+: option in the 2nd and 3rd line of the .BAT file. This option ensures that the results of the 2nd and 3rd ROBOCOPY are appended to the log file created in the 1st ROBOCOPY line, meaning I only need one log file to capture all the information I backup. The log file is always saved to the same folder as the .BAT file - in my case, the folder is saved to my Desktop.

Since the output from ROBOCOPY is written to the log file, the cmd window will not display the output from ROBOCOPY. If I wish to have this information written to both the log file and the cmd window for visual tracking of the backup process, then I can add the /tee option to each line in the .BAT file, as shown below.
C ode:

r o b o c o p yE : \ D a t a 1G : \ B a c k u p s \ D a t a 1/ e/ m i r/ n p/ t e e/ l o g : b a c k u p _ l o g . t x t r o b o c o p yF : \ D a t a 2G : \ B a c k u p s \ D a t a 2/ e/ m i r/ n p/ t e e/ l o g + : b a c k u p _ l o g . t x t r o b o c o p yF : \ D a t a 3Q : \ B a c k u p s \ D a t a 3/ e/ m i r/ n p/ t e e/ l o g + : b a c k u p _ l o g . t x t p a u s e

This is an example of the typical output to the the log file - it looks exactly the same as what is echoed to the cmd window.
C ode:

R O B O C O P Y : : R o b u s tF i l eC o p yf o rW i n d o w s S t a r t e d:S u nS e p1 82 3 : 3 5 : 0 12 0 1 1 S o u r c e:E : \ D a t a 1 \ D e s t:G : \ B a c k u p s \ D a t a 1 \ F i l e s:* . * O p t i o n s:* . */ S/ E/ C O P Y : D A T/ P U R G E/ M I R/ R : 1 0 0 0 0 0 0/ W : 3 0 2E : \ D a t a 1 \ T o t a l C o p i e d S k i p p e d M i s m a t c h F A I L E D E x t r a s D i r s: 1 0 1 0 0 0 F i l e s: 2 0 2 0 0 0 B y t e s: 4 4 2 . 1k 0 4 4 2 . 1k 0 0 0 T i m e s: 0 : 0 0 : 0 0 0 : 0 0 : 0 0 0 : 0 0 : 0 0 0 : 0 0 : 0 0 E n d e d:S u nS e p1 82 3 : 3 5 : 0 12 0 1 1 Since one of the data folders I am backing up is being copied across a network, I want to ensure that any possible network outages do not cause some critical files to be skipped in the backup. To do this, I can make use of the /z option in the 3rd line of my .BAT file (backup to my network storage) as shown below.
C ode:

r o b o c o p yE : \ D a t a 1G : \ B a c k u p s \ D a t a 1/ e/ m i r/ n p/ t e e/ l o g : b a c k u p _ l o g . t x t r o b o c o p yF : \ D a t a 2G : \ B a c k u p s \ D a t a 2/ e/ m i r/ n p/ t e e/ l o g + : b a c k u p _ l o g . t x t r o b o c o p yF : \ D a t a 3Q : \ B a c k u p s \ D a t a 3/ e/ m i r/ n p/ z/ t e e/ l o g + : b a c k u p _ l o g . t x t

www.sevenforums.com/tutorials/187346-robocopy-create-backup-script.html

3/6

29/04/14

ROBOCOPY - Create Backup Script - Windows 7 Help Forums

This option implements a "retry" for the copying. If I were part way through the copying process, and I lost connection with the network, then ROBOCOPY would automatically restart the copying at the point of failure once the network connection was re-established. It would retrying a million times every 30 seconds (the default settings shown in the image above). The only drawback with this option, is that it can significantly increase the backup time. ROBOCOPY also has the ability to perform faster multi-threaded copying by simply using the option /mt. I can choose the number of threads to use by specifying a number between 1 and 128 after the /mt option, or if I just specify /mt without a number then the it will use 8 threads by default. In the example below, I use 4 threads to copy to my USB drive, and 8 threads (no number) to copy to my network drive.
C ode:

r o b o c o p yE : \ D a t a 1G : \ B a c k u p s \ D a t a 1/ e/ m i r/ n p/ t e e/ m t : 4/ l o g : b a c k u p _ l o g . t x t r o b o c o p yF : \ D a t a 2G : \ B a c k u p s \ D a t a 2/ e/ m i r/ n p/ t e e/ m t : 4/ l o g + : b a c k u p _ l o g . t x t r o b o c o p yF : \ D a t a 3Q : \ B a c k u p s \ D a t a 3/ e/ m i r/ n p/ z/ t e e/ m t/ l o g + : b a c k u p _ l o g . t x t

Below is a template that you can use to create your own backup strategy using ROBOCOPY. Simply copy and paste the lines into a blank text document, and then edit as appropriate.
C ode:

r e m-E d i tt h el i n e sb e l o wt oc r e a t ey o u ro w nb a c k u ps t r a t e g y r e m-T h e/ m i ro p t i o nh a sb e e nl e f to u tf o rs a f e t ys a k e r e m-A d dm o r el i n e sf o re a c hn e wf o l d e rr e q u i r i n gb a c k u p r e m-S p e c i f i e d4t h r e a d st ou s ef o rm u l t i t h r e a d e dc o p y i n g r e m-T h er e s u l t so ft h eb a c k u pc a nb ef o u n di nm y _ b a c k u p _ l o g . t x t r o b o c o p y< s o u r c e >< d e s t i n a t i o n >/ e/ n p/ t e e/ m t : 4/ l o g : m y _ b a c k u p _ l o g . t x t r o b o c o p y< s o u r c e >< d e s t i n a t i o n >/ e/ n p/ t e e/ m t : 4/ l o g + : m y _ b a c k u p _ l o g . t x t r o b o c o p y< s o u r c e >< d e s t i n a t i o n >/ e/ n p/ t e e/ m t : 4/ l o g + : m y _ b a c k u p _ l o g . t x t p a u s e

Tip The can automate your backup's by using the Windows 7 Task Scheduler to run the .BAT file at specific times. For more information please refer to this tutorial by Orbital Shark: Task Scheduler - Create New Task

I hope this brief tutorial helps you access the power and simplicity of ROBOCOPY to create some effective backup strategies. Regards, Golden

18 Sep 2011

#1

Bill2
Windows 7 x64 pro/ Windows 7 x86 Pro/ XP SP3 x86 5,148 posts My System Specs .

Bravo! Well done, Golden!


Tip: Download Windows Repair Tool

www.sevenforums.com/tutorials/187346-robocopy-create-backup-script.html

4/6

29/04/14

ROBOCOPY - Create Backup Script - Windows 7 Help Forums

18 Sep 2011

#2

Golden

Thanks Bill

Windows 7 Ult. x64 Windows 8.1 x64 Ubuntu 12.04 LTS Tri-Boot 14,311 posts South Australia My System Specs 18 Sep 2011 #3

Guy Scharf
Win 7-32, XP Pro-32 80 posts WA My System Specs 18 Sep 2011

Good article, but note that the URL for technet should not have "www." in front of it. The link should be to http://technet.microsoft.com/en-us/library/cc733145(WS.10).aspx.

#4

Golden

Thanks Guy. I've been having some formatting "issues" with http's recently - links corrected.

Windows 7 Ult. x64 Windows 8.1 x64 Ubuntu 12.04 LTS Tri-Boot 14,311 posts South Australia My System Specs 10 Feb 2012 #5 winscp also provides handy automated backups

marcusidle
Windows 7 Home Premium 1 posts My System Specs 27 Feb 2012

Came across this forum while looking for alternative backup strategies. I've found Dropbox and Mozy quite useful, but also winscp (with a bit of work). The first two do continuous backup but winscp is ideal if you want an in-house solution.

#6

BigV
Windows 7 Ultimate x64 20 posts Belgium My System Specs 27 Feb 2012

Brilliant tutorial thanks!

#7

Golden
Quote: Originally Posted by BigV

Brilliant tutorial thanks!

Windows 7 Ult. x64 Windows 8.1 x64 Ubuntu 12.04 LTS Tri-Boot 14,311 posts South Australia My System Specs 05 Mar 2012

Thanks BigV. Many of our MVP's that attend conferences can testify that SevenForums has by far the best tutorials out there.

#8

www.sevenforums.com/tutorials/187346-robocopy-create-backup-script.html

5/6

29/04/14

ROBOCOPY - Create Backup Script - Windows 7 Help Forums

mick1
Windows 7 64bit 17 posts My System Specs 05 Mar 2012

Very Nice , But a person like me who is very new at this computer stuff how can i restore my files from this operation ?? and where can i see them ???

#9

Golden

Hi Mick, Thanks for the comment. ROBOCOPY is designed to backup/copy folders to another destination (different disk, external USB drive). The idea is that if the original files are accidently deleted or damaged, you can simply copy the required from the backup location to where you need them.

Windows 7 Ult. x64 Windows 8.1 x64 Ubuntu 12.04 LTS Tri-Boot 14,311 posts South Australia

If you need help setting up a robocopy script to backup your data, then let me know and I'll write one for you. Regards, Golden

My System Specs Page 1 of 24 1 2 3 11 > Last

ROBOCOPY - Create Backup Script


Recommended Fix: Download Here

Log On Screen - C hange | Windows Media Player Troubleshooting Guide

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

Our Sites Vista Forums Eight Forums Nine Forums PC Help Forum Network Status

Site Links Contact Us Legal Privacy and cookies

About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft C orporation. "Windows 7" and related materials are trademarks of Microsoft C orp. Designer Media Ltd All times are GMT -5. The time now is 03:24 PM.

Find Us

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

www.sevenforums.com/tutorials/187346-robocopy-create-backup-script.html

6/6

S-ar putea să vă placă și