Written By: Thomas LaRock -- 5/8/2009
Problem
Many shops do full backups of their databases as part of a job within SQL Agent, typically as part of a maintenance plan. This job will often times do all database backups in secession. As such, while you may know how long the job takes, you may not know how long any one particular database takes to have a full backup taken. When deploying changes it is advised to take a full backup of a database prior to deploying the change and a common question faced will be "how long will it take?".
Solution
The information is readily available inside the msdb database, making the solution as easy as a few lines of T-SQL.
The T-SQL provided below allows for you to input the name of a database if desired. I have also added a line that will filter the results, limiting your view to only the databases that are currently listed in the master.dbo.sysdatabases table. If you comment out that line of code you will return information on the last time a database was backed up on the instance, regardless if the database is currently listed in master.dbo.sysdatabases.
Returning the details
Here is the T-SQL
DECLARE @dbname sysname |
The script will return the following result set:
Column Name | Description |
User | The name of the user that issued the BACKUP DATABASE command. |
Database | The name of the database. |
Server | The name of the server instance. |
Backup Started | The time at which the backup was started. |
Backup Finished | The time at which the backup was completed. |
Total Time | The total amount of time it took to complete the backup for that database. |
Images
Here is a screenshot of a sample result set returned by the script.
If you want to get a list of all backups and not just the most recent you can issue the following:
DECLARE @dbname sysname |
Thank you: MS SQL TRIPS
0 ความคิดเห็น:
แสดงความคิดเห็น