August 23, 2013 at 8:47 am
Hi, Can you help me to solve my problem with my script. got an error "sqlcmd' is not recognized as an internal or external command" and below is the full script.
@title Database Backup
@color 0a
rem User to Pre or Post Batch Backup
@echo.
@echo Please select:
@echo 1. Pre-Batch Backup - DATABASE NAME PB
@echo 2. Post-Batch Backup - DATABASE NAME PB
@echo.
choice /C 12 /M "Backup Type :"
IF %ERRORLEVEL%==1 SET var3=Pre-DATABASE NAME-PB-FullBackup-
IF %ERRORLEVEL%==2 SET var3=Post-DATABASE NAME-PB-FullBackup-
rem Get the Batch Processing Day per backup type
@echo.
@echo Please select:
@echo 1. MWF - (Monday,Wednesday, Friday)
@echo 2. TTH - (Tuesday, Thurdsay)
@echo.
choice /C 12 /M "Backup ProcDay :"
IF %ERRORLEVEL%==1 SET var2=MWF
IF %ERRORLEVEL%==2 SET var2=TTH
rem Display Parameters before proceeding
@echo.
@echo ================================================
@echo Backup Parameters for your confirmation....
@echo ================================================
@echo Backup Type : %var3%
@echo Batch ProcDay: %var2%
@echo.
@echo.
choice /C YN /M "Are the parameters correct?"
IF %ERRORLEVEL%==1 SET proceed=Yes
IF %ERRORLEVEL%==2 SET proceed=No
if %proceed%==No (
@echo.
@echo Backup terminated...
@echo.
pause
exit
)
set bkpfilepath=H:\Backup\Full Backup\%var3%%var2%.bak
@echo ================================================
@echo Backing up DATABASE NAME Database. Please Wait....
@echo ================================================
sqlcmd -S SERVERNAME -U USERNAME -P PASSWORD -Q "BACKUP DATABASE [DATABASE NAME] TO DISK = N'%bkpfilepath%' WITH NOFORMAT, INIT, NAME = N'DATABASE NAME-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
set /p var5= Database backup completed. Press any key to continue..
August 23, 2013 at 11:56 am
Looks like just a path issue. Is the account executing the script able to run sqlcmd from the context of the folder that holds the script file? (log on as script user, open cmd prompt, navigate to script folder, exec sqlcmd to see if it runs).
You may need to add the path to sqlcmd (and also ensure the file is installed) to that user's profile, or use the fill path to sqlcmd in your script.
For example, on my laptop, the command would be C:\mssql\DefaultInstance\100\Tools\Binn\sqlcmd.exe <...parameters...>
Eddie Wuerch
MCM: SQL
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply