August 14, 2019 at 12:47 pm
i am able to run backups for all sytem dbs using a script from SSMS but the same script is backing up only master from the sql agent job but not msdb or model, what am i missing?
August 14, 2019 at 1:34 pm
Can you publish the script?
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
August 14, 2019 at 1:50 pm
Do you receive any error messages?
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
August 14, 2019 at 1:51 pm
declare @dbname as varchar(80)
declare @msgdb as varchar(80)
declare @dbbkpname as varchar(80)
declare @datepart as char(1)
declare rs_cursor CURSOR for select name from master.sys.databases
where state_desc = 'ONLINE' and name <> 'tempdb' order by name
set @datepart = datepart(dw,getdate()) -1
open rs_cursor
Fetch next from rs_cursor into @dbname
WHILE @@FETCH_STATUS = 0 and @datepart IN (1,2,3,4)
BEGIN
select @msgdb= 'database backup in progress: ' + @dbname
PRINT @msgdb
if @datepart = 5 or @dbname = 'master' -- Make full backups on Sunday
BEGIN
select @dbbkpname='\\PVPStorage\STRev_PD\full\' + @dbname + '7.bak'
exec master.dbo.xp_backup_database
@database = @dbname,
@filename = @dbbkpname,
@compressionlevel = 2,
@init = 1,
@threads = 3
END
else
if (select count(*) from msdb.dbo.backupset where database_name = @dbname and type = 'D') > 0
BEGIN
select @dbbkpname='\\PVPStorage\STRev_PD\' + @dbname + @datepart + '.bak'
exec master.dbo.xp_backup_database
@database = @dbname,
@filename = @dbbkpname,
@compressionlevel = 2,
@init = 1,
@threads = 3
, @with = 'DIFFERENTIAL'
END
else
BEGIN
select @dbbkpname='\\PVPStorage\STRev_PD\full\' + @dbname + '7.bak'
exec master.dbo.xp_backup_database
@database = @dbname,
@filename = @dbbkpname,
@compressionlevel = 2,
@init = 1,
@threads = 3
END
FETCH NEXT FROM rs_cursor INTO @dbname
END
CLOSE rs_cursor
deallocate rs_cursor
GO
August 14, 2019 at 1:53 pm
i dont think there is any issue with the script as it works fine from SSMS but it does not work from SQL Agent job though it backups only master and skips the rest of databases with no errors.
August 14, 2019 at 7:11 pm
i dont think there is any issue with the script as it works fine from SSMS but it does not work from SQL Agent job though it backups only master and skips the rest of databases with no errors.
It IS possible that the SQL Agent Service has a different level of privs than you do. Check on the privs (especially at the OS level) that the SQL Agent Service actually has.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 15, 2019 at 7:34 pm
all sql server services are running under same account, its weird that only master database backups 🙁
August 15, 2019 at 7:37 pm
all sql server services are running under same account, its weird that only master database backups 🙁
Ok, but does this account have permissions to do this?
Here are a couple things.
Add an output file to the steps of the job. Add some more print statements to the code. See what is captured in the output file.
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply