dataplat / dbatools

🚀 SQL Server automation and instance migrations have never been safer, faster or freer

Home Page:https://dbatools.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test-DbaLastBackup fails if backup was mirrored based on Get-DbaBackupHistory output AND transaction logs are included in the restore test

SQLGB opened this issue · comments

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

Exception             : System.Exception: Microsoft.Data.SqlClient.SqlError: The media loaded on 
                        "\\MyBackupShare\MyServer$MyInstance\MyDatabase\LOG\MyServer$MyInstance_MyDatabase_LOG_20240405_091625.trn" is formatted to support 1 media families, 
                        but 2 media families are expected according to the backup device specification. ---> System.Exception: Microsoft.Data.SqlClient.SqlError: The media loaded on 
                        "\\MyBackupShare\MyServer$MyInstance\MyDatabase\LOG\MyServer$MyInstance_MyDatabase_LOG_20240405_091625.trn" is formatted to support 1 media families, 
                        but 2 media families are expected according to the backup device specification. ---> System.Management.Automation.MethodInvocationException: Exception calling "SqlRestore" 
                        with "1" argument(s): "Restore failed for Server 'MyServer\MyInstance'. " ---> Microsoft.SqlServer.Management.Smo.FailedOperationException: Restore failed for Server 
                        'MyServer\MyInstance'.  ---> Microsoft.SqlServer.Management.Smo.SmoException: Microsoft.Data.SqlClient.SqlError: The media loaded on 
                        "\\MyBackupShare\MyServer$MyInstance\MyDatabase\LOG\MyServer$MyInstance_MyDatabase_LOG_20240405_091625.trn" is formatted to support 1 media families, 
                        but 2 media families are expected according to the backup device specification.
                           at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQueryWithMessage(StringCollection queries, ServerMessageEventHandler dbccMessageHandler, Boolean 
                        errorsAsMessages, Boolean retry)
                           at Microsoft.SqlServer.Management.Smo.BackupRestoreBase.ExecuteSql(Server server, StringCollection queries)
                           at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
                           --- End of inner exception stack trace ---
                           at Microsoft.SqlServer.Management.Smo.Restore.SqlRestore(Server srv)
                           at CallSite.Target(Closure , CallSite , Object , Object )
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
                           at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
                           --- End of inner exception stack trace ---
                           --- End of inner exception stack trace ---
TargetObject          : MyServer\MyInstance
CategoryInfo          : NotSpecified: (MyServer\MyInstance:String) [], Exception
FullyQualifiedErrorId : dbatools_Restore-DbaDatabase
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at Stop-Function, <No file>: line 97891
                        at Restore-DbaDatabase<End>, <No file>: line 71290
                        at Test-DbaLastBackup<Process>, <No file>: line 85210
                        at <ScriptBlock>, <No file>: line 5
PipelineIterationInfo : {}

Steps to Reproduce

To prepare the test, create a new database, then create full, diff and log backups of the database, including at least one mirrored copy of each backup, using the MIRROR TO clause of the BACKUP command. T-SQL for these steps not included here. The command below is just the dbatools command to run Test-DbaLastBackup after you've created a database and backups which include at least one mirrored copy.

Test-DbaLastBackup -SqlInstance MyServer\MyInstance -Database MyDatabase -Destination MyServer\MyInstance -NoCheck -Prefix "dbatools-testrestore-MyServer-MyInstance-$databaseName"

Please confirm that you are running the most recent version of dbatools

2.1.12

Other details or mentions

I created dbatools bug report #5360 on April 11, 2019. A fix was created via #5361 which seems to work for backup types of FULL and DIFF, but if you include LOG backups in your test restore, you still get the errors.

What PowerShell host was used when producing this error

Windows PowerShell ISE (powershell_ise.exe)

PowerShell Host Version

Name                           Value                                                                                                                                                                  
----                           -----                                                                                                                                                                  
PSVersion                      5.1.17763.5576                                                                                                                                                         
PSEdition                      Desktop                                                                                                                                                                
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                
BuildVersion                   10.0.17763.5576                                                                                                                                                        
CLRVersion                     4.0.30319.42000                                                                                                                                                        
WSManStackVersion              3.0                                                                                                                                                                    
PSRemotingProtocolVersion      2.3                                                                                                                                                                    
SerializationVersion           1.1.0.1                                                                                                                                                                

SQL Server Edition and Build number

Microsoft SQL Server 2022 (RTM-CU12) (KB5033663) - 16.0.4115.5 (X64)   Mar  4 2024 08:56:10   Copyright (C) 2022 Microsoft Corporation  Enterprise Edition (64-bit) on Windows Server 2019 Datacenter 10.0 <X64> (Build 17763: ) (Hypervisor) 

.NET Framework Version

.NET Framework 4.7.4051.0