HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Full backup on database creation

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
databasefullcreationbackup

Problem

When new databases are created the Differential and transaction log backup maintenance plans start failing and sending alerts as full backup is not taken. What could be the best solution to handle it.

I tried to do full backup on database created trigger but that is failing as backup cannot be taken in the same transaction.

Solution

To achieve this task kindly follow below steps:-

  • create server level trigger on create_database.



  • Create sql job and add code to dynamic get the name of database and initiate backup.



  • Add Code in the trigger to invoke job to create database backup.



e.g

CREATE TRIGGER ddl_trig_database   
ON ALL SERVER   
FOR CREATE_DATABASE   
AS   
   EXEC msdb.dbo.sp_start_job N'backup_job' ;  
GO

Code Snippets

CREATE TRIGGER ddl_trig_database   
ON ALL SERVER   
FOR CREATE_DATABASE   
AS   
   EXEC msdb.dbo.sp_start_job N'backup_job' ;  
GO

Context

StackExchange Database Administrators Q#239077, answer score: 9

Revisions (0)

No revisions yet.