SQL Server
(1)
Backup
(1)
Disk
(1)
Database
(1)
Alejandro
(1)
Demarce
(1)
Mesa
(1)
Leo
(1)

Creating a Backup Batch File for SQL 2005 Express

Asked By LeoDemarc
22-Aug-07 09:34 AM
I have 2 parts to this question based on this problem; I need to create a
scheduled backup for my SQL 2005 Express databases, but the Management Studio
Express does not come with an agent to process scheduled backups.

Part 1: has there been any kind of release from Microsoft to provide this
tool? Is there something I'm missing that I can download?

Part 2: assuming Part 1 is no, I have done research and have been trying to
figure out how to create a batch file that will perform the backups, that I
can attach to a basic windows schedule. This is what I have discovered:
I can, for a command prompt, initialize a sqlcmd, then I can, manually from
the sqlcmd prompt, perform a backup. This is the generic code that I have
created:

from the command prompt
C:\>sqlcmd
1>EXEC sp_addumpdevice 'disk', 'database_backup',
2>'D:\Backupfolder\database_backup.bak'
3>BACKUP DATABASE database TO database_backup
4>GO
5>exit
C:\>

When I put this in a batch file and execute the batch file it stops after
the sqlcmd, where the command prompt sits at the first line 1>.

I am at a loss as to what I need to do, am I on the right track?
Thanks in advance for any assistance, my experience in the past has always
been exceptional.
Leo Demarce

Leo Demarce,You need to use parameters, like [-i inputfile].

Asked By AlejandroMes
22-Aug-07 09:42 AM
Leo Demarce,

You need to use parameters, like [-i inputfile]. For more info, check
following links.

Using the sqlcmd Utility (SQL Server Express)
http://msdn2.microsoft.com/en-us/library/ms165702.aspx

sqlcmd Utility Tutorial
http://msdn2.microsoft.com/en-us/library/ms170207.aspx


AMB

Thank you so much!

Asked By LeoDemarc
22-Aug-07 10:12 AM
Thank you so much! That is what I was looking for.

Here is the results:
I created a batch file called backup.bat with the following code:
c:
cd\backup
del samincbu.bak
sqlcmd -i c:\backup\backup.sql

I then created the following code in the backup.sql file:
EXEC sp_addumpdevice 'disk', 'samincbu',
'c:\Backup\samincbu.bak'
BACKUP database saminc TO samincbu
GO

The batch file is used to remove the old backup, then start the sqlcmd with
the backup.sql as the list of T-SQL commands. The backup.sql commands perform
the database backup. I am then able to schedule the batch file in the windows
scheduler. And then, from there, am able to automate a backup program.
Once again, thank you for your fast and perfect response!
Leo

Thank you so much for this fast and perfect response.

Asked By LeoDemarc
22-Aug-07 10:16 AM
Thank you so much for this fast and perfect response. For those who care, the
following is the resulting code:

I created a batch file called backup.bat (I firtst delete the existing
backup file, then make a call for the sql command);
c:
cd\backup
del samincbu.bak
sqlcmd -i c:\backup\backup.sql

Then I created the T-SQL commands in the file backup.sql, as indicated in
the batch file;
EXEC sp_addumpdevice 'disk', 'samincbu',
'c:\Backup\samincbu.bak'
BACKUP database saminc TO samincbu
GO

This performs the backup of the database saminc.
I then schedule the batch file with the windows scheduler.

Thanks Again!
Leo
Post Question To EggHeadCafe