Thursday, March 22, 2012

check if the database is currently being backed up

How can I check if the database is currently being backed up?

Seems like that should be a property, but it's not an attribute of the DATABASEPROPERTY function.

Thanks

You can check sp_who/spwho2 to find out if any database is being backed up on the server. This involves manual intervention to look at the output of above SP's. Are you trying to retrieve that information interactively and do some other action or what are you trying to achieve?

|||I am trying to have certain logic kick off based on database is being backed. I know I can query the sysprocesses, which is what sp_who2 does, and look for 'BACKUP' string, but I was wondering if there's a better way.|||

I am not sure if its a good idea to have separate logic if the database is being backed up. Anyway, if the backup task is coming from Sql job, you should be able to query the job status.

|||

Check the Log Reuse description when you query sys.databases, and you can tell if a backup is running.

|||

Glenn,

I am not sure if we can use Log Reuse description to find if the database is currently being backed up. I have tried it on 9.00.1399.06 build and while the db is being backed up, log_reuse_wait is 0 and desc says 'NOTHING'. Did I miss something how this can be used?

|||

I figured it now. I had to do BACKUP LOG to see the values. Paul's article on this helped me to understand it better. Thanks to KaliBaba & Glenn, I learned something new today.

|||

Glenn,

I think you're talking about log_reuse_wait_desc in sysdatabases, but that's only talking about log backup,

and sql 2005. I needed to clarify, but I need this for sql 2000 as well. Any suggestions other that sysprocesses?

Thanks

No comments:

Post a Comment