容器sqlserver导出导入数据

#安装mssql-tools
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/msprod.repo
yum install -y mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
BAN=_v1.0
BML=/opt/test$BAN

#备份mmsql 测试 最好免密数据库端 ssh-keygen -N ""        && ssh-copy-id $IP
sqlcmd -S 10.0.43.28 -U SA -P123456 -Q "backup database TEST to disk='/usr/local/databackup/TEST.bak'"
ssh  10.0.43.28 "docker cp sqlserver:/usr/local/databackup/TEST.bak /opt"
scp 10.0.43.28:/opt/TEST.bak $BML/sql/

#恢复sql   测试 最好免密数据库端 ssh-keygen -N ""        && ssh-copy-id $IP
scp $BML/sql/TEST.bak 10.0.43.39:/root
ssh  10.0.43.39 "docker cp /root/TEST.bak sqlserver:/TEST.bak"
#sqlcmd -S 10.0.43.39 -U SA -P123456 -Q "RESTORE FILELISTONLY FROM DISK = '/TEST.bak'"
sqlcmd -S 10.0.43.39 -U SA -P123456 -Q "RESTORE DATABASE TEST FROM DISK = '/TEST.bak' WITH MOVE 'TEST' TO '/TEST.mdf', MOVE 'TEST_log' TO '/TEST.ldf'"  

参考博客

Linux下SqlServer的备份和还原:https://blog.csdn.net/zhang41228/article/details/79893230

posted @ 2020-09-28 15:42  鸣昊  阅读(251)  评论(0编辑  收藏  举报