Solved

Xcopy backup script

Posted on 2007-11-30
15
5,238 Views
Last Modified: 2012-05-05
I have a batch file that runs xcopy and copies files/folders from one server to another this batch file is scheduled with task scheduler.
I need someone to help elaborate this batch file so that it will be able to do the following tasks:
-it will create a text file that will serve as a log.
  the log will show the start time of the xcopy backup and the end time.
-it will compare the size of the source and destination and logs their sizem in the text file I previously  mentionned.
- it will send email to admin@domain.com with the content of the text file.

the batch file code is:
xcopy /D /s /H I:\source \\servername\destination

Thanks
0
Comment
Question by:jskfan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 20383025
Here is a batch file which should do what you want.  It requires Diruse.exe from the Server 2003 Support Tools and Blat.exe, a free command-line email utility.  These executables should be placed in the same directory as the batch file.
http://www.microsoft.com/downloads/details.aspx?familyid=96A35011-FD83-419D-939B-9A772EA2DF90
http://www.blat.net

I left your xcopy command as you had it, but note that the /D switch should include a date.


@echo off
setlocal
 
REM File locations
set log=copylog.txt
set source=I:\source
set dest=\\servername\destination
 
REM Email options
set to=-to admin@domain.com
set from=-f admin@domain.com
set subject=-subject "Auto Message: copy log %date%%time%"
set smtp=-server yoursmtpserver.domain.com
 
REM Generates log and copies files
if exist "%log%" del "%log%"
echo Start time: %date%%time% >> "%log%"
for /F "tokens=1 usebackq" %%G in (`diruse "%source%" /M`) do set sourcesize=%%G
for /F "tokens=1 usebackq" %%G in (`diruse "%dest%" /M`) do set destsizepre=%%G
echo Source size before copy: %sourcesize% MB >> "%log%"
echo Destination size before copy: %destsizepre% MB >> "%log%"
xcopy /D /s /H "%source%" "%dest%" > NUL 2>&1
for /F "tokens=1 usebackq" %%G in (`diruse "%dest%" /M`) do set destsizepost=%%G
echo Destination size after copy: %destsizepost% MB >> "%log%"
echo Finish time: %date%%time% >> "%log%"
 
REM Emails log
blat "%log%" %to% %from% %subject% %smtp%
 
endlocal

Open in new window

0
 

Author Comment

by:jskfan
ID: 20384073
where does the xcopy fit in your script?
xcopy /D /s /H I:\source \\servername\destination


0
 
LVL 38

Expert Comment

by:Shift-3
ID: 20384518
Line 22.  

I:\Source is set as the Source variable on Line 6.
\\servername\destination is set as the Dest variable on Line 7.
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 

Author Comment

by:jskfan
ID: 20384678
so do I need to leave that batch file that has xcopy /D /s /H I:\source \\servername\destination
in a separate file?
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 20384802
No.  This script incorporates that command on Line 22.
0
 

Author Comment

by:jskfan
ID: 20390228
by the way, since nobody will be logged on to the source(server1) and nobody will be logged on to the destination(server2), in this case would the script run as it is scheduled with scheduled task?
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 20390237
You should change "I:\source" in the Source variable to a UNC path (e.g. \\server\share\source) if it will be running as a scheduled task.  Otherwise it should work fine.
0
 

Author Comment

by:jskfan
ID: 20395335
it works fine. the only thing that is not working is the email. I haven't received an email after the backuo jobs done and the log file was logged.
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 20396234
Did you customize the smtp variable under "REM Email options" with the name of your SMTP server?  Do you receive email if you run the Blat command manually?
0
 

Author Comment

by:jskfan
ID: 20396413
<<Do you receive email if you run the Blat command manually?>>>

how do you use it?
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 20402540
You can view all the switches by typing Blat /?, but all you really need to test it is

blat somefile.txt -to admin@domain.com -f admin@domain.com subject "test message" -server yoursmtpserver.domain.com
0
 

Author Comment

by:jskfan
ID: 20402819
yoursmtpserver  you mean my exchange server. correct?
well i tried it and it hasn't sent me any message. Is the machine from where I am running the Blat command supposed to have SMTP service on it?
0
 

Author Comment

by:jskfan
ID: 20402845
I guess it worked now after removing the word subject and the word "text message"
0
 

Author Comment

by:jskfan
ID: 20402980
excellent!!!!!!
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 20403351
Ah, I missed a dash.  It should be -subject.
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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