dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer
https://dbatools.io
MIT License
2.47k stars 802 forks source link

[Bug] Test-DbaLastBackup - backup history is getting corrupted #5836

Closed kmramsey closed 4 years ago

kmramsey commented 5 years ago

Environmental information

Name                           Value                                                                                                                                                                                      
----                           -----                                                                                                                                                                                      
PSVersion                      5.0.10586.117                                                                                                                                                                              
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                    
BuildVersion                   10.0.10586.117                                                                                                                                                                             
CLRVersion                     4.0.30319.42000                                                                                                                                                                            
WSManStackVersion              3.0                                                                                                                                                                                        
PSRemotingProtocolVersion      2.3                                                                                                                                                                                        
SerializationVersion           1.1.0.1                                                                                                                                                                                    

Name    : dbatools
Path    : C:\windows\system32\WindowsPowerShell\v1.0\Modules\dbatools\dbatools.psd1
Version : 1.0.9

SQL Server:

Microsoft SQL Server 2014 (SP3-CU2) (KB4482960) - 12.0.6214.1 (X64) 
    Feb  2 2019 01:10:18 
    Copyright (c) Microsoft Corporation
    Developer Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)

Report

I believe I have reviewed the things to consider.

Host used

If anything other than powershell.exe was used, please confirm that you can duplicate the issue with powershell.exe

Errors Received

No errors were received.

Steps to Reproduce


##  You need two database instances.
##  Create a database with the exact same name on both instances (ExampleDB).
##  Perform a backup on both of the databases so that you can see prior history, and be able to perform a dbcc.
##  Strong preference that you save your backups with the server name in the backup name.  This will allow you to trace where the history is coming from when you get to the last line.

$MyExampleDatabase = 'ExampleDB'
$destinationInstance = 'InsertHere'
$Someplaceelse = 'InsertHere'

$mytsql = "-- Step 1 Delete backup history
            use msdb
            EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'$MyExampleDatabase'
          "

Invoke-DbaQuery -SqlInstance $destinationInstance  -Database msdb -Query $mytsql 

Get-DbaDbBackupHistory -SqlInstance $destinationInstance -Database $MyExampleDatabase | select SqlInstance, Database, Type, TotalSize, DeviceType, Start, Duration, End, path | ft

Backup-DbaDatabase -SqlInstance $destinationInstance  -Database $MyExampleDatabase

Get-DbaDbBackupHistory -SqlInstance $destinationInstance -Database $MyExampleDatabase | select SqlInstance, Database, Type, TotalSize, DeviceType, Start, Duration, End, path | ft

Test-DbaLastBackup -SqlInstance $destinationInstance  -Database $MyExampleDatabase  -Destination $destinationInstance   -CopyFile -Prefix "MY_DBCC_" 

Get-DbaDbBackupHistory -SqlInstance $destinationInstance -Database $MyExampleDatabase | select SqlInstance, Database, Type, TotalSize, DeviceType, Start, Duration, End, path | ft

Test-DbaLastBackup -SqlInstance $Someplaceelse  -Database $MyExampleDatabase  -Destination $destinationInstance   -CopyFile -Prefix "MY_DBCC_" ```

# if you're backup file name has the server name in the name, then when you run this command, you'll see two instances have backup files in one database.
Get-DbaDbBackupHistory -SqlInstance $destinationInstance -Database $MyExampleDatabase | select SqlInstance, Database, Type, TotalSize, DeviceType, Start, Duration, End, path | ft

#### Expected Behavior

I expected the `$MyExampleDatabase` on the `$destinationInstance` instance would **NOT** have its backup history show backup information from the `$Someplaceelse` instance.  

#### Actual Behavior

The `$Someplaceelse` backup information is in the `$MyExampleDatabase` from the `$destinationInstance`.  From what I can tell, this means that when the restore of the prefixed database (MY_DBCC_) somehow did not specify a database name when restoring and ended up confusing the histories together.  This could be a problem with the restore script and not the test database backup script.  If I had to guess, the prefix name (MY_DBCC_) should be passed in as the database name to prevent cross pollination.
kmramsey commented 5 years ago

Would someone mind trying to reproduce this problem and confirm it? Thanks!

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. If you would like this issue to remain open:

kmramsey commented 5 years ago

I believe this is a bug. Can someone please investigate?

sorry... I got a stale notification. I'm not trying to be a pest.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. If you would like this issue to remain open:

stale[bot] commented 4 years ago

This issue has been automatically closed because it has not had activity in the last three months. If this issue is still valid, please add a comment