使用Powershell获取SQL备份数据
我一直在寻找自动获取有关 SQL 备份信息的方法,以及 这篇 Technet 文章 会很好,除了它返回的数据存在问题。
运行时,它会返回我知道尚未通过 SQL 备份的测试数据库的“上次备份”日期。看来它占用了系统备份的时间;它与操作系统事件日志中的 beVSS 启动时间一致(服务器由 Backup Exec 2010 备份,不使用 SQL 代理)。
我希望它收集上次运行 SQL 备份的时间,而不是系统备份。这有可能以某种方式过滤掉吗?
数据库服务器是 Windows Server 2008/SQL server 2008。
编辑:
澄清一下,我正在寻找 PowerShell 中的解决方案,而不是 SQL,并了解为什么 PowerShell 返回它的功能。
I've been looking at ways to automatically get information about SQL backups, and the Powershell script in this Technet article would do nicely, except for an issue with the data it returns.
When run, it returns a "last backup" date for test databases I know have not been backed up via SQL. It would appear that it's taking the times of the system backup; it coincides with beVSS start times in the OS event log (the server is backed up by Backup Exec 2010, not using the SQL agent).
I would like it to gather the last time that the SQL backup was run, not a system backup. Is this possible to filter out somehow?
The DB Server is Windows Server 2008/SQL server 2008.
Edit:
To clarify, I'm looking for solutions in PowerShell, not SQL, and to understand why PowerShell returns what it does.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在查找最近备份的时间和文件名时,我经常使用这样的查询。这个特定的查询将返回最近的完整备份或差异备份,但显然您可以根据需要更改它。
I often use a query like this when looking for the time and filename of the most recent backup. This particular query will return either the most recent FULL Backup or Differential Backup but obviously you can change that if you like.
我倾向于对 msdb 中的备份集表使用查询,而不是您引用的文章中提到的 SMO LastBackupDate 数据库属性。
在我的环境中,我们使用 CommVault Galaxy 进行备份,我可以通过查看备份集表的 user_name 列来筛选出 CommvVault 备份与常规 SQL 备份。 SQL Agent 和 CommVault 在不同的用户帐户下运行。
http://msdn.microsoft.com/en-us/library/ms186299.aspx
I've tended to use queries against the backupset table in msdb instead of the SMO LastBackupDate Database property as mentioned in the article you referenced.
In my environment we're using CommVault Galaxy for backups and I can filter out backups by CommvVault vs. regular SQL backups by looking at the the user_name column of the backupset table. SQL Agent and CommVault run under difference user accounts.
http://msdn.microsoft.com/en-us/library/ms186299.aspx