Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Deny Backup Expand / Collapse
Author
Message
Posted Tuesday, November 20, 2012 2:15 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, September 4, 2014 1:20 AM
Points: 70, Visits: 190
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.
Post #1386744
Posted Tuesday, November 20, 2012 2:19 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:10 AM
Points: 5,216, Visits: 5,108
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
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

Post #1386748
Posted Tuesday, November 20, 2012 7:06 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, September 4, 2014 1:20 AM
Points: 70, Visits: 190
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.





Post #1386893
Posted Tuesday, November 20, 2012 7:08 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:10 AM
Points: 5,216, Visits: 5,108
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
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

Post #1386895
Posted Wednesday, November 21, 2012 6:57 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 5:35 PM
Points: 191, Visits: 898
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
Post #1387407
Posted Wednesday, November 21, 2012 8:21 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 2:10 AM
Points: 5,216, Visits: 5,108
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
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

Post #1387446
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse