我每月进行一次完整备份,然后在两者之间进行增量备份。
但同时其他用户可以进行完全备份并打破我的链条。我知道有一个完整备份只有副本。
但在我的情况下,我不知道何时以及谁将进行备份,所以我需要找到一个解决方案来实施以避免这个问题。
有人有想法或解决方案可以实施吗?非常感谢你。
答案 0 :(得分:0)
这个代码示例有点简洁,以便于理解,但表msdb.dbo.backupset可以帮助您解决这个问题。 https://docs.microsoft.com/en-us/sql/relational-databases/system-tables/backupset-transact-sql
declare @MostRecentAuthorizedFullBackup datetime
declare @MostRecentUnauthorizedNonCopyOnlyBackup datetime
declare @AuthorizedBackupUser nvarchar(128) = N'YourBackupUser'
declare @DatabaseName nvarchar(128) = N'YourDatabase'
select @MostRecentAuthorizedFullBackup = backup_start_date
from msdb.dbo.backupset
where database_name = @DatabaseName
and is_copy_only = 0
and type = 'D'
and user_name = @AuthorizedBackupUser
order by backup_start_date desc
select @MostRecentUnauthorizedNonCopyOnlyBackup = backup_start_date
from msdb.dbo.backupset
where database_name = @DatabaseName
and is_copy_only = 0
and type = 'D'
and user_name <> @AuthorizedBackupUser
order by backup_start_date desc
if @MostRecentAuthorizedFullBackup > @MostRecentUnauthorizedNonCopyOnlyBackup
begin
print 'Differential base is good'
end
else
begin
print 'Differential base is bad'
end