[英]Check last Database backup date in C# - SQL Server 2008
我有一个C#Windows窗体应用程序,当启动窗体加载时,我想检查上次在应用程序连接到的数据库上执行备份。
you could create a store procedure that does the work for you. 你可以创建一个为你工作的商店程序。 then you can execute it within the form's
OnLoad
event or where ever it fits for your need. 然后你可以在表单的
OnLoad
事件中执行它,或者它适合你的需要。
Have a look at the below for getting the T-SQL that does the trick 看看下面有关获得T-SQL的技巧
http://www.mssqltips.com/sqlservertip/1601/script-to-retrieve-sql-server-database-backup-history-and-no-backups/ http://www.mssqltips.com/sqlservertip/1601/script-to-retrieve-sql-server-database-backup-history-and-no-backups/
These are taken from my automation of backups: 这些来自我的备份自动化:
First get a list of all databases, including their database GUID: 首先获取所有数据库的列表,包括其数据库GUID:
select db.name, db.database_id, rec.database_guid
from sys.databases db
inner join sys.database_recovery_status rec on db.database_id = rec.database_id
where db.source_database_id is null and db.name <> 'tempdb'
The condition on source_database_id
excludes snapshots. source_database_id
上的条件排除了快照。
Then using the GUID from the above, get the date of the last full backup type='D'
that isn't COPY_ONLY
: 然后使用上面的GUID,获取上次完全备份
type='D'
的日期type='D'
不是COPY_ONLY
:
SELECT MAX(backup_finish_date) as backup_finish_date
from msdb..backupset
where type='D' and database_guid = @DbGuid and is_copy_only=0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.