Skip to content

Restore-DbaDatabase failes with "file already exists" on Azure SQL MI #10386

Description

@transmokopter

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

I'm restoring a database on an Azure SQL MI, using Restore-DbaDatabase
I first tried with -WithReplace, but got this error message:
"File C:\SFApplications\Worker.CL.WCOW.SQL22_App15\work\data\ab5ca1fc-372f-4deb-be9f-369e4ea5bd92.xtp already exists on myinstancename.f9c13c324b0c.database.windows.net, not owned by any database in mysqlmi.abc123def456.database.windows.net, will not overwrite."

Since it's not possible to use WITH REPLACE on a Managed Instance I figured that might be the problem. So I used Remove-DbaDatabase and then rerun Restore-DbaDatabase without -WithReplace.

Same error.

Dropping the database with t-sql and then restoring with restore database testdb from url =N'https://mystorageaccount.blob.core.windows.net/backups/testdb.bak' works just fine.
When I drop and restore the database with t-sql, the xtp file gets a new name every time without me using the move directive for restore database. So it seems like Azure SQL Managed Instance takes care of the possibility that there are orphaned xtp-files left from previous operations by always creating it with a new name.
I guess Restore-DbaDatabase should skip this check when restoring to a managed instance (?)

Steps to Reproduce

$cn = Connect-DbaInstance -SqlInstance mysqlmi.abc123def456.database.windows.net -AppendConnectionString 'Authentication=ActiveDirectoryInteractive;Integrated Security=False'
Remove-DbaDatabase -SqlInstance $cn -Database testdb
Restore-DbaDatabase -SqlInstance $cn -DatabaseName testdb -Path https://mystorageaccount.blob.core.windows.net/backups/testdb.bak

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

2.8.2

Other details or mentions

No response

What PowerShell host was used when producing this error

PowerShell Core (pwsh.exe)

PowerShell Host Version

Name Value


PSVersion 7.5.5
PSEdition Core
GitCommitId 7.5.5
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

SQL Server Edition and Build number

Microsoft SQL Azure (RTM) - 12.0.2000.8 May 4 2026 08:02:12 Copyright (C) 2022 Microsoft Corporation

.NET Framework Version

PSChildName Version


v2.0.50727 2.0.50727.4927
v3.0 3.0.30729.4926
Windows Communication Foundation 3.0.4506.4926
Windows Presentation Foundation 3.0.6920.4902
v3.5 3.5.30729.4926
Client 4.8.09032
Full 4.8.09032
Client 4.0.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions