Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Deny Backup


Deny Backup

Author
Message
RedDoorSQL
RedDoorSQL
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 221
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.
anthony.green
anthony.green
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6091 Visits: 6069
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.



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


RedDoorSQL
RedDoorSQL
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 221
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.
anthony.green
anthony.green
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6091 Visits: 6069
Well deny backup wont work then if the account is sysadmin, as if your a sysadmin even explicit denies do not take precidence.



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


vikingDBA
vikingDBA
SSC-Enthusiastic
SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)SSC-Enthusiastic (198 reputation)

Group: General Forum Members
Points: 198 Visits: 929
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
anthony.green
anthony.green
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6091 Visits: 6069
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/



Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
When a question, really isn't a question - Jeff Smith
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search