Deny Backup

  • Is there a way to deny a login from backing up any database on a sql instance, or will I need to deny backup on all database users.

  • First off why do your users have access to backup the database? I would strongly recommend reviewing your permissions and working from the ground up on least amount of permissions to do the users job using roles for ease of ongoing support.

    But you can deny backup database on a particular database to a particular user or role by running DENY BACKUP DATABASE TO <login>|<rolename>

    But remember if they have sysadmin rights you cant stop them from doing anything.

  • Thanks, thats what I thought, I'm in the process of reviewing the security on a sql instance which I've inherited, but currently one login has sysadmin rights and has been getting used to take adhoc backups of a database without using the COPY_ONLY command therefore its knocking out the backup chain for diff backups etc.

    I don't want to remove the sysadmin right straight away before I can determine who or what is using this login.

  • Well deny backup wont work then if the account is sysadmin, as if your a sysadmin even explicit denies do not take precidence.

  • Unfortunately, I have a food court server with several databases for almost as many applications. Some vendors have access to their databases. Also unfortunately, some have db_owner rights because they refuse to do actual permissions on their database. db_owner rights allows them to do a backup of that database.

    I use the following every night, say after 11pm, to check that day's backups and make sure no one other than those authorized made any backups. Just create a job and run the t-sql script.

    The 'D' in the script is for checking only the full backups. It assumes that you have DB Mail set up on the instance.

    /* ===================================================================================================================== */

    /* This code checks for unauthorized backups and sends an email if any are found for the current day.

    (Should be run late in the day, say after 11pm.)

    If change the criteria, remember to change it in both the IF EXISTS section, and below in the email SELECT statement section.

    */

    if exists

    (SELECT S.database_name, S.recovery_model, S.user_name, S.backup_start_date, CONVERT(decimal(10,2),S.backup_size/1024.0/1024.0/1024.0) AS backup_size_GB,

    M.physical_device_name

    FROM msdb..backupset S

    JOIN msdb..backupmediafamily M ON M.media_set_id=S.media_set_id

    WHERE S.type = 'D'

    AND CONVERT(int,CONVERT(varchar(20),S.backup_start_date,112)) = CONVERT(int,CONVERT(varchar(20),GETDATE(),112))

    and S.user_name NOT LIKE '%<serviceAccount>%')

    BEGIN

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'SQL Server Agent Mail Profile',

    @recipients = 'someone@mycompany.com',--Use semicolon to separate multiple email addresses

    @query = 'SELECT CONVERT(varchar(25),@@SERVERNAME) AS ServerName,

    CONVERT(varchar(25),S.database_name) AS DatabaseName,

    CONVERT(varchar(10),S.recovery_model) AS RecoveryModel,

    CONVERT(varchar(30),S.user_name) AS UserName,

    CONVERT(varchar(30),S.backup_start_date,109) AS BackupStartDate,

    CONVERT(varchar(10),CONVERT(decimal(10,2),S.backup_size/1024.0/1024.0/1024.0)) AS backup_size_GB,

    CONVERT(varchar(100),M.physical_device_name) AS PhysicalDevicename

    FROM msdb..backupset S

    JOIN msdb..backupmediafamily M ON M.media_set_id=S.media_set_id

    WHERE S.type = ''D''

    AND CONVERT(int,CONVERT(varchar(20),S.backup_start_date,112)) = CONVERT(int,CONVERT(varchar(20),GETDATE(),112))

    and S.user_name NOT LIKE ''%<serviceAccount>%''

    ORDER by backup_start_date DESC' ,

    @subject = '<servername> - Unauthorized Backups',

    @attach_query_result_as_file = 1 ;

    END

  • vikingDBA (11/21/2012)


    Unfortunately, I have a food court server with several databases for almost as many applications. Some vendors have access to their databases. Also unfortunately, some have db_owner rights because they refuse to do actual permissions on their database. db_owner rights allows them to do a backup of that database.

    I use the following every night, say after 11pm, to check that day's backups and make sure no one other than those authorized made any backups. Just create a job and run the t-sql script.

    The 'D' in the script is for checking only the full backups. It assumes that you have DB Mail set up on the instance.

    /* ===================================================================================================================== */

    /* This code checks for unauthorized backups and sends an email if any are found for the current day.

    (Should be run late in the day, say after 11pm.)

    If change the criteria, remember to change it in both the IF EXISTS section, and below in the email SELECT statement section.

    */

    if exists

    (SELECT S.database_name, S.recovery_model, S.user_name, S.backup_start_date, CONVERT(decimal(10,2),S.backup_size/1024.0/1024.0/1024.0) AS backup_size_GB,

    M.physical_device_name

    FROM msdb..backupset S

    JOIN msdb..backupmediafamily M ON M.media_set_id=S.media_set_id

    WHERE S.type = 'D'

    AND CONVERT(int,CONVERT(varchar(20),S.backup_start_date,112)) = CONVERT(int,CONVERT(varchar(20),GETDATE(),112))

    and S.user_name NOT LIKE '%<serviceAccount>%')

    BEGIN

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'SQL Server Agent Mail Profile',

    @recipients = 'someone@mycompany.com',--Use semicolon to separate multiple email addresses

    @query = 'SELECT CONVERT(varchar(25),@@SERVERNAME) AS ServerName,

    CONVERT(varchar(25),S.database_name) AS DatabaseName,

    CONVERT(varchar(10),S.recovery_model) AS RecoveryModel,

    CONVERT(varchar(30),S.user_name) AS UserName,

    CONVERT(varchar(30),S.backup_start_date,109) AS BackupStartDate,

    CONVERT(varchar(10),CONVERT(decimal(10,2),S.backup_size/1024.0/1024.0/1024.0)) AS backup_size_GB,

    CONVERT(varchar(100),M.physical_device_name) AS PhysicalDevicename

    FROM msdb..backupset S

    JOIN msdb..backupmediafamily M ON M.media_set_id=S.media_set_id

    WHERE S.type = ''D''

    AND CONVERT(int,CONVERT(varchar(20),S.backup_start_date,112)) = CONVERT(int,CONVERT(varchar(20),GETDATE(),112))

    and S.user_name NOT LIKE ''%<serviceAccount>%''

    ORDER by backup_start_date DESC' ,

    @subject = '<servername> - Unauthorized Backups',

    @attach_query_result_as_file = 1 ;

    END

    Nice script, also like your use of DBA slang. Have a running joke with myself and a former employer as to who is Keyser Soze

    http://www.brentozar.com/archive/2012/10/learn-speak-dba-slang-terms/

Viewing 6 posts - 1 through 5 (of 5 total)

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