Solved

Reliable Copying - Robocopy?

Posted on 2004-09-12
7
1,003 Views
Last Modified: 2012-06-21
Hi

I am currently using Symantec's V2i Server Protector on a Windows 2003 Server and backing up (incrementals) hourly to a network share. This is working fine.

I wish to copy the files in the network share once a day (say 6pm) as a Scheduled Task to an external USB hard drive subject to the following requirements:

- I only wish new files to be copied to the external drive (ie nothing overwritten)
- I want the job to abort and cancel itself if the external drive is not available. Future jobs should still run however without any intervention.
- If an error occurs I would like this logged somewhere in the Windows 2003 Server Event logs and a network or SMTP-relayed email warning sent to one or more network users.

I have taken a look at Robocopy (the Windows 2003 Resource Kit is installed) and this looks to be fine but I wonder how reliable it is and whether it can cope with large files when a full backup is run once a week (~40Gb of data) without taking out the computer to which it is attached!

Can anyone advise on whether the above is possible and also the syntax needed please for whatever utility recommended.

many thanks

Rob
0
Comment
Question by:WebAdviser
  • 4
  • 3
7 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 12038772
First of all: robocopy is definitely the tool to use. It will handle the 40 Gb with a smile on its lips, singlehandedly, with the other hand tied to its back. The exact options to chose depend mainly on your situation; did you notice the robocopy.doc file in the ResKit folder?
To check if the USB drive is accessible, simply test its existence; if you have the W2k Resource Kit (unfortunately, it's not part of the free W2k3 ResKit tools), you can use logevent.exe to create an entry in the event log. For warnings in your network, you can use the good old "net send" (if the messenger service is running), and/or blat.exe to send an email from the command line.
You can schedule this with the regular task scheduler, running under a domain account with the appropriate permissions.
What's not quite clear is the "nothing overwritten" part; what is supposed to happen if an existing document in the backup folder has been changed?

Rough draft:

@echo off
set SourceDir=D:\FileRoot
set TargetDir=U:\Backup
if not exist "%TargetDir%" goto err_Target
...
robocopy "%Source%" "%Target%" -<YourOptions>

goto leave

:err_Target
logevent -m \\YourDC -s F "Backup job failed; USB drive not accessible."
net send SomeMachine "Backup job failed; USB drive not accessible."
blat.exe -t someone@your.domain.local -s "Backup job failed; USB drive not accessible." -f backup@your.domain.local
goto leave

:leave
0
 
LVL 83

Expert Comment

by:oBdA
ID: 12038774
Forgot the blat link, sorry:
What is Blat?
http://www.blat.net/
0
 

Author Comment

by:WebAdviser
ID: 12038836
Thanks oBdA. Your code seems just the job - fantastic response!

You asked: "What's not quite clear is the "nothing overwritten" part; what is supposed to happen if an existing document in the backup folder has been changed?"

This is a fair question. Perhaps some further explanation might be useful here...

The V2i backups consist of one .v2i file per week (full backup file) and one .iv2i file per hour written to the network share. All of the files are written into a single directory as read-only files so can't be changed. All I want to happen is for the files written to the network share since the last scheduled task to be copied to the external drive - not to re-write the whole directory each time to the external drive. This will give maximum efficiency.

In reality the situation is slightly more complex than this as backups are cycled over a period as obviously disk space on the network share (and the external drive) is not unlimited. At the moment the backup jobs cycle every three weeks with the oldest backup files being overwritten in order. I guess the full requirement for this task is for a full comparison of files in the network share and external drive to be undertaken each time the scheduled task runs. This is because as the backups are cycled the base file (.v2i) and ALL of its associated incrementals (.iv2i) files are deleted when a new base file is created.

I hope this makes some sense and possibly you can find a way to incorporate the above in your script.

thanks again

Rob







0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 83

Expert Comment

by:oBdA
ID: 12039004
So the "hourly" files have different names, and there's a new file added to the directory every hour? By default, robocopy won't copy files that already exist in the target directory and have the same size and date as the source file; have a look at the "Using Robocopy File Classes" section in robocopy.doc.
You might want to have a look at robocopy's /mir option; this will keep an exact copy of the source directory, where files in the target are removed automatically if they don't exist anymore in the source.
0
 

Author Comment

by:WebAdviser
ID: 12039033
thanks again oBdA.

So if I read your post and the Robocopy help correctly I could use your code with just /mir as the option then to achieve what I am looking to do?

Rob
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 12039117
If you want the backup folder to be an exact replica of the original folder, that's the easiest option.
You might want to try the /r (number of retries) and /w (wait between retries) options to something useful, in case there are access problems.
As for checking if robocopy was successful, check out the "Return Code" section in robocopy.doc. In your case, it would probably be enough to check for an errorlevel larger than 4. If you create a log file (/log:"%LogFile%"), you can, for example, use the log file as the body of the email if a serious error occurred.
I'd suggest you check out the robocopy documentation and experiment a bit with it; the options are somewhat amazing.
The "Controlling Bandwidth Usage" section might be interesting for you as well, but that depends mainly on when you run the backup and whether robocopy really throttles your network.

@echo off
set SourceDir=D:\FileRoot
set TargetDir=U:\Backup
set LogFile=%Temp%\~Backup~.log

if not exist "%TargetDir%" goto err_Target
robocopy.exe "%Source%" "%Target%" /r:4 /w:5 /mir /log:"%LogFile%"
if errorlevel 4 goto err_robocopy
goto leave

:err_Target
logevent -m \\YourDC -s F "Backup job failed; USB drive not accessible."
net send SomeMachine "Backup job failed; USB drive not accessible."
blat.exe -t someone@your.domain.local -s "Backup job failed; USB drive not accessible." -f backup@your.domain.local
goto leave

:err_robocopy
logevent -m \\YourDC -s F "Backup job failed; errorlevel %Errorlevel% during robocopy."
net send SomeMachine "Backup job failed; errorlevel %Errorlevel% during robocopy."
blat.exe "%LogFile%" -t someone@your.domain.local -s "Backup job failed; errorlevel %Errorlevel% during robocopy." -f backup@your.domain.local
goto leave

:leave
0
 

Author Comment

by:WebAdviser
ID: 12039369
What can I say, fantastic answers!

Points to you oBdA and many many thanks.

Rob
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

Organizations create, modify, and maintain huge amounts of data to help their businesses earn money and generally function.  Typically every network user within an organization has a bit of disk space to store in process items and personal files.   …
by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now