Asked 1 month ago by VoidScientist251
How can I copy a production SQL Server database to a local Docker instance without Windows authentication?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by VoidScientist251
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
To improve developer experience and avoid migration conflicts, we want each developer to have a local copy of the production database running in Docker.
My plan is to create a tool or script that backs up the production database and restores it on a local Docker instance. The process should extract only the necessary schema elements (tables, schemas, functions, stored procedures, and views) while excluding Windows-authenticated users; having everything under the SA account is acceptable.
Since the developers work on macOS, we cannot use SSMS, and the production database's file system isn’t accessible. I've managed to use a data-tier application for most databases, but issues arise when some schemas require Windows authentication, which isn’t available locally.
The following answer suggests using Microsoft’s cross‑platform SQLPackage tool to extract a lightweight DACPAC that only includes the desired schema objects and then deploy it to the local Docker-hosted SQL Server instance:
BASHsqlpackage /Action:Extract \ /SourceConnectionString:"Data Source=prodserver;Initial Catalog=prodDb;User ID=yourUser;Password=yourPassword;" \ /TargetFile:"proddb.dacpac" \ /p:ExcludeObjectTypes=Logins,Users,Roles
and later deploying it using:
BASHsqlpackage /Action:Publish \ /TargetConnectionString:"Data Source=localhost,1433;Initial Catalog=devDb;User ID=SA;Password=yourSAPassword;" \ /SourceFile:"proddb.dacpac" \ /p:DropObjectsNotInSource=True \ /p:BlockOnPossibleDataLoss=False
This approach avoids copying over unwanted security objects from production while ensuring that each local environment mimics the necessary structure for development.
Comments 0
•Answers 2
•Views 61
Answer by TychoAI Agent • 1 month ago
Below is one approach that uses Microsoft’s cross‑platform SQLPackage tool to extract a lightweight DACPAC of just your schema objects and then deploy it against your local docker SQL Server instance. This method avoids copying over users (and related security objects) while preserving tables, schemas, functions, stored procedures, and views.
Extracting the Schema from Prod
Use SQLPackage’s Extract action to create a DACPAC from your production database. When doing so, set parameters to exclude users (and any other security objects you don’t need) so that any schema tied to Windows authentication isn’t included.
Deploying on the Local Machine
Transfer the resulting DACPAC to your Mac. Then use SQLPackage’s Publish action to deploy the schema to a docker-hosted SQL Server running with the SA account.
Since SSMS isn’t available on Mac, SQLPackage is ideal because it’s cross‑platform. You can run a command like the following from a Windows machine (or any environment where SQLPackage is installed):
BASHsqlpackage /Action:Extract \ /SourceConnectionString:"Data Source=prodserver;Initial Catalog=prodDb;User ID=yourUser;Password=yourPassword;" \ /TargetFile:"proddb.dacpac" \ /p:ExcludeObjectTypes=Logins,Users,Roles
Notes:
/p:ExcludeObjectTypes
property excludes security objects (logins and users) that cause issues in a Windows‑authenticated production environment.Once you have the DACPAC on your local machine, you can deploy it onto your docker‑hosted SQL Server instance. On your Mac, with SQLPackage installed (via Homebrew or direct download), run:
BASHsqlpackage /Action:Publish \ /TargetConnectionString:"Data Source=localhost,1433;Initial Catalog=devDb;User ID=SA;Password=yourSAPassword;" \ /SourceFile:"proddb.dacpac" \ /p:DropObjectsNotInSource=True \ /p:BlockOnPossibleDataLoss=False
Notes:
/p:DropObjectsNotInSource=True
parameter ensures that any objects present in the target but not in the DACPAC are removed, keeping your local environment in sync./p:BlockOnPossibleDataLoss=False
parameter bypasses interactive confirmation for changes that may lead to data loss (since you’re dealing with a dev database).This solution provides a consistent way to extract only the objects you care about from production and re‑apply them locally, enhancing developer experience and reducing headaches around migration conflicts.
Feel free to adjust any parameters and review SQLPackage documentation for additional options as needed.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by PlutonianSentinel096 • 1 month ago
You can use sqlpackage.exe to extract a dacpac that excludes server scoped objects such as logins and credentials.
sqlpackage.exe /a:Extract /p:ExtractReferencedServerScopedElements=false /p:ExtractAllTableData=true ...
Note the use of /a:Extract instead of /a:Export to generate a .dacpac instead of a .bacpac
If you need additional flexibility, since .dacpac's and .bacpacs are just zip files, you can unzip/edit/rezip them to perform any additional customizations required.
No comments yet.
No comments yet.