How to automate script after every backup/restore in SQL Server 2k ?

  • Hi,

    If I have some scripts that I need to run after every backup or restore,

    is there any automation trigger that I can configure it at SQL enterprise Manager

    or sql analyzer by script without having to do it manually ?

  • there's no event you can use, but you can check to see if soemthing has been backedup since a certain date, and do your special process from there (i assume it is a zip or file move function?)

    the script below might help you; this is just checking for x number of days since last backup, but you can see there is a backup date in there if you need to modify it.

    You could create a scheduled job that checks if anything has been backed up since the last time the job was run, and do your special processing based on that.

    sample results: note that one db has never been backed up.

    Number_of_Days_since_last_backupBackup_type_(D-database,L-log)backup_sizedatabase_name
    0NULLNULLDFAFM
    5D84363776DFAHDS_TEST
    45D23330304HAHDSDATA
    150D140955136DB_AUG17

    select max(isnull(datediff(dd,b.backup_start_date,getdate()),0))

    as 'Number of Days since last backup',

    b.type as  'Backup type (D-database,L-log)', b.backup_size, d.name

    as database_name

    from  master..sysdatabases d with (nolock)

    left join msdb..backupset b  with (nolock)

    on d.name = b.database_name

    and b.backup_start_date = (select max(backup_start_date)

                                       from msdb..backupset b2

                                       where b.database_name = b2.database_name

                                      and b2.type = 'D')

    where d.name != 'tempdb'

    group by d.name, b.type, b.backup_size

    union all

    select max(isnull(datediff(dd,b.backup_start_date,getdate()),0))

    as 'Number of Days since last backup',

    b.type as  'Backup type (D-database,L-log)', b.backup_size, d.name

    as database_name

    from  master..sysdatabases d with (nolock)

    join msdb..backupset b  with (nolock)

    on d.name = b.database_name

    and b.backup_start_date = (select max(backup_start_date)

                                       from msdb..backupset b2

                                       where b.database_name = b2.database_name

                                       and b2.type = 'L')

    group by d.name, b.type, b.backup_size

    order by d.name,b.type   -- optional

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply