千家信息网

docker 安装sql2017还原windows2012数据库备份

发表于:2024-11-12 作者:千家信息网编辑
千家信息网最后更新 2024年11月12日,docker 安装sql2017还原windows2012数据库备份1. centos7.6安装docker#安装依赖包yum install -y yum-utils device-mapper-p
千家信息网最后更新 2024年11月12日docker 安装sql2017还原windows2012数据库备份

docker 安装sql2017还原windows2012数据库备份

1. centos7.6安装docker

#安装依赖包yum install -y yum-utils device-mapper-persistent-data lvm2#下载docker yum源yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo#下载dockeryum install -y docker#配置国内镜像[root@node1 ~]#cat /etc/docker/daemon.json {"registry-mirrors": ["https://kfwkfulq.mirror.aliyuncs.com","https://2lqq34jg.mirror.aliyuncs.com","https://pee6w651.mirror.aliyuncs.com","https://registry.docker-cn.com","http://hub-mirror.c.163.com"],"dns": ["8.8.8.8","8.8.4.4"]}#启动&开机启动dockersystemctl start docker && systemctl enable docker

2.docker安装mssql2017

#搜索镜像[root@node1 ~]# docker search mssqlINDEX       NAME                                                            DESCRIPTION                                     STARS     OFFICIAL   AUTOMATEDdocker.io   docker.io/microsoft/mssql-server-linux                          Deprecated SQL Server on Linux Container R...   1159                 docker.io   docker.io/microsoft/mssql-server-windows-developer              Official Microsoft SQL ..........................#下载镜像[root@node1 ~]#docker pull microsoft/mssql-server-linux:2017-latest#查看下载好的镜像[root@node1 ~]# docker images      REPOSITORY                               TAG                 IMAGE ID            CREATED             SIZEdocker.io/microsoft/mssql-server-linux   2017-latest         314918ddaedf        11 months ago       1.35 GB#创建并运行容器[root@node1 ~]#docker run --name MSSQL_1433 -m 512m -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=yourpasSw0rd' --net=host -d microsoft/mssql-server-linux[root@node1 ~]# docker start eae198ad6034(可以启动ID或者容器名)eae198ad6034#查看创建好的容器(UP代表已经启动)[root@node1 ~]# docker ps -aCONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                    PORTS               NAMESeae198ad6034        314918ddaedf        "/opt/mssql/bin/sq..."   24 hours ago        Up 58 minutes                                 MSSQL_14338b1962a03efe        314918ddaedf        "/bin/bash"              25 hours ago        Exited (0) 24 hours ago                       linuxmssql#进入容器[root@node1 ~]# docker exec -it eae198ad6034 /bin/bash#进入数据库(IP是宿主机的IP,用户是大写的)root@node1:~# /opt/mssql-tools/bin/sqlcmd -S 172.16.10.66 -U SA  -P 'lihao@123'     #出现这个就表示进入数据库了1> select name from sys.databases;2> goname                                                                                                                            --------------------------------------------------------------------------------------------------------------------------master                                                                                                                          tempdb                                                                                                                          model                                                                                                                           msdb   

3.还原数据库

#上传备份文件下载winscp或者lrzsz工具,把备份文件上传宿主机,再把备份文件复制到容器的/var/opt/mssql/data/目录下[root@node1 ~]# docker cp EastRiver.bak eae198ad6034:/var/opt/mssql/data/root@node1:~# ll /var/opt/mssql/data/total 1300488drwxr-xr-x 2 root root      4096 Nov 19 14:25 ./drwxr-xr-x 7 root root        73 Nov 18 15:23 ../-rw-r--r-- 1 root root 205852672 Nov  4 09:43 EastRiver.bak-rw-r----- 1 root root   4194304 Nov 19 15:14 master.mdf-rw-r----- 1 root root   2097152 Nov 19 15:23 mastlog.ldf-rw-r----- 1 root root   8388608 Nov 19 14:09 model.mdf-rw-r----- 1 root root   8388608 Nov 19 14:09 modellog.ldf-rw-r----- 1 root root  15466496 Nov 19 15:14 msdbdata.mdf-rw-r----- 1 root root    786432 Nov 19 15:14 msdblog.ldf-rw-r----- 1 root root   8388608 Nov 19 14:09 tempdb.mdf-rw-r----- 1 root root   8388608 Nov 19 15:14 templog.ldf-rw-r----- 1 root root   8388608 Nov 19 14:09 test.mdf-rw-r----- 1 root root   8388608 Nov 19 15:09 test_log.ldf #打开Windows下的sql管理工具(我用2008R2中文版的不行,用2012的英文版的可以,不清楚是中英文的关系,还是版本的的关系,有兴趣的你们可以试试)新建了一个test库create database test;

#还原数据库

后面的操作因为某些原因无法上图了,都跟Windows还原一样了,百度一下就可以了
还原成功后,就出现新的库了

#在容器上查看1> select name from sys.databases2> goname                                                                                                                            --------------------------------------------------------------------------------------------------------------------------------master                                                                                                                          tempdb                                                                                                                          model                                                                                                                           msdb                                                                                                                            test                                                                                                                            EastRiver                                                                                                                       (6 rows affected)1> use EastRiver2> goChanged database context to 'EastRiver'.1> select name from sys.tables;2> goname                                                                                                                            --------------------------------------------------------------------------------------------------------------------------------BlackCardTask                                                                                                                   ReplaceReg_D                                                                                                                    TransRecords                                                                                                                    Archs                                                                                                                           RefuseReg_M                                                                                                                     BlackCardTaskClockState                                                                                                         MChargeRecords                                                                                                                  Area                                                                                                                                                                                                                                     ......                                                                                                                 UpLoadTable_comp2                                                                                                               Company                                                                                                                         PriceHistory                                                                                                                                                                                                                           CommMsg                                                                                                                                                                                                                                             OpLog                                                                                                                           CardTypeConfig                                                                                                                  OutWork_D                                                                                                                       RealCardState                                                                                                                                                                                                                             RealStateInfo                                                                                                                   OutWork_M                                                                                                                       EmployeeAccount                                                                                                                 OverTime_Detail                                                                                                                 TimeReport2                                                                                                                     ClockDefaultParam                                                                                                               Scheme                                                                                                                          ClockParams                                                                                                                     Groups                                                                                                                          NumberPool                                                                                                                                                                                                                                DataBaseConfig                                                                                                                  DoorTimeBound                                                                                                                   user_log                                                                                                                        ZKDownHis                                                                                                                       tblAdmin                                                                                                                        TB_FREESPACE                                                                                                                    Accounts                                                                                                                        

(212 rows affected)

0