?
Solved

DOS batch file backup script

Posted on 2009-04-20
16
Medium Priority
?
2,481 Views
Last Modified: 2012-08-13
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

Open in new window

0
Comment
Question by:parcou
  • 7
  • 6
  • 3
16 Comments
 
LVL 16

Assisted Solution

by:t0t0
t0t0 earned 80 total points
ID: 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.



 
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24194516
Oh, just noticed you ARE already familiar with redirection!!! Sorry for the previous whaffle.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 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
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 16

Expert Comment

by:t0t0
ID: 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
0
 
LVL 16

Expert Comment

by:t0t0
ID: 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.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24195807
And then run the code as is (without taking out the additional ECHOs and REMs) to see the run-effect.
0
 

Author Comment

by:parcou
ID: 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!!!
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 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

Open in new window

0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 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.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 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
0
 

Author Comment

by:parcou
ID: 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
0
 

Author Comment

by:parcou
ID: 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
0
 

Author Comment

by:parcou
ID: 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:
0
 

Author Comment

by:parcou
ID: 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....
0
 

Author Comment

by:parcou
ID: 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
0
 
LVL 21

Accepted Solution

by:
AmazingTech earned 1920 total points
ID: 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

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Migration of Exchange mailbox can be done with the ExProfre.exe tool. But at times, when the ExProfre.exe tool migrates the Exchange Server user profile, it results in numerous synchronization problems. Synchronization error messages appear in the e…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

840 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