Skip to content

No Column Name

My learnings and thoughts on SQL Server and PowerShell

  • About Me:
    • Twitter:
    • DBA.stackexchange
  • Community Scripts
  • T-SQL Tuesday
  • SQL Server
  • PowerShell
  • Twitter

Tag: create

Does dbcreator Grant Backup Privileges?

Does dbcreator Grant Backup Privileges?

Words: 581

Time to read: ~ 3 minutes

TL;DR: No.

This is a straight #SQLNewBlogger post.

I was working on privileges and permissions for some server roles in the database on a new server the other day.

From talking with the Developers, they wanted the ability to be able to backup and restore databases.

Reading the documentation

I knew from reading the documentation that dbcreator grants permissions to create, alter, drop, and restore databases. My question was does it give permission to backup databases?

It seems to give everything else so is backup databases just missing there? Or is it intentionally left out?

A few tries with different search engine didn’t reveal much for me. Luckily, this is something that we can easily test! Perfect for a #SQLNewBlogger post.

If you have a situation like this one; figure it out and write it up!

Set Up

I’m going to assume that you have a development instance of SQL Server to test things out on.

If not, Grant Fritchey ( blog | twitter ) is currently doing a great series on getting started with Docker.

And thank you Andy Mallon ( blog | twitter ) for the Data Blogger Resource that lets me copy and paste the information over!

On your test instance, we’re going to create a SQL Authentication Login that shall be our test subject.

We are testing dbcreator so we’re going to add it to that role after we create it. We’ll also need a database that we can test this on.

USE [master];
GO

CREATE LOGIN [RestoreNoBackup] WITH PASSWORD = 'WhyOneAndNotOther?';
GO

ALTER SERVER ROLE dbcreator ADD MEMBER RestoreNoBackup;
GO

IF DB_ID(N'TestBackup') IS NOT NULL BEGIN
    ALTER DATABASE TestBackup SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    DROP DATABASE TestBackup;
END;
GO

CREATE DATABASE TestBackup;
ALTER DATABASE TestBackup SET RECOVERY SIMPLE;
GO

USE TestBackup;
GO

CREATE TABLE dbo.TestData (
    TestDataId int IDENTITY(1, 1) NOT NULL
        CONSTRAINT pk_TestData PRIMARY KEY,
    TestDate date NOT NULL
        CONSTRAINT df_TestDate_getdate DEFAULT (GETDATE()),
    TestValue varchar(25) NOT NULL
);
GO

CREATE USER RestoreNoBackup FROM LOGIN RestoreNoBackup;
GO
GRANT SELECT ON dbo.TestData TO RestoreNoBackup;
GO

INSERT INTO dbo.TestData (TestValue)
VALUES
    ('This is important!'),
    ('So is this.');
GO

SELECT * FROM dbo.TestData;
GO
Very Important Data

So now we have:

  • A database: TestBackup
  • A SQL Login: RestoreNoBackup
    • Assigned to dbcreator
  • A User on the database linked to the login: RestoreNoBackup
    • Granted SELECT on the table.

Are we missing something? Let’s take a backup as well.

BACKUP DATABASE TestBackup
TO DISK = N'E:\BACKUP\TestBackup_20190530_01.bak'
WITH
    COMPRESSION,
    CHECKSUM;
GO
Backed up

Now, let’s do our actual test.

Quick Test.

We’re going to connect to the instance as our login; RestoreNoBackup.

Now, let’s test that we can create a database…

CREATE DATABASE Empty01;
GO

SELECT
    DbOwner = SUSER_SNAME(owner_sid),
    DbName  = [name]
FROM sys.databases;
GO
He creates!

Lovely, can we restore the backup that we took?…

RESTORE DATABASE RestoreTest01
FROM DISK = N'E:\BACKUP\TestBackup_20190530_01.bak'
WITH
    MOVE N'TestBackup' TO N'/var/opt/mssql/data/RestoreTest01.mdf',
    MOVE N'TestBackup_log' TO N'/var/opt/mssql/data/RestoreTest01_log.ldf',
    CHECKSUM,
    STATS = 10;

SELECT * FROM [RestoreTest01].dbo.TestData;

SELECT
    DbOwner = SUSER_SNAME(owner_sid),
    DbName  = [name]
FROM sys.databases;
GO
He restores!

Great! But can we backup the database that we created?…

SELECT SUSER_SNAME();
BACKUP DATABASE RestoreTest01
TO DISK = N'E:\BACKUP\RestoreTest01_20190530_01.bak'
WITH
    COMPRESSION,
    CHECKSUM;
GO
But most importantly, he does NOT backup!

Okay! So if backup permissions are needed, I need to add the user to the db_backupoperator database role.

Good to know!

#SQLNewBlogger

Great!

I now have confirmation that dbcreator can create and restore (I’m wasn’t testing alter or drop) databases.

This is a lovely case of #SQLNewBlogger, it took me 15 minutes for this blog post and most of that was taking the screenshots and cleaning the code.

Author Shane O'NeillPosted on May 30, 2019May 31, 2019Categories GeneralTags backup, container, create, login, restore, sql-server1 Comment on Does dbcreator Grant Backup Privileges?

Recent Posts

  • Ordering and Choices in PowerShell
  • How SQL Server’s Compute Scalar Will Impede You
  • Getting SQL Server Version using dbatools
  • T-SQL Tuesday 183 – Tracking Permissions
  • T-SQL Tuesday #182 – Integrity

Recent Comments

Ordering Collections… on Ordering and Choices in PowerS…
webdesigner on Updating the Account Password…
Anonymous on When Stored Procedures say the…
Performing a Quick F… on How SQL Server’s Compute…
Get the SQL Server V… on Getting SQL Server Version usi…

Archives

  • July 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • February 2024
  • October 2023
  • July 2023
  • April 2023
  • December 2022
  • October 2022
  • August 2022
  • July 2022
  • May 2022
  • April 2022
  • January 2022
  • November 2021
  • October 2021
  • July 2021
  • June 2021
  • May 2021
  • February 2021
  • January 2021
  • November 2020
  • October 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016

Categories

  • Advent of Code
  • DBA Fundamentals
  • dbachecks
  • dbatools
  • General
  • Golang
  • maintenance plan
  • Pester
  • Powershell
  • SQL Family
  • SQL New Blogger
  • sql-server
  • STATISTICS IO
  • T-SQL Tuesday
  • Uncategorized

Recent Posts

  • Ordering and Choices in PowerShell
  • How SQL Server’s Compute Scalar Will Impede You
  • Getting SQL Server Version using dbatools
  • T-SQL Tuesday 183 – Tracking Permissions
  • T-SQL Tuesday #182 – Integrity
  • About Me:
    • Twitter:
    • DBA.stackexchange
  • Community Scripts
  • T-SQL Tuesday
  • SQL Server
  • PowerShell
  • Twitter
No Column Name Powered by WordPress.com.
 

Loading Comments...