Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Backup Database

Status
Not open for further replies.

scabral79

MIS
May 16, 2007
25
US
Is there a way to use the Backup Database command to backup a database to disk from a stored proc?

for example, if you try to run the following command from a stored proc:

Backup database ABLTEST to disk='e:\mssql\mssql\backup\Daily\ABLTest.bak'

I get the following error:

Incorrect syntax near 'Backup'.

Basically, what i need to do is figure out a way to backup the database either by using stored proc or dts package, but NOT using the sql scheduler.

thanks
scott
 
yes you can.
I used a backup device.

I just created this quick test and it worked.
Code:
create proc backupdb
as
begin
BACKUP DATABASE DBASaveObjects to [backup]
end

Create a backup device and try it again.


- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
I also tested this, but with the To Disk syntax, and it worked for me.

Can you post the entire contents of your SP so we can have a better look?

-George

"the screen with the little boxes in the window." - Moron
 
here is my syntax. I created a backup device call Backup:

CREATE PROCEDURE [dbo].[clo_daily_backup] AS

begin
BACKUP DATABASE ABLTEST to Backup
end

I am still getting the following:
Server: Msg 156, Level 15, State 1, Procedure clo_daily_backup, Line 5
Incorrect syntax near the keyword 'Backup'.
 
you need [ ] brackets around backup. Did you create the device backup? Use the example that Denis posted?

- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
Code:
BACKUP DATABASE ABLTEST TO DISK='e:\mssql\mssql\backup\Daily\ABLTest.bak'
  WITH DESCRIPTION = 'Manual ABLTEST Backup', RETAINDAYS = 0, NOFORMAT, INIT, NAME = 'ABLTEST', NOSKIP, RESTART
 
Can this stored procedure be created in the database that i am backing up or does it have to be created in master?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top