sql docker容器
In this 17th article of the series (see the full article index at bottom), we will discuss the concepts of database backup-and-restore operations on SQL Server Docker containers. This is certainly the era of containers era and it is buzz right now, so let us understand the importance of backup-and-restore the databases on the Docker containers.
在该系列的第 17篇文章中(请参阅底部的完整文章索引),我们将讨论SQL Server Docker容器上的数据库备份和还原操作的概念。 这肯定是容器时代,现在很流行,所以让我们了解在Docker容器上备份和还原数据库的重要性。
Docker containers are systems that are small, light weight, isolated, and segmented subsystems built on the Linux or Windows host system. It’s just running an application on the host machine.
Docker容器是在Linux或Windows主机系统上构建的小型,轻量,隔离和分段子系统的系统。 它只是在主机上运行一个应用程序。
This article discusses the following topics:
本文讨论以下主题:
- Pre-requisites 先决条件
- Steps to initiate a database backup and copy the backup file across the containers 启动数据库备份并跨容器复制备份文件的步骤
- Step by step to restore a database 逐步还原数据库
- Pulling the latest SQL Server 2017 container images from the docker registry 从Docker注册表中提取最新SQL Server 2017容器映像
- Running the downloaded Docker container image using docker run command 使用docker run命令运行下载的Docker容器映像
- Details the steps to create the database in the container 详细说明在容器中创建数据库的步骤
- Explain data persistence in Docker 解释Docker中的数据持久性
- And more… 和更多…
先决条件 (Pre-requisites)
The list describes essential prerequisites to follow along the article
该列表描述了本文遵循的基本前提条件
- Docker engine 1.8+ on Linux/Mac/Windows Linux / Mac / Windows上的Docker引擎1.8+
- Min 2 GB disk space and Min 2 GB RAM 最少2 GB磁盘空间和最少2 GB RAM
- Open the Super User console 打开超级用户控制台
- Basic understanding of Docker containers 对Docker容器的基本了解
入门 (Getting started)
To build the SQL Server 2017 container use the docker pull command and specify the reference to the latest available Docker container image from the Microsoft repo registry.
要构建SQL Server 2017容器,请使用docker pull命令并从Microsoft存储库注册表中指定对最新可用Docker容器映像的引用。
docker pull microsoft/mssql-server-linux:2017-latest
docker pull microsoft / mssql-server-linux:2017-latest
To run the SQL Server Docker container, in the background, use docker run command.
要在后台运行SQL Server Docker容器,请使用docker run命令。
docker run -e ‘ACCEPT_EULA=Y’ -e ‘MSSQL_SA_PASSWORD=SQLShack$2018’ –name shackdemo1 -p 1401:1433 -d microsoft/mssql-server-linux:latest
docker run -e'ACCEPT_EULA = Y'-e'MSSQL_SA_PASSWORD = SQLShack $ 2018'–name shackdemo1 -p 1401:1433 -d microsoft / mssql-server-linux:latest
To instantiate a bash session, run the bash executable using docker exec command.
要实例化bash会话,请使用docker exec命令运行bash可执行文件。
docker exec –it shackdemo1 bash
docker exec –it shackdemo1 bash
Now, a Bash session is opened for SQLShackDemo1 container. Connect to the SQL instance using sqlcmd and create a new database named SQLShackDemo.
现在,将为SQLShackDemo1容器打开一个Bash会话。 使用sqlcmd连接到SQL实例并创建一个名为SQLShackDemo的新数据库。
Next, create a sample table SQLAuthor and insert few dummy records into the table.
接下来,创建一个示例表SQLAuthor并将少量虚拟记录插入表中。
Let us create a database backup using backup database command
让我们使用backup database命令创建数据库备份
BACKUP DATABASE [SQLShackDemo] TO DISK = N’/var/opt/mssql/backup/SQLShackDemo.bak’ WITH FORMAT, INIT, COMPRESSION,STATS = 10
备份数据库[SQLShackDemo]到磁盘= N'/ var / opt / mssql / backup / SQLShackDemo.bak',格式,INIT,COMPRESSION,STATS = 10