码迷,mamicode.com
首页 > 数据库 > 详细

查询数据库还原时间

时间:2021-02-23 14:26:19      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ast   tran   har   数据   sys   dbn   varchar   databases   tar   


--查询数据库还原时间
SELECT sdb.Name AS DatabaseName ,
COALESCE(CONVERT(VARCHAR(12), MAX(bus.backup_finish_date), 101), ‘-‘) AS LastBackUpTime
FROM sys.sysdatabases sdb
LEFT OUTER JOIN msdb.dbo.backupset bus ON bus.database_name = sdb.name
where sdb.Name=‘DS_LF‘
GROUP BY sdb.Name

SET NOCOUNT ON
GO
SET quoted_identifier OFF
DECLARE @dbname AS VARCHAR(80)
DECLARE @msgdb AS VARCHAR(100)
DECLARE @dbbkpname AS VARCHAR(80)
DECLARE @dypart1 AS VARCHAR(2)
DECLARE @dypart2 AS VARCHAR(3)
DECLARE @dypart3 AS VARCHAR(4)
DECLARE @currentdate AS VARCHAR(10)
DECLARE @server_name AS VARCHAR(30)
SELECT @server_name = @@servername
SELECT @dypart1 = DATEPART(dd,GETDATE())
SELECT @dypart2 = DATENAME(mm,GETDATE())
SELECT @dypart3 = DATEPART(yy,GETDATE())
SELECT @currentdate= @dypart1 + @dypart2 + @dypart3
PRINT "#####################################################################"
PRINT "# SERVERNAME : "+ @server_name + " DATE : "+ @currentdate +"#"
PRINT "#####################################################################"
PRINT "DatabaseName Full Diff TranLog"
PRINT "##########################################################################################################################################"
SELECT SUBSTRING(s.name,1,50) AS ‘DATABASE Name‘,
b.backup_start_date AS ‘Full DB Backup Status‘,
c.backup_start_date AS ‘Differential DB Backup Status‘,
d.backup_start_date AS ‘Transaction Log Backup Status‘
FROM MASTER..sysdatabases s
LEFT OUTER JOIN msdb..backupset b
ON s.name = b.database_name
AND b.backup_start_date =
(SELECT MAX(backup_start_date)AS ‘Full DB Backup Status‘
FROM msdb..backupset
WHERE database_name = b.database_name
AND TYPE = ‘D‘) -- full database backups only, not log backups
LEFT OUTER JOIN msdb..backupset c
ON s.name = c.database_name
AND c.backup_start_date =
(SELECT MAX(backup_start_date)‘Differential DB Backup Status‘
FROM msdb..backupset
WHERE database_name = c.database_name
AND TYPE = ‘I‘)
LEFT OUTER JOIN msdb..backupset d
ON s.name = d.database_name
AND d.backup_start_date =
(SELECT MAX(backup_start_date)‘Transaction Log Backup Status‘
FROM msdb..backupset
WHERE database_name = d.database_name
AND TYPE = ‘L‘)
WHERE s.name <>‘tempdb‘ and s.name=‘DS_LF‘
ORDER BY s.name

查询数据库还原时间

标签:ast   tran   har   数据   sys   dbn   varchar   databases   tar   

原文地址:https://www.cnblogs.com/chengzi00/p/14433705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!