space in the path

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
oracle_coorgi
Posts: 1
Joined: 14 Nov 2010 00:54

space in the path

#1 Post by oracle_coorgi » 14 Nov 2010 01:16

Hi All,

I Have written a batch script to do some backup and restore for sqlserver 2005 database. It WORKS FINE when i hard code the path eg:C:\Users\Public\xxxx.txt
My issue is when i dont hardcode the path then it backups to
eg: C:\Program Files\Microsoft SQL Server\80.................
which is having WHITESPACE there by it doesnot find the file.
How to overcome this issue .
Note:
1. we should not hardcode the path.
2. we should get the file from the eg: C:\Program Files\Microsoft SQL Server\80................. which is having WHITESPACE.

Iam posting the sample batch code

Code: Select all

REM %1 SOURCE USER NAME
REM %2 SOURCE USER PASSWORD
REM %3 SOURCE HOST
REM %4 TRAGET USER NAME
REM %5 TRAGET USER PASSWORD
REM %6 TRAGET HOST
REM %7 SOURCE DATABASE
REM %8 TRAGET DATABASE

echo OSQL -U %1 -P%2 -H %3  > "%0.sql"
echo "BACKUP DATABASE %7 TO DISK = '%7.bak'" >> "%0.sql"
echo go  >> "%0.sql"
echo exit >> "%0.sql"
echo sqlcmd -U %4 -P%5 -H %6 >> "%0.sql"
echo "RESTORE DATABASE %8 FILE = N'%7' FROM  DISK = N'%7.bak' WITH  FILE = 1,  MOVE N'%7' TO N'%8.mdf',  MOVE N'%7_log' TO N'%8.ldf', NOUNLOAD,  REPLACE,  STATS = 10" >> "%0.sql"
echo go >> "%0.sql"
echO exit >> "%0.sql"
sqlcmd -i "%0.sql" -o "%0.log"  -U %4 -P%5 -H %6


AS I am new to this Please Please correct me with the code.

THANKS A LOT IN ADVANCE

Post Reply