C
C#β€’16mo ago
Matanza

❔ Restore database in Docker windows container

Hi. I am going to rewrite a solution built in classic asp in .NET and thought I should dockerise the solution as I will need both the old and new systems to run in parallel. Due to the fact that ASP requires windows servers to run I am limited to windows containers. After a lot of searching I found a 3'rd party image of sql server dev-edition for windows and made it running. My question is: How can I write a docker command that restores a backup of the database to develop against?
56 Replies
Unknown User
Unknown Userβ€’16mo ago
Message Not Public
Sign In & Join Server To View
Matanza
MatanzaOPβ€’16mo ago
Thanks for the answer. I tried using chatGPT which gave me this answer, but it doesn't work. RUN sqlcmd -S localhost -U SA -P $env:SA_PASSWORD -Q "RESTORE DATABASE [$env:RESTORE_DB] FROM DISK = 'C:\SQLData\YourBackupFile.bak' WITH MOVE 'YourLogicalName' TO 'C:\SQLData$env:RESTORE_DB.mdf', MOVE 'YourLogicalName_Log' TO 'C:\SQLData$env:RESTORE_DB.ldf', REPLACE;" But I will search some more in the docs πŸ™‚ As it is now I can start the container and manually restore the database. I am just hoping that I can do it all automatically
Unknown User
Unknown Userβ€’16mo ago
Message Not Public
Sign In & Join Server To View
Joreyk ( IXLLEGACYIXL )
what should a "3rd party sql server dev edition" should be? the original one is free to use and "doesnt work" is 0 info if you just want to get your stuff backin non automated use ssms gui
Matanza
MatanzaOPβ€’16mo ago
When I try to use the official one I get an error message when trying to download the image from Microsoft. What I have understood from searching is that the windows image is not supported and only the linux one is.
Joreyk ( IXLLEGACYIXL )
which linux do you have? whatever
Matanza
MatanzaOPβ€’16mo ago
I can't use linux as I have to host classic ASP. Therefore I must run it all in windows containers right now
Joreyk ( IXLLEGACYIXL )
you say you are on linux but you have a powershell command and what error do you get with the command
Matanza
MatanzaOPβ€’16mo ago
Unexpected argument. and returned a non-zero code: 1
Joreyk ( IXLLEGACYIXL )
you have powershell on that container?
Unknown User
Unknown Userβ€’16mo ago
Message Not Public
Sign In & Join Server To View
Matanza
MatanzaOPβ€’16mo ago
Sqlcmd: 'DATABASE [XXXX] FROM DISK = C:\SQLData\XXX.bak WITH MOVE XXX TO C:\SQLData$env:RESTORE_DB.mdf REPLACE': Unexpected argument. Enter '-?' for help. The command 'powershell -Command $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; sqlcmd -S localhost -U SA -P $env:SA_PASSWORD -Q "RESTORE DATABASE [$env:RESTORE_DB] FROM DISK = 'C:\SQLData\backupfile.bak' WITH MOVE 'XXX' TO 'C:\SQLData$env:RESTORE_DB.mdf', REPLACE;"' returned a non-zero code: 1 ok. It might be that I have no powershell in that image
Unknown User
Unknown Userβ€’16mo ago
Message Not Public
Sign In & Join Server To View
Joreyk ( IXLLEGACYIXL )
or pwsh
Unknown User
Unknown Userβ€’16mo ago
Message Not Public
Sign In & Join Server To View
Joreyk ( IXLLEGACYIXL )
pwsh
Invoke-Sqlcmd -ServerInstance localhost -User sa -Password asdf -Query "RESTORE DATABASE [$env:RESTORE_DB] FROM DISK = 'C:\SQLData\backupfile.bak' WITH MOVE 'XXX' TO 'C:\SQLData$env:RESTORE_DB.mdf', REPLACE;"
pwsh
Invoke-Sqlcmd -ServerInstance localhost -User sa -Password asdf -Query "RESTORE DATABASE [$env:RESTORE_DB] FROM DISK = 'C:\SQLData\backupfile.bak' WITH MOVE 'XXX' TO 'C:\SQLData$env:RESTORE_DB.mdf', REPLACE;"
sqlcmd -S localhost -U SA -P $env:SA_PASSWORD this is impossible that it works as its powershell syntax that you run in cmd it cant work
Matanza
MatanzaOPβ€’16mo ago
I thought about that as well. Maybe I have to start the container before I restore the database?
Joreyk ( IXLLEGACYIXL )
is your sql server online? you are currently hardcore trying random stuff... 1. turn your sql server on 2. check that your login is valid 3. are your files where they should be
Matanza
MatanzaOPβ€’16mo ago
I am trying to start a development environment. I am not connecting to the real server.
Joreyk ( IXLLEGACYIXL )
whatever it is where you want to connect to in addition to that if you dont need a ful install and just the db you could use localdb which is meant for developers
Matanza
MatanzaOPβ€’16mo ago
I'm not used to work in docker. Therefore I'm kind of winging it right now to learn
Joreyk ( IXLLEGACYIXL )
how big is your developement db at max in total
Matanza
MatanzaOPβ€’16mo ago
Quite small. 200Mb the bak-file
Joreyk ( IXLLEGACYIXL )
which linux do you have? ubuntu?
Matanza
MatanzaOPβ€’16mo ago
I'm on windows, so it is wsl for docker containers. But I think it is Ubuntu yes
Joreyk ( IXLLEGACYIXL )
you are on windows then why do you not just install it regurarly or use localdb?
Matanza
MatanzaOPβ€’16mo ago
I wanted it to be general so colleagues could easilly work on it as well
Joreyk ( IXLLEGACYIXL )
but your pc wont run all the time then you are at the same spot again
Matanza
MatanzaOPβ€’16mo ago
That is why I wanted the database in the container instead of my localdb
Joreyk ( IXLLEGACYIXL )
if you turn oyur pc off then the container is also off
Matanza
MatanzaOPβ€’16mo ago
Yes. But if I could run a sql server in a container and restore a demodb inside it. All of them could get one through the docker-compose. That was my thought at least
Joreyk ( IXLLEGACYIXL )
or you throw the mdf into a shared file system and launch it through localdb localdb is just a click in VS its the engine to be able to open mdf files
Matanza
MatanzaOPβ€’16mo ago
ok. Thanks. I will look into that option. Is it as simple in Rider?
Joreyk ( IXLLEGACYIXL )
uhhh
Joreyk ( IXLLEGACYIXL )
seems like its only supposed to handle mdf files tho like there is no sql agent or management or always on
Matanza
MatanzaOPβ€’16mo ago
Thanks.
Joreyk ( IXLLEGACYIXL )
developer edition is meant to replicate your production db for testing ( with no real data .. else you get license problems ) as its a ful enterprise version sql express is awful ( for companies who dont know what to do with their money ) and localdb is for developement purposes you edit your mdf file and give it your dbas so they can hook it into the developer edition and the testers can test then on a production equivalent edition or you rent in your company one Wndows server with 1 core and get happy 1 core is more than enough there you would let your dbas make it in always on developer edition so you have at any time a sql server no matter what localdb is never bad to have though... you can just open mdf files which is nice to have ( max 10gb )
Matanza
MatanzaOPβ€’16mo ago
Yes. It might be that it is the best solution. But right now access to our databases are restricted and can't be accessed from anywhere else. But I think we will open up a development server
Joreyk ( IXLLEGACYIXL )
you have a dba team? then let them do it... 2 1-core servers in always on cluster so you push the management to them less work for you and less responsibility
Matanza
MatanzaOPβ€’16mo ago
it is a very small company where I recently joined. I have one colleague who is in contact with the server-host. All knowledge they have is probably 20 years old and related to classic asp
Joreyk ( IXLLEGACYIXL )
you are not allowed to store real user data into a dev system tho.. or "protected user data" imagine it like microsoft could come any day and look at the data and you have to allow them to do so if you are a small company get these two 1 core servers they dont need an sql server license as developer is free and throw all developement instances on it mssql can easily manage multiple instances on single core when only a few people work at it
Matanza
MatanzaOPβ€’16mo ago
Thanks πŸ™‚
Joreyk ( IXLLEGACYIXL )
more cores is a waste of money you will have to pay windows server license but i think there was a cheap license for small companies mybe increase at some point to 2 cores... but i doubt that you wil lreach that point always on is easy to setup...which makes it the best per default the way it works is also nice but the ease of use makes it bueno you will need an Active Directory Availability Group listener and your 2 servers in a cluster then you type that in in ssms and let it do the rest ah and a gmsa account to make it easier with host account
Matanza
MatanzaOPβ€’16mo ago
Thanks for your help. It is much appreciated. I haven't been handling db-related stuff before. Only focused on coding πŸ™‚ Yes, I see πŸ™‚
Joreyk ( IXLLEGACYIXL )
and i would tell you not to use ORM where the code is the truth source but any other coder will tell you ORM is the best
Matanza
MatanzaOPβ€’16mo ago
πŸ˜†
Joreyk ( IXLLEGACYIXL )
is there any particular reason to use mssql? in the end you will result in paying licenses for the enterprise edition in production at some point mybe its not the best choice at all πŸ‘€
Matanza
MatanzaOPβ€’16mo ago
It is used in the old solution. My goal is to be more flexible in the future, but right now focus is on making the two systems running together
Joreyk ( IXLLEGACYIXL )
postgres is much more flexible than mssql , but some sort of more complexe but its free you will have to pay enterprisedb support at some point but thats a fraction of the enterprise license cost
Matanza
MatanzaOPβ€’16mo ago
I'm not sure how well the old system can handle that change right now. And as they did in the 90's they have no version control and use the rename the file versioning
Joreyk ( IXLLEGACYIXL )
bruh mkay keep it in mind postgres has compared to mssql some advantages one is you can embed it entirely with mysticmind postgresembed microsoft discontinued a ful embedded mssql server in 2006
Matanza
MatanzaOPβ€’16mo ago
I will. I am also open to migrate some tables to Nosql if I find it suitable
Joreyk ( IXLLEGACYIXL )
also try phind.com as AI helper as he makes less nonsense answers and gives you the sauces frome where it got it
Matanza
MatanzaOPβ€’16mo ago
Thanks
Accord
Accordβ€’16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server