View unanswered posts | View active topics It is currently 22 Oct 2014 19:35



Post new topic Reply to topic  [ 5 posts ] 
Using a batch file to backup data to an external drive help 
Author Message

Joined: 25 Apr 2012 12:09
Posts: 2
Post Using a batch file to backup data to an external drive help
Hi everyone. I am hoping someone on this forum can assist me with this issue.
I have a batch file that we use at work to backup computers. Currently, all of the files associated with the batch file are meant to be put on an external drive. When the batch it run, it creates an additional dir on the external drive where it puts all of the files.
My problem is this. We want to be able to run the batch file from the main drive (C:\) and have it backup to the external drive without hard coding the external drive letter. Can anyone explain to me how to make it prompt for the drive where you want the backup folder to be created and the data moved to?

Here is the first part of my backup batch file:

REM Data Transfer Tool Ver 2.0.0

@echo off

mode con cols=140
mode con lines=400

cls

color 0A


echo BACKUP UTILITY
echo.
echo Machine Name: %COMPUTERNAME% User Name: %USERNAME%
echo.
echo Ready to BACKUP laptop data (Press [CTRL] C to Abort)...
echo.
cd\
pause

echo.
echo START TIME: %TIME%
echo.

if exist UserData\RestoreLog.txt erase UserData\RestoreLog.txt
if exist UserData\BackupLog.txt erase UserData\BackupLog.txt


echo Creating a restore point if Windows Scripting Host Security Settings Allows...
echo.
BIN\CreateRestorePoint.vbs

if exist UserData\%USERNAME%. (rd UserData\%USERNAME% /s/q)
mkdir UserData\%USERNAME%


I hope that makes sense. Thanks in advance for any help or suggestions.

Tripp


25 Apr 2012 12:30
Profile

Joined: 08 Apr 2012 17:11
Posts: 187
Post Re: Using a batch file to backup data to an external drive h
This is untested.
Code:
:prompt
fsutil fsinfo drives
echo,
set /p "driveletter=Drive letter: "
set driveletter=%driveletter:~0,1%:
dir %driveletter% >nul 2>&1^
||echo Drive %driveletter% is not available.&&pause&&exit /b

Another way:
Code:
:prompt
fsutil fsinfo drives
echo,
set /p "driveletter=Drive letter: "
set driveletter=%driveletter:~0,1%:
if not exist %driveletter% (
echo Drive %driveletter% is not available.
pause
exit /b
)

Edit: made some mistakes. Fixed


Last edited by Fawers on 25 Apr 2012 13:43, edited 2 times in total.



25 Apr 2012 13:37
Profile WWW
Online

Joined: 10 Feb 2012 02:20
Posts: 4319
Post Re: Using a batch file to backup data to an external drive h
All references to the utilities will need to be changed too.
It can be done but not without seeing the batch file and knowing what is going on in it.

Is the problem in copying the tools to the external drive, or having to manually launch the backup from the external drive?
You can launch it from c: in a batch file by detecting which drive letter is being used and then using the c: batch file to launch the backup batch file.


25 Apr 2012 13:40
Profile

Joined: 25 Apr 2012 12:09
Posts: 2
Post Re: Using a batch file to backup data to an external drive h
@Fawers: Thanks, I will give that a go.

@foxidrive: Currently we run the batch from an external drive and the data is backed up to the drive the batch file is run from. (For example, the batch files reside on the D: drive and that is also where it creates the UserData directory for the files to be put in.) What we want to do it run the batch file from the C: drive and be able to select the drive letter of the external drive via user input. We dont want to assume the external drive will be D: or E: or whatever. I apologize if I'm explaining this crazy. I hear in my mind how I want it to sound, but it doesn't come out that way in my posts. :lol:


25 Apr 2012 13:52
Profile
Online

Joined: 10 Feb 2012 02:20
Posts: 4319
Post Re: Using a batch file to backup data to an external drive h
Mobjack wrote:
@foxidrive: Currently we run the batch from an external drive and the data is backed up to the drive the batch file is run from. (For example, the batch files reside on the D: drive and that is also where it creates the UserData directory for the files to be put in.) What we want to do it run the batch file from the C: drive and be able to select the drive letter of the external drive via user input. We dont want to assume the external drive will be D: or E: or whatever.


You can place a file in the root of the external drive and then detect the drive letter from a batch file.
Place a blank text file in the root of the external drive called backup.flag and run this batch file from c:

Code:
@echo off
for %%a in (d e f g h i j k l m n o p q r s t u v w x y z ) do if exist "%%a:\backup.flag" set drv=%%a
echo the USB drive is on drive %drv%:
pushd "%drv%:\"
call "normal backup USB.bat"
popd


25 Apr 2012 14:57
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: foxidrive, Google [Bot], Yahoo [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.