Search code examples
sql-server-2008sql-server-2008-express

SQL Server 2008 Express Automatic Backup Methods?


i would like to ask you about the available automatic backup methods for SQL Server 2008 Express Editition. I tried Replication method on other server, but it is not available with Express Edition. Please help, i searched a lot for solutions but nothing found. Thanks Alot


Solution

  • Finally i found a solution.. very easy and practical one.

    Create the following File : "SQL_StoredProcedure.sql"

    USE MyDBName
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    
    -- ============================================= 
    create PROCEDURE [dbo].[mysp_BackupDb]  
           @dbName sysname, @backupTypeToRun CHAR(1) 
    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),':','')  
    
           DECLARE @databaseFileName NVARCHAR(200)
           SET @databaseFileName = replace(@dbName,']','')
           SET @databaseFileName = replace(@databaseFileName,'[','')
    
           IF @backupTypeToRun = 'F' 
                   SET @sqlCommand = 'BACKUP DATABASE ' + @dbName + 
                   ' TO DISK = ''D:\DBBackup\DBs\' + @databaseFileName + '_Full_' + @dateTime + '.BAK''' 
    
           IF @backupTypeToRun = 'D' 
                   SET @sqlCommand = 'BACKUP DATABASE ' + @dbName + 
                   ' TO DISK = ''D:\DBBackup\DBs\' + @databaseFileName + '_Diff_' + @dateTime + '.BAK'' WITH DIFFERENTIAL' 
    
           IF @backupTypeToRun = 'L' 
                   SET @sqlCommand = 'BACKUP LOG ' + @dbName + 
                   ' TO DISK = ''D:\DBBackup\DBs\' + @databaseFileName + '_Log_' + @dateTime + '.TRN''' 
    
           EXECUTE sp_executesql @sqlCommand 
    END 
    

    Create the Following File: "BackupScript.sql"

    Use master
    Exec mysp_BackupDbMaster 'MyDBName', 'F';
    Go
    

    Now you have everything. Just create a task in Windows Task Scheduler In the Task itself -> Actions -> Start Program -> Edit, use following inputs:

    Program/script: C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE Add arguemtns: -S MyServer\MySQlInstant -E -i D:\DBBackup\BackupScript.sql