join the MSSQLTips community

MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

 
Scheduling Backups for SQL Server 2005 Express - MSSQLTips

MSSQLTips

MSSQLTips.com - your daily source for SQL Server tips
Welcome to MSSQLTips Sign in | Join | Help
in Search

Scheduling Backups for SQL Server 2005 Express

Last post 10-08-2009 12:13 PM by admin. 24 replies.
Page 1 of 2 (25 items) 1 2 Next >
Sort Posts: Previous Next
  • 02-07-2007 12:00 AM

    Scheduling Backups for SQL Server 2005 Express

    This post is related to this tip: Scheduling Backups for SQL Server 2005 Express

    http://www.mssqltips.com/tip.asp?tip=1174

  • 06-17-2008 8:32 AM In reply to

    Re: Scheduling Backups for SQL Server 2005 Express

     just wanted to point out that the stored process sp_executesql is not in SQL Server 2005 Express.  I've looked in the sp folder and nothing is there. 

  • 06-17-2008 6:53 PM In reply to

    • grobido
    • Top 10 Contributor
    • Joined on 10-11-2007
    • Wilton, NH
    • Posts 103

    Re: Scheduling Backups for SQL Server 2005 Express

    This is stored under the Extended Stored Procedures -> System Extended Stored Procedures

    Try running this code below to see if this works:

     

    use master
    go

    sp_executesql N'SELECT * FROM sys.databases'

  • 06-21-2008 5:13 PM In reply to

    Re: Scheduling Backups for SQL Server 2005 Express

     Hello,

       I am very thankful to the code which i got it from you on taking the backup. I am a .net Programmer.

    I have an requirement as to take the backup on different paths (as you have gave "c:\Backup") the path will change any no. of time, so i am planning to send a parameter of path, i tried to run the stored proc as this. but this gives a problem.

    USE [master]
    GO
    /****** Object:  StoredProcedure [dbo].[sp_BackupDatabase]    Script Date: 06/22/2008 03:54:47 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO


    -- =============================================
    -- Author: Edgewood Solutions
    -- Create date: 2007-02-07
    -- Description: Backup Database
    -- Parameter1: databaseName
    -- Parameter2: backupType F=full, D=differential, L=log
    -- =============================================
    alter PROCEDURE [dbo].[sp_BackupDatabasess] 
           @databaseName sysname, @backupType CHAR(1),
           @backuppath varchar(200)
    AS
    BEGIN
           SET NOCOUNT ON;

           DECLARE @sqlCommand NVARCHAR(1000)
           DECLARE @dateTime NVARCHAR(20)

           SELECT @dateTime = REPLACE(CONVERT(VARCHAR, GETDATE(),111),'/','') +
           REPLACE(CONVERT(VARCHAR, GETDATE(),108),':','') 

           IF @backupType = 'F'
                   SET @sqlCommand = 'BACKUP DATABASE ' + @databaseName +
                   ' TO DISK = '+@backuppath + @databaseName + '_Full_' + @dateTime + '.BAK'''
           
           IF @backupType = 'D'
                   SET @sqlCommand = 'BACKUP DATABASE ' + @databaseName +
                   ' TO DISK = '+@backuppath + @databaseName + '_Diff_' + @dateTime + '.BAK'' WITH DIFFERENTIAL'
           
           IF @backupType = 'L'
                   SET @sqlCommand = 'BACKUP LOG ' + @databaseName +
                   ' TO DISK = '+@backuppath + @databaseName + '_Log_' + @dateTime + '.TRN'''
           
           EXECUTE sp_executesql @sqlCommand
    END

     

     

    Msg 102, Level 15, State 1, Line 1
    Incorrect syntax near 'c:'.
    Msg 105, Level 15, State 1, Line 1
    Unclosed quotation mark after the character string ''.

     

    I would be very glad, if you can help me. prashanthganathe@gmail.com.

     

    Thanks & Regards,

    prashanthganathe@gmail.com.

     

     

  • 06-23-2008 6:35 AM In reply to

    • grobido
    • Top 10 Contributor
    • Joined on 10-11-2007
    • Wilton, NH
    • Posts 103

    Re: Scheduling Backups for SQL Server 2005 Express

    You need to fix the quoting around the path.

    The line should be like this

           IF @backupType = 'F'
                   SET @sqlCommand = 'BACKUP DATABASE ' + @databaseName +
                   ' TO DISK = '''+@backuppath + @databaseName + '_Full_' + @dateTime + '.BAK'''

     

    You need to  have three single quotes before the @backuppath variable

  • 06-25-2008 6:26 AM In reply to

    • proof
    • Not Ranked
    • Joined on 06-25-2008
    • Posts 1

    Re: Scheduling Backups for SQL Server 2005 Express

    I love this script, but how would Iike to use it to backup another database, that may have users in it at the time.  Is there a way to run this script to an attached database that may be active?

  • 07-02-2008 4:14 PM In reply to

    Re: Scheduling Backups for SQL Server 2005 Express

     This script also needs brackets eg: [ ] around the database name to support names with characters such as hyphens ( - )

  • 08-08-2008 10:24 AM In reply to

    • Kendjr
    • Top 500 Contributor
    • Joined on 08-08-2008
    • Posts 2

    Re: Scheduling Backups for SQL Server 2005 Express

    I am using VIsta, and I am receiving the following error:

    Cannot open backup device 'C:\Users\Ken\Documents\Backup\SQL Goldmine Backups\Princeton3_Full_20080808131951.BAK'. Operating system error 5(Access is denied.).

    Can you tell me where I can open up the access?

    Thanks,

    Ken

  • 08-08-2008 12:51 PM In reply to

    • grobido
    • Top 10 Contributor
    • Joined on 10-11-2007
    • Wilton, NH
    • Posts 103

    Re: Scheduling Backups for SQL Server 2005 Express

    This is a permissions problem.  The SQL Server service account probably does not have rights to the folder where you are trying to create the backup files. 

    By default the NetworkService account is probalby being used for SQL Express which has limited rights.

    You can either grant rights to this account to create files in this folder or you can use a different account for the SQL Server service or write to a folder where this account has permissions to create files.

  • 08-08-2008 1:06 PM In reply to

    • Kendjr
    • Top 500 Contributor
    • Joined on 08-08-2008
    • Posts 2

    Re: Scheduling Backups for SQL Server 2005 Express

    Thanks,

     I am not familiar with any of these, what would you recommend doing, and how can I do that?

     Thank you very much for your help.

     Ken

  • 09-25-2008 6:36 AM In reply to

    Re: Scheduling Backups for SQL Server 2005 Express

    Thanks

    Great Script

    Worked first time

    Best I have ever found

  • 10-20-2008 8:01 AM In reply to

    Re: Scheduling Backups for SQL Server 2005 Express

    you'll probably want to see this page, http://devzone.advantagedatabase.com/dz/webhelp/Advantage9.0/server1/sp_restoredatabase.htm

    which talks about using sp_RestoreDatabase to use the data.

  • 10-20-2008 8:02 AM In reply to

    Re: Scheduling Backups for SQL Server 2005 Express

    sorry *this* is the page that talks about having to use it:

     

    http://devzone.advantagedatabase.com/dz/webhelp/Advantage9.0/server1/sp_backupdatabase.htm

  • 10-20-2008 10:07 AM In reply to

    • grobido
    • Top 10 Contributor
    • Joined on 10-11-2007
    • Wilton, NH
    • Posts 103

    Re: Scheduling Backups for SQL Server 2005 Express

    Kendjr, if you look in Configuration Manager you will probably see that the SQL Server service is using the Network Service account.  This account probably has limited access to the folder you are trying to back up to.

    You can either change the account in Configuration Manager to use the LocalSystem account

    or

    you can give write permissions to the Network Service account to the folder where you want to create the backup

    or

    you can try to save the backup to the default folder which is probably something like this:C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup

  • 03-02-2009 8:38 AM In reply to

    • rsteph
    • Not Ranked
    • Joined on 03-02-2009
    • Posts 1

    Re: Scheduling Backups for SQL Server 2005 Express

    I found this tip, and have tried to set it up. I actually got the SQL part all set up, and if I simple run the command in the backup.sql file (to call the stored procedure), it makes the backup without problem.

     However, for some reason when I go to place it on in the Scheduled Task list, it doesn't seem to work. Here's the command line I'm using:

    "sqlcmd -S dbServer-1 -E -i C:\backup script\Backup.sql"

     Do I need to add the SQL Server name to the Server (i.e. dbServer-1\SQLExpress)? Or does anyone have any other ideas why the schedule might not be working? Like I said, I've tested the stored procedure, so I know that part works; so it has to be in the scheduling part...

     Any help would be greatly appreciated. Thank you.

Page 1 of 2 (25 items) 1 2 Next >