combining two .bat files Dos and T-SQL
What I would like is to combine the two files into one bat file but currently sqlcmd stops with the sqlqcmd prompt and the SQL is not running.
Ouch server went bang so I need to put contingency in place PDQ
I normally use SQL server agent with some jobs but while the new server is being sorted. I only have SQL express No SQL server agent.
Fine my so I have created a backup.bat it works fine in cmd calling backup.sql the sql send it to another drive.
The statement I used is:-
Sqlcmd –S \mypc\instancename –i C:\backup.sql( as I am local window authentication is fine)
This is so that i can use task scheduler in not very friendly windows 7
At the moment I have a .bat file calling a .sql file.
Backup.bat
Sqlcmd –S \mypc\instancename –i C:\backup.sql
Backup.sql
BACKUP DATABASE [Northwind] TO DISK = N'\\nas1\开发者_如何学JAVAbackup\northwind.bak' WITH NOFORMAT, INIT, NAME = N'Northwind-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'Northwind' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'Northwind' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''Northwind'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM DISK = N'\\nas1\backup\Northwind.bak' WITH FILE = @backupSetId, NOUNLOAD, NOREWIND
GO
What I want is to combine the two files into one bat file but currently sqlcmd stops with the sqlcmd prompt and the SQL is not running.
Sqlcmd –S \mypc\instancename
BACKUP DATABASE [Northwind] TO DISK = N'\\nas1\backup\northwind.bak' WITH NOFORMAT, INIT, NAME = N'Northwind-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
declare @backupSetId as int
select @backupSetId = position from msdb..backupset where database_name=N'Northwind' and backup_set_id=(select max(backup_set_id) from msdb..backupset where database_name=N'Northwind' )
if @backupSetId is null begin raiserror(N'Verify failed. Backup information for database ''Northwind'' not found.', 16, 1) end
RESTORE VERIFYONLY FROM DISK = N'\\nas1\backup\Northwind.bak' WITH FILE = @backupSetId, NOUNLOAD, NOREWIND
GO
Add
quit
as the last line of the .SQL files.
I found using two files works
精彩评论