microsoft / mssql-docker

Official Microsoft repository for SQL Server in Docker resources
MIT License
1.7k stars 753 forks source link

Remotely backup SQL Server Docker container Using Powershell #392

Open danielman111 opened 5 years ago

danielman111 commented 5 years ago

I have a SQL Server on a docker container (microsoft/mssql-server-linux) I want to Backup the database remotely using Powershell command.

So The final result will be that a .bak file would be added to the container. Does anyone knows if it is possible, and how?

twright-msft commented 5 years ago

Should be totally fine. If you dont specify a directory to backup the .bak file to the backup file will be backed up to the default/configurable backup directory. By default that dir is /var/opt/mssql/data "inside" the container. If that directory is mounted to the underlying host then it will be persisted to the host file system if that is what you want to do.

Public service announcement: We are going to eventually stop distributing the SQL Server container images via Docker Hub (i.e. /microsoft/mssql-server-linux). We are moving to the new Microsoft Container Registry (mcr.microsoft.com) so please change to using docker pull mcr.microsoft.com/mssql/server

See the We're moving! announcement for more info.

danielman111 commented 5 years ago

Hi, Thanks for the answer, Do you know how I backup using the powershell-core? I saw that there is powershell command named Backup-SqlDatabase View Link here: Link

But it does not work on Powershell Core (version 6), my powershell version 5.1 recognized the command.

Or if you have any other method to backup the containred SQL Server from a remote machine, I would like to hear that.

My idea was to send some Rest command to the SQL Server container to perform the back, but I didn't find a way to do it.

Thanks

twright-msft commented 5 years ago

The PowerShell cmdlets are not really supported on PowerShell core yet (we are working on it though!). You can either use full PowerShell on Windows and remotely connect to the SQL Server instance to run the PowerShell commands or you can use a command line utility such as sqlcmd (pre-installed with SQL Server on Windows and SSMS or download/install) (docs) or mssql-cli (install/docs) to remotely connect and run a T-SQL script using BACKUP DATABASE.