Question

DOS batch file backup script

Asked by: parcou

How can I modify the code\script below to:
-exclude specific file types (eg. mp3, m4a, mpg, etc)
-hide\mask the error message when it searches for the SD\USB drive name on each pass
-run minimized (optional)

Goal: We have laptops with SD drives and I have added a 32GB SD to each PC. I want to run an automated backup controlled by a batch file (see code below) and use Windows Task Scheduler to kick off the backup at a scheduled time daily. Yeah poor man way but boss will not offer any assistance so I have to work with a homebrew :-) My users need a backup safety net...

---------
I have a DOS code below created by one of the great users here. It works great but I need to take it up a notch.

-The script will search for a USB (SD soon) drive name 'IMG DRV' or whatever I call it

-Currently it is set to search drive letters (C,D,E,F,G,I,J). I usually do not see letters higher than J. Beforehand it was set all the way to 'Z' but it hangs on network drives until it times out.

-I get an error (nothing major but will alarm users) when running the drive look-up cycle until it finds the correct drive letter. I added the 'cls' between the script below to try clearing it on each drive letter look-up pass. Beforehand it listed a drive look-up error for each following letter on a new line until the drive was finally found. I WOULD LIKE to hide/mask that if possible until the letter is found.

(extracted from the code below)
"%%y"=="%testfor%" set drive=%test%:
cls <--- I added this was not there before......
goto end

-Last part of the code will copy the needed data to a USB drive or in my case will be the attached SD drive on the laptop. I WILL ADD more lines of data in the script to backup but I want to EXCLUDE certain file types like (music, movies, videos, etc). How can I do that?

Please help me modify or rewrite this code if needed for my two (three) main questions above. My DOS knowledge is beginner.

Thx

@echo off
 
REM ---------
REM BACKUP
REM ---------
ECHO -------------------------------------------------------
ECHO CLOSE ALL PROGRAMS and APPLICATIONS NOW!!
ECHO -------------------------------------------------------
ECHO.
ECHO Your hard drive is about to be searched for Documents,
ECHO Databases, Spreadsheets, and Email storage files.
ECHO.
ECHO All files of these types will be saved to 
ECHO your REMOVABLE DEVICE in their original
ECHO directories\folders.
ECHO.
ECHO This will replace any previous backup on the
ECHO removable drive.
ECHO.
 
PAUSE
 
 
REM -------------------------------------------------------------------------------------
REM Finding Removable Drive Letter Code...
REM -------------------------------------------------------------------------------------
 
REM The string below will be for the DRIVE Name eg. set testfor=ABS
set testfor=IMG_DRV
set drive=unknown
 
for %%a in (C,D,E,F,G,I,J) do call :testdrive %%a
goto continue
 
:testdrive
set test=%1
REM Use Dir to get drive label.  Sets drive variable
for /f "tokens=5,*" %%x in ('dir %test%:\*.* 2^>NUL ^| find /i "volume in drive"') do if /i "%%y"=="%testfor%" set drive=%test%:
cls
goto end
 
:continue
cls
echo.
echo USB drive was found...
echo.
echo The drive name is. %testfor% 
echo Drive letter is.  %drive%
echo.
echo.
REM xcopy c:\source\*.* %drive%\backup /e /i /y
 
pause
cls
 
 
 
REM -------------------------------------------------------------------------------------
REM Starting Backup Routine...
REM -------------------------------------------------------------------------------------
 
ECHO Copying "My Documents" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\My Documents\*.*" "%drive%\_Rep_Backup\%username%\My Documents" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Desktop" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\Desktop\*.*" "%drive%\_Rep_Backup\%username%\Desktop" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Favorites" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\Favorites\*.*" "%drive%\_Rep_Backup\%username%\Favorites" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Email Storage" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Outlook\*.pst" "%drive%\_Rep_Backup\%username%\Outlook\" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Email Nickname File" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Application Data\Microsoft\Outlook\*.nk2" "%drive%\_Rep_Backup\%username%\Outlook_NK2\" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "AXSOne" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\AXSOne\*.*" "%drive%\_Rep_Backup\%username%\AXSOne" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Siebel-SROC Database" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Program Files\Siebel\7.7\web client\LOCAL\*.*" "%drive%\_Rep_Backup\%username%\SROC\Local" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "I-ROAM Database" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Program Files\NikeGolf I-ROAM\*.sdf" "%drive%\_Rep_Backup\%username%\IROAM" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Wallpaper" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\*.bmp" "%drive%\_Rep_Backup\%username%\" /e /h /i /y
 
 
dir %drive%\_Rep_Backup\%username%\ /s > %drive%\_Rep_Backup\%username%\backup_log.txt
 
 
 
cls
ECHO.
ECHO Your BACKUP has been completed!!!.  
ECHO It is located on your removable device
ECHO in a folder called: _Rep_Backup
ECHO.
ECHO You may disconnect your device from the PC!
ECHO.
ECHO Please continue to periodically backup...
ECHO.
ECHO.
ECHO Systems Tech Support
ECHO.
PAUSE

                                  
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:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-04-20 at 20:55:53ID24340013
Tags

dos

,

windows xp

Topics

MS DOS

,

Windows XP Operating System

Participating Experts
2
Points
500
Comments
16

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Midi music on Flash 5 movie
    Greetings, How do I incorporate midi music file on Flash 5 movie? As midi is not natively supported in Flash, wouldn't it take a long time to download Flash movies on browsers if mp3 are incorporated in Flash movies? How do I convert midi file to wav format? TIA
  2. MP3 music
    Let's say I download a music file and it's bitrate is 128kps. And let's say it's size is 5mb and the sound if good. But what would happen if I converted that same 128kps song to a 196kps song. The size would probably jump from 5mb's to say 8mb's. But would the actual song sou...
  3. Adding .mp3 background music to my Photo Gallery
    Hi! I have downloaded the Phot Gallery applictionto run on the web. It seems the entire code for Gallery is written using XML. I am using FrontPage 2003 to call the .html files of the web based Photo Gallery. I would like to add the background music (.mp3 files that can be...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: t0t0Posted on 2009-04-21 at 06:53:01ID: 24194312

why not use redirection?

You can redirect standard output and AND standard errors

if you append '>NUL' to the end of a line, output is redirected (in this case) to the NUL device - ie, it just doesn't go anywhere and therefore won't be displayed. Try this:

   ECHO Hello World>NULL

It just disappears. You can also redirect output to a file such as:

   ECHO Hello World>c:\file.txt

Again, nothing appears on the screen however, this time, a file is created (C:\FILE.TXT) and if you examine it's contents using TYPE FILE.TXT then you will see the text "Hello World".

Now, if you run a batch file with ECHO ON rather than ECHO OFF, then you'll see DOS expand the command line from:

   ECHO Hello World>NUL

to:

   ECHO Hello World 1>NUL

Interesting!!!! You can actually just add the line "ECHO Hello World 1>NUL" yourself and DOS won't have to do the conversion for you.

Anyway, the '1>NUL' instructs DOS to output all standard output to the NUL device (or in the case of 1>C:\FILE.TXT, to a text file named FILE.TXT in the root folder of drive C:).

Now then... Just as you can redirect standard output, you can ALSO redirect standard error messages as in:

   ECHO Hello World 2>NUL

Hmmm..... What's going on here then. Here, the text "Hello World" is displayed on the screen as usual and because there are no errors, nothing is redirected however, if we did something like:

   TYPE X:\file.txt

If the drive X: does not exist, you're going to get an error on the screen hoever, if you redirect all errormessages as in:

   TYPE X:\file.txt 2>NUL

The this time, if the drive (or the file) do not exist then the error message will just get sent to NUL (nowhere) - which is great because it doesn't mess up your screen.

Finally, how about this:

   TYPE c:\file.txt 1>c:\file2.txt 2>NUL

This says, write the contents of the file C:\FILE.TXT to the file C:\FILE2.TXT (rather than the screen) AND write any errors to the NUL device  (should there be any!).

You could have also done:

   TYPE c:\file.txt 1>"c:\output file.txt" 2>"error file.txt"

Here's a variation (Try it)....

>>file.txt ECHO Hello World
>>file.txt ECHO Hello Again....

Google redirection, it's fascinating and it has many powerful and everyday uses.

Final word:

   ECHO Hello World 1>file.txt

the '>' will CREAT the file FILE.TXT whereas using '>>' will APPEND to the file as in:

   ECHO Hello World 1>>file.txt

Try it. Experiment. Have fun.



 

 

by: t0t0Posted on 2009-04-21 at 07:07:31ID: 24194516

Oh, just noticed you ARE already familiar with redirection!!! Sorry for the previous whaffle.

 

by: t0t0Posted on 2009-04-21 at 07:51:50ID: 24195073

How about testing for each drive first as in:

   IF EXIST x:\ (
      SET drive=x
   ) ELSE (
      SET drive=
   )

This also works too...

   IF EXIST x:\NUL (
   ...
   ...

So, you could do something like:

   for %%a in (C,D,E,F,G,I,J) do if exist %%a:\nul call :your_process_name %%a

 

by: t0t0Posted on 2009-04-21 at 08:31:04ID: 24195575

Please try this.... remove the added ECHO and REM statements to perform the XCOPYs etc...

@echo off
 
REM ---------
REM BACKUP
REM ---------
ECHO -------------------------------------------------------
ECHO CLOSE ALL PROGRAMS and APPLICATIONS NOW!!
ECHO -------------------------------------------------------
ECHO.
ECHO Your hard drive is about to be searched for Documents,
ECHO Databases, Spreadsheets, and Email storage files.
ECHO.
ECHO All files of these types will be saved to
ECHO your REMOVABLE DEVICE in their original
ECHO directories\folders.
ECHO.
ECHO This will replace any previous backup on the
ECHO removable drive.
ECHO.
 
rem PAUSE

REM -------------------------------------------------------------------------------------
REM Finding Removable Drive Letter Code...
REM -------------------------------------------------------------------------------------
 
REM The string below will be for the DRIVE Name eg. set testfor=ABS
set testfor=IMG_DRV
set drive=unknown

echo Searching for removable drive...

for %%a in (C,D,E,F,G,I,J) do (
   call :testdrive %%a
   if not defined drive (
      echo Cannot find USB drive. Backup aborted.
      exit /b 1
   )
)

rem cls
echo.
echo USB drive was found...
echo.
echo The drive name is. %testfor%
echo Drive letter is.  %drive%
echo.
echo.
echo xcopy c:\source\*.* %drive%\backup /e /i /y
 
rem pause
rem cls
 
REM -------------------------------------------------------------------------------------
REM Starting Backup Routine...
REM -------------------------------------------------------------------------------------
 
ECHO Copying "My Documents" Folder to Backup device...
ECHO.
ECHO.
echo xcopy "c:\Documents and Settings\%username%\My Documents\*.*" "%drive%\_Rep_Backup\%username%\My Documents" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Desktop" Folder to Backup device...
ECHO.
ECHO.
echo xcopy "c:\Documents and Settings\%username%\Desktop\*.*" "%drive%\_Rep_Backup\%username%\Desktop" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Favorites" Folder to Backup device...
ECHO.
ECHO.
echo xcopy "c:\Documents and Settings\%username%\Favorites\*.*" "%drive%\_Rep_Backup\%username%\Favorites" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Email Storage" Folder to Backup device...
ECHO.
ECHO.
echo xcopy "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Outlook\*.pst" "%drive%\_Rep_Backup\%username%\Outlook\" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Email Nickname File" Folder to Backup device...
ECHO.
ECHO.
echo xcopy "C:\Documents and Settings\%username%\Application Data\Microsoft\Outlook\*.nk2" "%drive%\_Rep_Backup\%username%\Outlook_NK2\" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "AXSOne" Folder to Backup device...
ECHO.
ECHO.
echo xcopy "C:\AXSOne\*.*" "%drive%\_Rep_Backup\%username%\AXSOne" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Siebel-SROC Database" Folder to Backup device...
ECHO.
ECHO.
echo xcopy "C:\Program Files\Siebel\7.7\web client\LOCAL\*.*" "%drive%\_Rep_Backup\%username%\SROC\Local" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "I-ROAM Database" Folder to Backup device...
ECHO.
ECHO.
echo xcopy "C:\Program Files\NikeGolf I-ROAM\*.sdf" "%drive%\_Rep_Backup\%username%\IROAM" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Wallpaper" Folder to Backup device...
ECHO.
ECHO.
echo xcopy "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\*.bmp" "%drive%\_Rep_Backup\%username%\" /e /h /i /y
 
rem  dir %drive%\_Rep_Backup\%username%\ /s > %drive%\_Rep_Backup\%username%\backup_log.txt
 
rem cls
ECHO.
ECHO Your BACKUP has been completed!!!.  
ECHO It is located on your removable device
ECHO in a folder called: _Rep_Backup
ECHO.
ECHO You may disconnect your device from the PC!
ECHO.
ECHO Please continue to periodically backup...
ECHO.
ECHO.
ECHO Systems Tech Support
ECHO.
rem PAUSE
exit /b

rem ==========================================
rem TESTDRIVE
rem ==========================================
:testdrive
set test=%1
REM Use Dir to get drive label.  Sets drive variable
for /f "tokens=5,*" %%x in ('dir %test%:\*.* 2^>NUL ^| find /i "volume in drive"') do (
   if /i "%%y"=="%testfor%" set drive=%test%:
)
exit /b

 

by: t0t0Posted on 2009-04-21 at 08:47:54ID: 24195794

Sorry... Replace:

REM The string below will be for the DRIVE Name eg. set testfor=ABS
set testfor=IMG_DRV
set drive=unknown

with the following:

REM The string below will be for the DRIVE Name eg. set testfor=ABS
set testfor=IMG_DRV
set drive=

This will ensure the batch file aborts if it cannot find the drive.

 

by: t0t0Posted on 2009-04-21 at 08:49:14ID: 24195807

And then run the code as is (without taking out the additional ECHOs and REMs) to see the run-effect.

 

by: parcouPosted on 2009-04-21 at 09:13:27ID: 24196053

t0t0

I am not familiar with DOS and the code was written by someone else for me I posted it here to modify it a bit.

1. Thx the tutorial I am read word for word. I will test all the examples shortly
2. Help me out a bit more since I am green. Can you copy part of the code and insert you you recommend in there for me. I am not sure where to add it. I assume between lines 34-41.

3. Any idea on how I can exclude file types in this code for the xcopy process

THX!!!

 

by: AmazingTechPosted on 2009-04-21 at 09:18:03ID: 24196104

Create a file "ExcludeExt.txt" with the extensions you want to exclude 1 on each line in the same folder as your batch file.

.mp3
.avi
.mpg

The exclude will exclude if the match is found in the entire path so

C:\Music files all .mp3\AlbumListing.doc

Will be excluded because the folder name has .mp3

Your script doesn't have a label END so I changed it to :EOF.

I added code to remove network drives found with "net use".  You might still have a problem with CDROM drives not accessible.

I would probably think changing the script to use WMIC and querying removeable drives would be better.

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
 
REM ---------
REM BACKUP
REM ---------
ECHO -------------------------------------------------------
ECHO CLOSE ALL PROGRAMS and APPLICATIONS NOW!!
ECHO -------------------------------------------------------
ECHO.
ECHO Your hard drive is about to be searched for Documents,
ECHO Databases, Spreadsheets, and Email storage files.
ECHO.
ECHO All files of these types will be saved to 
ECHO your REMOVABLE DEVICE in their original
ECHO directories\folders.
ECHO.
ECHO This will replace any previous backup on the
ECHO removable drive.
ECHO.
 
PAUSE
 
 
REM -------------------------------------------------------------------------------------
REM Finding Removable Drive Letter Code...
REM -------------------------------------------------------------------------------------
 
REM The string below will be for the DRIVE Name eg. set testfor=ABS
set testfor=IMG_DRV
set drive=unknown
set drives=C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
 
Set AllNetworkLetters=
for /f "tokens=1 delims=:" %%a in ('net use ^| find ":"') do (
    Set NetworkLetter=%%a
    Set AllNetworkLetters=!AllNetworkLetters!,!NetworkLetter:~-1!
)
 
 
for %%a in (%AllNetworkLetters%) do (
    Set Drives=!Drives:%%a=!
    Set Drives=!Drives:,,=,!
)
 
Echo %Drives%
Pause
 
for %%a in (%Drives%) do call :testdrive %%a
goto continue
 
:testdrive
set test=%1
REM Use Dir to get drive label.  Sets drive variable
for /f "tokens=5,*" %%x in ('dir %test%:\*.* 2^>NUL ^| find /i "volume in drive"') do if /i "%%y"=="%testfor%" set drive=%test%:
cls
goto :EOF
 
:continue
cls
echo.
echo USB drive was found...
echo.
echo The drive name is. %testfor% 
echo Drive letter is.  %drive%
echo.
echo.
REM xcopy c:\source\*.* %drive%\backup /EXCLUDE:"%~dp0\ExcludeExt.txt" /e /i /y
 
pause
cls
 
 
 
REM -------------------------------------------------------------------------------------
REM Starting Backup Routine...
REM -------------------------------------------------------------------------------------
 
ECHO Copying "My Documents" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\My Documents\*.*" "%drive%\_Rep_Backup\%username%\My Documents" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Desktop" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\Desktop\*.*" "%drive%\_Rep_Backup\%username%\Desktop" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Favorites" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\Favorites\*.*" "%drive%\_Rep_Backup\%username%\Favorites" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Email Storage" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Outlook\*.pst" "%drive%\_Rep_Backup\%username%\Outlook\" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Email Nickname File" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Application Data\Microsoft\Outlook\*.nk2" "%drive%\_Rep_Backup\%username%\Outlook_NK2\" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "AXSOne" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\AXSOne\*.*" "%drive%\_Rep_Backup\%username%\AXSOne" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Siebel-SROC Database" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Program Files\Siebel\7.7\web client\LOCAL\*.*" "%drive%\_Rep_Backup\%username%\SROC\Local" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "I-ROAM Database" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Program Files\NikeGolf I-ROAM\*.sdf" "%drive%\_Rep_Backup\%username%\IROAM" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Wallpaper" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\*.bmp" "%drive%\_Rep_Backup\%username%\" /e /h /i /y
 
 
dir %drive%\_Rep_Backup\%username%\ /s > %drive%\_Rep_Backup\%username%\backup_log.txt
 
 
 
cls
ECHO.
ECHO Your BACKUP has been completed!!!.  
ECHO It is located on your removable device
ECHO in a folder called: _Rep_Backup
ECHO.
ECHO You may disconnect your device from the PC!
ECHO.
ECHO Please continue to periodically backup...
ECHO.
ECHO.
ECHO Systems Tech Support
ECHO.
PAUSE
                                              
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:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:

Select allOpen in new window

 

by: AmazingTechPosted on 2009-04-21 at 09:19:19ID: 24196116

Opps. For my testing lines 46 and 47 can be removed when you give this to your users. It merely shows the letters it will use to search/test for.

 

by: t0t0Posted on 2009-04-21 at 09:31:11ID: 24196252

AmazingTech
Hello.... Just gonna look at your code in a mo to see if I've missed something myself....

parcou
In the meantime, here's your code (edited). It should work to the specs you've given....



@echo off
 
REM ---------
REM BACKUP
REM ---------
ECHO -------------------------------------------------------
ECHO CLOSE ALL PROGRAMS and APPLICATIONS NOW!!
ECHO -------------------------------------------------------
ECHO.
ECHO Your hard drive is about to be searched for Documents,
ECHO Databases, Spreadsheets, and Email storage files.
ECHO.
ECHO All files of these types will be saved to
ECHO your REMOVABLE DEVICE in their original
ECHO directories\folders.
ECHO.
ECHO This will replace any previous backup on the
ECHO removable drive.
ECHO.
 
PAUSE

REM -------------------------------------------------------------------------------------
REM Finding Removable Drive Letter Code...
REM -------------------------------------------------------------------------------------
 
REM The string below will be for the DRIVE Name eg. set testfor=ABS
set testfor=IMG_DRV
set drive=

echo Searching for removable drive...

for %%a in (C,D,E,F,G,I,J) do (
   call :testdrive %%a
   if not defined drive (
      echo Cannot find USB drive. Backup aborted.
      exit /b 1
   )
)

cls
echo.
echo USB drive was found...
echo.
echo The drive name is. %testfor%
echo Drive letter is.  %drive%
echo.
echo.
rem copy c:\source\*.* %drive%\backup /e /i /y
 
pause
cls
 
REM -------------------------------------------------------------------------------------
REM Starting Backup Routine...
REM -------------------------------------------------------------------------------------
 
ECHO Copying "My Documents" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\My Documents\*.*" "%drive%\_Rep_Backup\%username%\My Documents" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Desktop" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\Desktop\*.*" "%drive%\_Rep_Backup\%username%\Desktop" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Favorites" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\Favorites\*.*" "%drive%\_Rep_Backup\%username%\Favorites" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Email Storage" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Outlook\*.pst" "%drive%\_Rep_Backup\%username%\Outlook\" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Email Nickname File" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Application Data\Microsoft\Outlook\*.nk2" "%drive%\_Rep_Backup\%username%\Outlook_NK2\" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "AXSOne" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\AXSOne\*.*" "%drive%\_Rep_Backup\%username%\AXSOne" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Siebel-SROC Database" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Program Files\Siebel\7.7\web client\LOCAL\*.*" "%drive%\_Rep_Backup\%username%\SROC\Local" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "I-ROAM Database" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Program Files\NikeGolf I-ROAM\*.sdf" "%drive%\_Rep_Backup\%username%\IROAM" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Wallpaper" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\*.bmp" "%drive%\_Rep_Backup\%username%\" /e /h /i /y
 
dir %drive%\_Rep_Backup\%username%\ /s > %drive%\_Rep_Backup\%username%\backup_log.txt
 
cls
ECHO.
ECHO Your BACKUP has been completed!!!.  
ECHO It is located on your removable device
ECHO in a folder called: _Rep_Backup
ECHO.
ECHO You may disconnect your device from the PC!
ECHO.
ECHO Please continue to periodically backup...
ECHO.
ECHO.
ECHO Systems Tech Support
ECHO.
PAUSE
exit /b

rem ==========================================
rem TESTDRIVE
rem ==========================================
:testdrive
set test=%1
REM Use Dir to get drive label.  Sets drive variable
for /f "tokens=5,*" %%x in ('dir %test%:\*.* 2^>NUL ^| find /i "volume in drive"') do (
   if /i "%%y"=="%testfor%" set drive=%test%:
)
exit /b

 

by: parcouPosted on 2009-04-26 at 22:27:38ID: 24239049

t0t0

Sorry for the delay suffered a family loss so I was out a few days...back to business...

I tested (coped) the code as is but I cannot get it to complete. I run the bat file and as soon as I see the:

Searching for removable drive...

the command window closes...what am I missing? I have the USB drive attached by the correct volume name but I see nothing else in the code because the window closes after the echo string above

 

by: parcouPosted on 2009-04-26 at 23:15:23ID: 24239200

AmazingTech

Your code is working perfectly. I have not tested the exclude code yet will do so in the morning... One question. I ran the script with the USB drive removed although it said it was not found it will run the code xcopy the files but with no backup drv attached it goes no where:

How could you add a simple code IF drv by volume name is not found it goes to :end where I can echo a message 'no drive found terminating backup"....?

Thx

 

by: parcouPosted on 2009-04-27 at 00:07:27ID: 24239390

AmazingTech

Not having much luck with the EXCLUDE....can you explain to me how to code is called in the script where you added /EXCLUDE:

 

by: parcouPosted on 2009-04-27 at 08:15:17ID: 24242612

AmazingTech...

I did figure out that the /EXCLUDE:"%~dp0\ExcludeExt.txt" would show in the command window as:

cannot read: "e:\\excludeExt.txt"

by putting a pause in the code. I changed it to: /EXCLUDE:"%~dp0ExcludeExt.txt" and it shows as:

cannot read: "e:\excludeExt.txt"

Although the file is there I still cannot get the script to read it....

 

by: parcouPosted on 2009-04-27 at 09:04:10ID: 24243112

AmazingTech

Got the exclude to work found by just putting in a direct path to the c: drive over the %~dp0

I am almost there:

Can you help me with the other question above:

Your code is working perfectly. I have not tested the exclude code yet will do so in the morning... One question. I ran the script with the USB drive removed although it said it was not found it will run the code xcopy the files but with no backup drv attached it goes no where:

How could you add a simple code IF drv by volume name is not found it goes to :end where I can echo a message 'no drive found terminating backup"....?

Thx

 

by: AmazingTechPosted on 2009-04-27 at 11:29:52ID: 24244323

Hmm... Sorry I haven't been on Experts Exchange much. I've been busy with other things.

Will you only ever have 1 removable drive with IMG_DRV? Because the script currently will only back up the last one found.

Anyways here's the update you wanted (if I understand what you want).

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
 
REM ---------
REM BACKUP
REM ---------
ECHO -------------------------------------------------------
ECHO CLOSE ALL PROGRAMS and APPLICATIONS NOW!!
ECHO -------------------------------------------------------
ECHO.
ECHO Your hard drive is about to be searched for Documents,
ECHO Databases, Spreadsheets, and Email storage files.
ECHO.
ECHO All files of these types will be saved to 
ECHO your REMOVABLE DEVICE in their original
ECHO directories\folders.
ECHO.
ECHO This will replace any previous backup on the
ECHO removable drive.
ECHO.
 
PAUSE
 
 
REM -------------------------------------------------------------------------------------
REM Finding Removable Drive Letter Code...
REM -------------------------------------------------------------------------------------
 
REM The string below will be for the DRIVE Name eg. set testfor=ABS
set testfor=IMG_DRV
set drive=unknown
set drives=C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
 
Set AllNetworkLetters=
for /f "tokens=1 delims=:" %%a in ('net use ^| find ":"') do (
    Set NetworkLetter=%%a
    Set AllNetworkLetters=!AllNetworkLetters!,!NetworkLetter:~-1!
)
 
 
for %%a in (%AllNetworkLetters%) do (
    Set Drives=!Drives:%%a=!
    Set Drives=!Drives:,,=,!
)
 
Echo %Drives%
Pause
 
for %%a in (%Drives%) do call :testdrive %%a
if /i "%drive%" == "unknown" (
    echo No drive with LABEL: %testfcr% was found. Terminating backup.
    goto :EOF
) else (
    goto continue
)
 
:testdrive
set test=%1
REM Use Dir to get drive label.  Sets drive variable
for /f "tokens=5,*" %%x in ('dir %test%:\*.* 2^>NUL ^| find /i "volume in drive"') do if /i "%%y"=="%testfor%" set drive=%test%:
cls
goto :EOF
 
:continue
cls
echo.
echo USB drive was found...
echo.
echo The drive name is. %testfor% 
echo Drive letter is.  %drive%
echo.
echo.
REM xcopy c:\source\*.* %drive%\backup /EXCLUDE:"%~dp0\ExcludeExt.txt" /e /i /y
 
pause
cls
 
 
 
REM -------------------------------------------------------------------------------------
REM Starting Backup Routine...
REM -------------------------------------------------------------------------------------
 
ECHO Copying "My Documents" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\My Documents\*.*" "%drive%\_Rep_Backup\%username%\My Documents" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Desktop" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\Desktop\*.*" "%drive%\_Rep_Backup\%username%\Desktop" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Favorites" Folder to Backup device...
ECHO.
ECHO.
xcopy "c:\Documents and Settings\%username%\Favorites\*.*" "%drive%\_Rep_Backup\%username%\Favorites" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Email Storage" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\Outlook\*.pst" "%drive%\_Rep_Backup\%username%\Outlook\" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Email Nickname File" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Application Data\Microsoft\Outlook\*.nk2" "%drive%\_Rep_Backup\%username%\Outlook_NK2\" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "AXSOne" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\AXSOne\*.*" "%drive%\_Rep_Backup\%username%\AXSOne" /e /h /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Siebel-SROC Database" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Program Files\Siebel\7.7\web client\LOCAL\*.*" "%drive%\_Rep_Backup\%username%\SROC\Local" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "I-ROAM Database" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Program Files\NikeGolf I-ROAM\*.sdf" "%drive%\_Rep_Backup\%username%\IROAM" /e /i /y
 
ECHO.
ECHO.
 
ECHO Copying "Wallpaper" Folder to Backup device...
ECHO.
ECHO.
xcopy "C:\Documents and Settings\%username%\Local Settings\Application Data\Microsoft\*.bmp" "%drive%\_Rep_Backup\%username%\" /e /h /i /y
 
 
dir %drive%\_Rep_Backup\%username%\ /s > %drive%\_Rep_Backup\%username%\backup_log.txt
 
 
 
cls
ECHO.
ECHO Your BACKUP has been completed!!!.  
ECHO It is located on your removable device
ECHO in a folder called: _Rep_Backup
ECHO.
ECHO You may disconnect your device from the PC!
ECHO.
ECHO Please continue to periodically backup...
ECHO.
ECHO.
ECHO Systems Tech Support
ECHO.
PAUSE

                                              
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:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:

Select allOpen in new window

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...