I'm trying to setup automated backups for my SQL Server Express 2019. I'm using the script from https://github.com/olahallengren/sql-server-maintenance-solution
Here's the command I run from an elevated command prompt.
sqlcmd -E -S .\SQLEXPRESS -d master -Q
"USE master;
grant execute on dbo.master.DatabaseBackup to [TODDCOM\itadmin];
EXECUTE dbo.DatabaseBackup @Databases = 'USER_DATABASES', @Directory = 'c:\sql2019\backup', @BackupType = 'FULL', @Verify = 'Y', @CheckSum ='Y'" -b -o C:\SQL2019\Backup\DatabaseBackup.txt
robocopy c:\sql2019\backup \\NAS\backup\SQL\ /E /MIR /LOG:"\\NAS\Backup\robocopy-log.txt" /np
DatabaseBackup.txt reports this error:
Changed database context to 'master'. Msg 15151, Level 16, State 1, Server SPURR\SQLEXPRESS, Line 1 Cannot find the object 'DatabaseBackup', because it does not exist or you do not have permission. Msg 229, Level 14, State 5, Server SPURR\SQLEXPRESS, Procedure dbo.DatabaseBackup, Line 1 The EXECUTE permission was denied on the object 'DatabaseBackup', database 'master', schema 'dbo'.
I've used select suser_sname()
to confirm that the account being used is the same as the one i gave permissions to. So far I've applied execute permissions to it in the following places:
- the
dbo
schema in the master database. - the
Security\Users
folder has the 'domain\admin' account and it has the execute permissions applied on it as well. - right clicked on the master db (in SSMS) and applied execute privileges to the 'domain\admin' account in there.
- right clicked on every user database in the system and added execute permissions to the 'domain\admin' account on all of them.
I'm assuming that I only need it in one place but I can't figure out which place to put the permissions. Can anyone help me figure out what I'm doing wrong?
UPDATE: I updated the commands and error report to show what we've tried from the comments.
UPDATE: Adding more info. I ran this code from the task scheduled batch file:
sqlcmd -E -S .\SQLEXPRESS -d master -Q "SELECT SUSER_NAME(); select name, USER_NAME(s.principal_id) AS Schema_Owner from sys.schemas s;" -o C:\SQL2019\Backup\User.txt
and it output:
domain\admin
(1 rows affected)
name Schema_Owner
-------------------- ----------------
dbo dbo
guest guest
INFORMATION_SCHEMA INFORMATION_SCHEMA
sys sys
db_owner domain\admin
db_accessadmin db_accessadmin
db_securityadmin db_securityadmin
db_ddladmin db_ddladmin
db_backupoperator domain\admin
db_datareader db_datareader
db_datawriter db_datawriter
db_denydatareader db_denydatareader
db_denydatawriter db_denydatawriter
(13 rows affected)```