/*==============================================================================
Object:       StoredProcedure 
Name:         dbo.sp_TDSDatabaseBackup
Author:       Fai Yuen
Create Date:  02/02/2009
Usage:        sp_TDSDatabaseBackup <DatabaseName>, <BackupType>, <BackupPath>
                <DatabaseName> : Database name to backup
                <BackType> :     'F' - Full Backup
                                        'D' - Differential Backup
                                        'L' - Log Backup
                <BackupPath> :   File path for backup database to
==============================================================================*/
USE [TDS_OTTO]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[sp_TDSDatabaseBackup] 
	@DatabaseName sysname, @BackupType CHAR(1), @BackupPath VARCHAR(255)
AS
BEGIN
	SET NOCOUNT ON;

    DECLARE @SqlCommand NVARCHAR(1000)

    IF @BackupType = 'F'
       SET @SqlCommand = 'BACKUP DATABASE ' + @DatabaseName +
       ' TO DISK = ''' + @BackupPath + '\' + @DatabaseName + '.bak''' +
       ' WITH NAME = N''' + @DatabaseName + '_FullBackup'', FORMAT'

    IF @BackupType = 'D'
       SET @SqlCommand = 'BACKUP DATABASE ' + @DatabaseName +
       ' TO DISK = ''' + @BackupPath + '\' + @DatabaseName + '_Diff.bak''' +
       ' WITH DIFFERENTIAL, NAME = N''' + @DatabaseName + '_DiffBackup'''

    IF @BackupType = 'L'
       SET @SqlCommand = 'BACKUP LOG ' + @DatabaseName +
       ' TO DISK = ''' + @BackupPath + '\' + @DatabaseName + '_Log.bak''' +
       ' WITH NAME = N''' + @DatabaseName + '_LogBackup'', FORMAT'

    EXECUTE sp_ExecuteSql @SqlCommand  

END
GO
