Technical Article

BackUp database

,

EXECUTE [dbo].[sp_BackupDatabase] 'master', 'F'

CREATE PROCEDURE
[dbo].[sp_BackupDatabase]  

       @databaseName sysname, @backupType 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),':','')  

 

       IF @backupType = 'F' 

               SET @sqlCommand = 'BACKUP DATABASE ' + @databaseName + 

               ' TO DISK = ''C:\Backup\'
+ @databaseName +
'_Full_' +
@dateTime + '.BAK'''


        

       IF @backupType = 'D' 

               SET @sqlCommand = 'BACKUP DATABASE ' + @databaseName + 

               ' TO DISK = ''C:\Backup\'
+ @databaseName +
'_Diff_' +
@dateTime + '.BAK''
WITH DIFFERENTIAL' 

        

       IF @backupType = 'L' 

               SET @sqlCommand = 'BACKUP LOG ' + @databaseName + 

               ' TO DISK = ''C:\Backup\'
+ @databaseName +
'_Log_' +
@dateTime + '.TRN'''


        

       EXECUTE sp_executesql @sqlCommand 

END

Rate

3.67 (3)

You rated this post out of 5. Change rating

Share

Share

Rate

3.67 (3)

You rated this post out of 5. Change rating