Answers:
是。如果已将sp_who2k5安装到主数据库中,则可以简单地运行:
sp_who2k5 1,1
结果集将包括所有活动交易。当前运行的备份将在requestCommand字段中包含字符串“ BACKUP” 。正确命名的percentComplete字段将为您提供备份进度。
注意:sp_who2k5应该成为每个人工具包的一部分,它不仅要做很多。
我在这里发现此示例脚本似乎运行良好:
SELECT r.session_id,r.command,CONVERT(NUMERIC(6,2),r.percent_complete)
AS [Percent Complete],CONVERT(VARCHAR(20),DATEADD(ms,r.estimated_completion_time,GetDate()),20) AS [ETA Completion Time],
CONVERT(NUMERIC(10,2),r.total_elapsed_time/1000.0/60.0) AS [Elapsed Min],
CONVERT(NUMERIC(10,2),r.estimated_completion_time/1000.0/60.0) AS [ETA Min],
CONVERT(NUMERIC(10,2),r.estimated_completion_time/1000.0/60.0/60.0) AS [ETA Hours],
CONVERT(VARCHAR(1000),(SELECT SUBSTRING(text,r.statement_start_offset/2,
CASE WHEN r.statement_end_offset = -1 THEN 1000 ELSE (r.statement_end_offset-r.statement_start_offset)/2 END)
FROM sys.dm_exec_sql_text(sql_handle))) AS [SQL]
FROM sys.dm_exec_requests r WHERE command IN ('RESTORE DATABASE','BACKUP DATABASE')
如果您知道sessionID,则可以使用以下内容:
SELECT * FROM sys.dm_exec_requests WHERE session_id = 62
或者,如果您想缩小范围:
SELECT command, percent_complete, start_time FROM sys.dm_exec_requests WHERE session_id = 62
这是一个简单的脚本,通常可以帮我解决问题:
SELECT command, percent_complete,total_elapsed_time, estimated_completion_time, start_time
FROM sys.dm_exec_requests
WHERE command IN ('RESTORE DATABASE','BACKUP DATABASE')
很多时候,您的备份(或还原)活动已经由另一个数据库管理员或某个作业启动,并且您无法使用GUI来检查该备份/还原的进度。
通过组合多个命令,我生成了以下脚本,该脚本可以为我们提供服务器上正在发生的当前备份和还原的摘要。
select
r.session_id,
r.blocking_session_id,
db_name(database_id) as [DatabaseName],
r.command,
[SQL_QUERY_TEXT] = Substring(Query.TEXT, (r.statement_start_offset / 2) + 1, (
(
CASE r.statement_end_offset
WHEN - 1
THEN Datalength(Query.TEXT)
ELSE r.statement_end_offset
END - r.statement_start_offset
) / 2
) + 1),
[SP_Name] =Coalesce(Quotename(Db_name(Query.dbid)) + N'.' + Quotename(Object_schema_name(Query.objectid, Query.dbid)) + N'.' +
Quotename(Object_name(Query.objectid, Query.dbid)), ''),
r.percent_complete,
start_time,
CONVERT(VARCHAR(20), DATEADD(ms, [estimated_completion_time],
GETDATE()), 20) AS [ETA_COMPLETION_TIME],
CONVERT(NUMERIC(6, 2), r.[total_elapsed_time] / 1000.0 / 60.0) AS [Elapsed_MIN],
CONVERT(NUMERIC(6, 2), r.[estimated_completion_time] / 1000.0 / 60.0) AS [Remaning_ETA_MIN],
CONVERT(NUMERIC(6, 2), r.[estimated_completion_time] / 1000.0 / 60.0/ 60.0) AS [ETA_Hours],
wait_type,
wait_time/1000 as Wait_Time_Sec,
wait_resource
from sys.dm_exec_requests r
cross apply sys.fn_get_sql(r.sql_handle) as Query where r.session_id>50 and command IN ('RESTORE DATABASE','BACKUP DATABASE', 'RESTORE LOG', 'BACKUP LOG')
SELECT session_id as SPID, command, a.text AS Query, start_time, percent_complete, dateadd(second,estimated_completion_time/1000, getdate()) as estimated_completion_time
FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) a
WHERE r.command in ('BACKUP DATABASE','RESTORE DATABASE')
尝试wih:
SELECT * FROM sys.dm_exec_requests where command like '%BACKUP%'
SELECT command, percent_complete, start_time FROM sys.dm_exec_requests where command like '%BACKUP%'
SELECT command, percent_complete,total_elapsed_time, estimated_completion_time, start_time
FROM sys.dm_exec_requests
WHERE command IN ('RESTORE DATABASE','BACKUP DATABASE')
使用STATS选项:http : //msdn.microsoft.com/en-us/library/ms186865.aspx
我认为找出还原或备份进度的最佳方法是通过以下查询:
USE[master]
GO
SELECT session_id AS SPID, command, a.text AS Query, start_time, percent_complete, dateadd(second,estimated_completion_time/1000, getdate()) as estimated_completion_time
FROM sys.dm_exec_requests r CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) a
WHERE r.command in ('BACKUP DATABASE','RESTORE DATABASE')
GO
上面的查询,每次您按SS5上的F5或Execute按钮时,就可以自行识别会话并执行百分比进度!
该查询是由撰写此帖子的人执行的
在备份命令中添加STATS=10
或STATS=1
。
BACKUP DATABASE [xxxxxx] TO DISK = N'E:\\Bachup_DB.bak' WITH NOFORMAT, NOINIT,
NAME = N'xxxx-Complète Base de données Sauvegarde', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10
GO.
要监视备份或还原进度,与启动备份或还原的会话完全分开。无需第三方工具。在Microsoft SQL Server 2012上测试。
SELECT percent_complete, *
FROM sys.dm_exec_requests
WHERE command In ( 'RESTORE DATABASE', 'BACKUP DATABASE' )
只需在主数据库上运行bkp_status,您将获得备份状态