November 12, 2010 at 11:40 pm
Hi All,
As i am working on batch script to take backup and restore ,it worked fine when i assigne
path eg: 'C:\public\sqlserver_batch\batch_script' , now the requirment is that i dont need to assign the path .If so then the backup is taken "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup" BUT I AM UNABLE TO RESTORE BECAUSE PATH AS WHITESPACE IN BETWEEN
Manually its working whithout the space.
I CANNOT hard code the path
Note:
"C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup" path as to be read to process
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 -n -Q "BACKUP DATABASE %7 TO DISK = '%7.bak'" > "%0.sql"
echo sqlcmd -U %4 -P%5 -H %6 -Q "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"
isql -i "%0.sql" -o "%0.log" -U %4 -P%5 -H %6
[/code]
Please help me with batch script and please let me know where i am worng.
If you all think this can be done in other way PLEASE PUT ACROSS
Thanks A lot in advance
November 13, 2010 at 11:46 pm
Hi All,
I dont know was this the right forum to post or i needed some other. if i have posted this in wrong place PLEASE let me know where i need to post this.
Was this the reason i did not get any Reply / Answer. Can any one please guide me on this issue.
Thanks & Regards
November 14, 2010 at 5:28 am
what you'll need to do is make sure any paths for file names exist in double quotes...that is what the OS requires for file names with spaces; my dbl quotes are slightly out of place, but this should get you started:
i changed part of your command just a bit, see if this works for you:
--example results:
/*
OSQL -U -P -H -n -Q BACKUP DATABASE "" TO DISK = '".bak' > "C:\Users\Lowell\De
sktop\Noname1.bat".sql
sqlcmd -U -P -H -Q RESTORE DATABASE FILE = N'""' FROM DISK = N'".bak"' WITH
FILE = 1, MOVE N'""' TO N'".mdf"', MOVE N'"_log"' TO N'".ldf"', NOUNLOAD, RE
PLACE, STATS = 10" >> ""C:\Users\Lowell\Desktop\Noname1.bat".sql"
*/
echo OSQL -U %1 -P%2 -H %3 -n -Q BACKUP DATABASE "%7" TO DISK = '"%7.bak' > %0.sql
echo sqlcmd -U %4 -P%5 -H %6 -Q 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"
isql -i %0.sql -o %0.log -U %4 -P%5 -H %6
Lowell
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply