SQL_SERVER_2005_TSQL_Email _To_Verify_Daily_Backup
EXEC msdb.dbo.sp_send_dbmail
@recipients='billie@myitguide.com;',
@body='This is an automated email please do not reply.',
@subject ='SQL-05 Verify Daily Backup',
@query ='
DECLARE @dbCnt as int;
-- less 1, minus tempdb
SELECT @dbCnt=Count(*)-4 FROM sys.databases;
PRINT ''Daily Backup Verification Email'';
PRINT ''Start Processing '' + CONVERT(VarChar(20), GETDATE(), 109);
PRINT ''-----------------------------'';
PRINT ''Server Name : '' + @@ServerName ;
PRINT ''User Database Count: '' + RTRIM(@dbCnt);
PRINT ''-----------------------------'';
PRINT '''';
SELECT CAST(database_name as char(25)) [database],
cast([name]as char(50)) backupname,
CAST(CAST(backup_size/1024/1000000 as decimal(8,6)) as char(15)) backup_size_gb,
backup_start_date, backup_finish_date,
cast([server_name]as char(25)) server_name,
cast([machine_name]as char(15)) machine_name
FROM msdb.dbo.backupset
WHERE backup_start_date BETWEEN DATEADD(hh, -24, GETDATE()) AND GETDATE()
AND Type = ''D''
AND database_name NOT IN (''model'', ''master'', ''msdb'', ''tempdb'')
ORDER BY [name];
PRINT ''End Processing '' + CONVERT(VarChar(20), GETDATE(), 109);
',
@attach_query_result_as_file = 1,
@query_attachment_filename ='BackupResults.txt'
GO
---------------------------------------------------------------------------------------------------
No comments:
Post a Comment