使用Powershell获取SQL备份数据

发布于 2024-12-11 20:48:10 字数 559 浏览 0 评论 0原文

我一直在寻找自动获取有关 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宁愿没拥抱 2024-12-18 20:48:10

在查找最近备份的时间和文件名时,我经常使用这样的查询。这个特定的查询将返回最近的完整备份或差异备份,但显然您可以根据需要更改它。

SELECT 
    bf.physical_device_name ,
    name ,
    bs.backup_start_date ,
    bs.media_set_id
    FROM sys.databases d
    OUTER APPLY (
        SELECT TOP 1
            backup_start_date ,
            media_set_id
        FROM msdb.dbo.backupset
        WHERE type != 'L'
        AND database_name = d.name
        ORDER BY backup_start_date DESC
    ) bs
INNER JOIN msdb.dbo.backupmediafamily bf ON bf.media_set_id = bs.media_set_id

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.

SELECT 
    bf.physical_device_name ,
    name ,
    bs.backup_start_date ,
    bs.media_set_id
    FROM sys.databases d
    OUTER APPLY (
        SELECT TOP 1
            backup_start_date ,
            media_set_id
        FROM msdb.dbo.backupset
        WHERE type != 'L'
        AND database_name = d.name
        ORDER BY backup_start_date DESC
    ) bs
INNER JOIN msdb.dbo.backupmediafamily bf ON bf.media_set_id = bs.media_set_id
相权↑美人 2024-12-18 20:48:10

我倾向于对 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文