Need help with batch file backup tool
I've made a batch file to backup certain folders to a USB device. This is what I have so far:
Quote:
@echo off
:: variables
set drive=F:\Backup\"%date:~0,2%-%date:~3,2%-%date:~6,6%"
set backupcmd=xcopy /s /c /e /h /i /y
echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents\"
echo ### Backing up Firefox...
%backupcmd% "%USERPROFILE%\Application Data\Mozilla" "%drive%\Mozilla\"
echo ### Backing up Thunderbird
%backupcmd% "%USERPROFILE%\Application Data\Thunderbird" "%drive%\Thunderbird\"
echo ### Backing up Desktop
%backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop\"
echo Backup Complete!
@pause
Currently, it backs up to a folder called Backup followed by a dated folder on drive F. I know there is a way to prompt for a drive using the /p command but I've not used prompts like this before. How can I prompt for a drive letter and still output a folder called Backup followed by the date?
For example driveletter\Backup\Date
Thanks
Re: Need help with batch file backup tool
If your batch file was called saveme.bat you could enter the following to run it:
saveme g
Which would tell it to backup to drive G
In your batch file you would change it as follows:
@echo off
if %1 == "" goto OOPS
Goto RUNME
:OOPS
echo You must supply a drive letter to backup to eg saveme g
goto END
:RUNME
:: variables
set drive=%1:\Backup\"%date:~0,2%-%date:~3,2%-%date:~6,6%"
set backupcmd=xcopy /s /c /e /h /i /y
echo ### Backing up My Documents...
%backupcmd% "%USERPROFILE%\My Documents" "%drive%\My Documents\"
echo ### Backing up Firefox...
%backupcmd% "%USERPROFILE%\Application Data\Mozilla" "%drive%\Mozilla\"
echo ### Backing up Thunderbird
%backupcmd% "%USERPROFILE%\Application Data\Thunderbird" "%drive%\Thunderbird\"
echo ### Backing up Desktop
%backupcmd% "%USERPROFILE%\Desktop" "%drive%\Desktop\"
echo Backup Complete!
@pause
:END
@echo on
Re: Need help with batch file backup tool
Wouldn't it be simpler to pass the drive letter to the script as an argument?
eg:
set drive=%1:\Backup\"%date:~0,2%-%date:~3,2%-%date:~6,6%"
Then you could just run the command "Mybackup.bat F" where F (or whatever) is the drive letter...
edit: far, far too slow...
Quote:
Originally Posted by
blueball
if %1 == "" goto OOPS
Slight correction (sorry) - %1 needs to be in quotes: if "%1" == "" goto OOPS
...