技术的坑分享记录

参考:https://blog.csdn.net/gzt19881123/article/details/107858206

docker run --name mssql4 \

-e 'ACCEPT_EULA=Y' \

-e 'MSSQL_PID=HMWJ3-KY3J2-NMVD7-KG4JR-X2G8G' \

-e 'SA_PASSWORD=AsABU962390%XxH5' \

-v /dx/m20201111/:/var/opt/mssql \

-p 1433:24339 \

-d mcr.microsoft.com/mssql/server:2019-latest

docker ps

获取正在运行的数据库ID

进入容器;

docker exec -it -u root /bin/bash   容器ID

获取备份文件的逻辑名

/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'AsABU962390%XxH5' -Q 'RESTORE FILELISTONLY FROM DISK = "/dx/m20201111/data/DevOpsDB/wms20201123"' | tr -s ' ' | cut -d ' ' -f 1-2

/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'AsABU962390%XxH5' -Q 'RESTORE FILELISTONLY FROM DISK = "*"' | tr -s ' ' | cut -d ' ' -f 1-2

/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P '数据库的SA密码' -Q 'RESTORE FILELISTONLY FROM DISK = "bak文件所在路径(/dx/...."' | tr -s ' ' | cut -d ' ' -f 1-2

使用RESTORE DATABASE命令还原数据库

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '数据库的SA密码' -Q '  RESTORE DATABASE 数据库逻辑名 FROM DISK = "备份文件路径" WITH MOVE "创建的新的数据库名"  TO      "/var/opt/mssql/data/DevOpsDB/新的mdf文件路径.mdf"   ,  MOVE "数据库log文件逻辑名字" TO "/var/opt/mssql/data/DevOpsDB/新的数据库log文件路径.ldf"'

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'AsABU962390%XxH5' -Q '  RESTORE DATABASE LXLCrmDB FROM DISK = "/11-7" WITH MOVE "CRM_44_DEV_001"  TO      "/var/opt/mssql/data/DevOpsDB/CRM_44_DEV_001.mdf"   ,  MOVE "LXLCrmDB_log" TO "/var/opt/mssql/data/DevOpsDB/CRM_44_DEV_001_LOG.ldf"'

/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'AsABU962390%XxH5' -Q 'RESTORE FILELISTONLY FROM DISK = "/var/opt/mssql/data/DevOpsDB/LXLOADB.bak"' | tr -s ' ' | cut -d ' ' -f 1-2

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'AsABU962390%XxH5' -Q 'RESTORE DATABASE  LXLOADB FROM DISK = "/var/opt/mssql/data/DevOpsDB/LXLOADB.bak" WITH MOVE "LXLOADB" TO "/var/opt/mssql/data/DevOpsDB/OA_44_DEV_001.mdf" , MOVE "LXLOADB_log" TO "/var/opt/mssql/data/DevOpsDB/OA_44_DEV_001_LOG.ldf"'

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 'AsABU962390%XxH5' -Q '  RESTORE DATABASE LXLOADB FROM DISK = "/var/opt/mssql/data/DevOpsDB/LXLOADB.bak" WITH MOVE "OA_44_DEV_001"  TO      "/var/opt/mssql/data/DevOpsDB/OA_44_DEV_001.mdf"   ,  MOVE "LXLOADB_log" TO "/var/opt/mssql/data/DevOpsDB/OA_44_DEV_001_LOG.ldf"'


上下篇:

相关推荐