Search code examples
sql-serveremailbackupprofilejobs

Backup sql server database and mail it


I have looked and searched to find a way to backup sql server db and send the backup file to email address with sql server mail profile but i did not get it, I found about sending email when there is a failure in db, and other notification but i did not see about backup and sending it to email automatically, is there any way to create a job to do that ? Thanks.


Solution

  • If you double click that SQL Agent job, go to the Steps section add another step there and execute the following procedure there.. Also make sure the following step is executed after the database backup step.

    Exec sp_send_dbmail   
            @profile_name =  'profile_name' 
         ,  @recipients =  '[email protected]' 
         ,  @subject =  'Database Backups bla bla'  
         ,  @body =  'body'  
         ,  @file_attachments =  'B:\Backups\DB_Back.bak' 
    

    This will send an email out to the person with the backup file as an attachment. Also by default sql server has a limit on how big file you can send you can change them settings to send a bigger file.

    Consult your data protection team before you do this, I dont think any company would allow this to happen :) just a heads up