恢复SQL Server备份的数据库.bak
文件
说是任何设备的原因是docker全平台都能用
假设bak文件在/home/temp/shifenzheng.bak
,我想恢复到/home/temp/2000w/
启动一个docker-compose容器
# root @ Ubuntu in /home/sqlserver [16:08:04]
$ cat docker-compose.yml
version: '3.8'
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
container_name: sqlserver
ports:
- "1433:1433"
volumes:
- /home:/home
environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: "password"
user: "root"
进入容器
docker exec -it sqlserver bash
查看备份文件中的数据库结构
root@db8e7de4a87d:/$ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P password -Q "RESTORE FILELISTONLY FROM DISK='/home/temp/shifenzheng.bak'"
LogicalName PhysicalName Type FileGroupName Size MaxSize FileId CreateLSN DropLSN UniqueId ReadOnlyLSN ReadWriteLSN BackupSizeInBytes SourceBlockSize FileGroupId LogGroupGUID DifferentialBaseLSN DifferentialBaseGUID IsReadOnly IsPresent TDEThumbprint SnapshotUrl
-------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---- -------------------------------------------------------------------------------------------------------------------------------- -------------------- -------------------- -------------------- --------------------------- --------------------------- ------------------------------------ --------------------------- --------------------------- -------------------- --------------- ----------- ------------------------------------ --------------------------- ------------------------------------ ---------- --------- ------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
linshi D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\linshi.mdf D PRIMARY 8029601792 35184372080640 1 0 0 8FA60F72-C223-419E-A7AE-0C1B929E3A38 0 0 8029536256 512 1 NULL 0 00000000-0000-0000-0000-000000000000 0 1 NULL NULL
linshi_log D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\shifenzheng_log.LDF L NULL 516096 35184372080640 2 0 0 1A494A3D-9A1A-4757-834E-A251E9522427 0 0 0 512 0 NULL 0 00000000-0000-0000-0000-000000000000 0 1 NULL NULL
(2 rows affected)
root@db8e7de4a87d:/$
恢复
执行命令
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P password -Q "RESTORE DATABASE twentyMillion FROM DISK='/home/temp/shifenzheng.bak' WITH MOVE 'linshi' TO '/home/temp/2000w/linshi.mdf', MOVE 'linshi_log' TO '/home/temp/2000w/shifenzheng_log.LDF', REPLACE;"
root@db8e7de4a87d:/# /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P password -Q "RESTORE DATABASE twentyMillion FROM DISK='/home/temp/shifenzheng.bak' WITH MOVE 'linshi' TO '/home/temp/2000w/linshi.mdf', MOVE 'linshi_log' TO '/home/temp/2000w/shifenzheng_log.LDF', REPLACE;"
Processed 980168 pages for database 'twentyMillion', file 'linshi' on file 1.
Processed 5 pages for database 'twentyMillion', file 'linshi_log' on file 1.
Converting database 'twentyMillion' from version 661 to the current version 904.
Database 'twentyMillion' running the upgrade step from version 661 to version 668.
Database 'twentyMillion' running the upgrade step from version 668 to version 669.
Database 'twentyMillion' running the upgrade step from version 669 to version 670.
Database 'twentyMillion' running the upgrade step from version 670 to version 671.
Database 'twentyMillion' running the upgrade step from version 671 to version 672.
Database 'twentyMillion' running the upgrade step from version 672 to version 673.
Database 'twentyMillion' running the upgrade step from version 673 to version 674.
Database 'twentyMillion' running the upgrade step from version 674 to version 675.
Database 'twentyMillion' running the upgrade step from version 675 to version 676.
Database 'twentyMillion' running the upgrade step from version 676 to version 677.
Database 'twentyMillion' running the upgrade step from version 677 to version 679.
Database 'twentyMillion' running the upgrade step from version 679 to version 680.
Database 'twentyMillion' running the upgrade step from version 680 to version 681.
Database 'twentyMillion' running the upgrade step from version 681 to version 682.
Database 'twentyMillion' running the upgrade step from version 682 to version 683.
Database 'twentyMillion' running the upgrade step from version 683 to version 684.
Database 'twentyMillion' running the upgrade step from version 684 to version 685.
Database 'twentyMillion' running the upgrade step from version 685 to version 686.
Database 'twentyMillion' running the upgrade step from version 686 to version 687.
Database 'twentyMillion' running the upgrade step from version 687 to version 688.
Database 'twentyMillion' running the upgrade step from version 688 to version 689.
Database 'twentyMillion' running the upgrade step from version 689 to version 690.
Database 'twentyMillion' running the upgrade step from version 690 to version 691.
Database 'twentyMillion' running the upgrade step from version 691 to version 692.
Database 'twentyMillion' running the upgrade step from version 692 to version 693.
Database 'twentyMillion' running the upgrade step from version 693 to version 694.
Database 'twentyMillion' running the upgrade step from version 694 to version 695.
Database 'twentyMillion' running the upgrade step from version 695 to version 696.
Database 'twentyMillion' running the upgrade step from version 696 to version 697.
Database 'twentyMillion' running the upgrade step from version 697 to version 698.
Database 'twentyMillion' running the upgrade step from version 698 to version 699.
Database 'twentyMillion' running the upgrade step from version 699 to version 700.
Database 'twentyMillion' running the upgrade step from version 700 to version 701.
Database 'twentyMillion' running the upgrade step from version 701 to version 702.
Database 'twentyMillion' running the upgrade step from version 702 to version 703.
Database 'twentyMillion' running the upgrade step from version 703 to version 704.
Database 'twentyMillion' running the upgrade step from version 704 to version 705.
Database 'twentyMillion' running the upgrade step from version 705 to version 706.
Database 'twentyMillion' running the upgrade step from version 706 to version 770.
Database 'twentyMillion' running the upgrade step from version 770 to version 771.
Database 'twentyMillion' running the upgrade step from version 771 to version 772.
Database 'twentyMillion' running the upgrade step from version 772 to version 773.
Database 'twentyMillion' running the upgrade step from version 773 to version 774.
Database 'twentyMillion' running the upgrade step from version 774 to version 775.
Database 'twentyMillion' running the upgrade step from version 775 to version 776.
Database 'twentyMillion' running the upgrade step from version 776 to version 777.
Database 'twentyMillion' running the upgrade step from version 777 to version 778.
Database 'twentyMillion' running the upgrade step from version 778 to version 779.
Database 'twentyMillion' running the upgrade step from version 779 to version 780.
Database 'twentyMillion' running the upgrade step from version 780 to version 781.
Database 'twentyMillion' running the upgrade step from version 781 to version 782.
Database 'twentyMillion' running the upgrade step from version 782 to version 801.
Database 'twentyMillion' running the upgrade step from version 801 to version 802.
Database 'twentyMillion' running the upgrade step from version 802 to version 803.
Database 'twentyMillion' running the upgrade step from version 803 to version 804.
Database 'twentyMillion' running the upgrade step from version 804 to version 805.
Database 'twentyMillion' running the upgrade step from version 805 to version 806.
Database 'twentyMillion' running the upgrade step from version 806 to version 807.
Database 'twentyMillion' running the upgrade step from version 807 to version 808.
Database 'twentyMillion' running the upgrade step from version 808 to version 809.
Database 'twentyMillion' running the upgrade step from version 809 to version 810.
Database 'twentyMillion' running the upgrade step from version 810 to version 811.
Database 'twentyMillion' running the upgrade step from version 811 to version 812.
Database 'twentyMillion' running the upgrade step from version 812 to version 813.
Database 'twentyMillion' running the upgrade step from version 813 to version 814.
Database 'twentyMillion' running the upgrade step from version 814 to version 815.
Database 'twentyMillion' running the upgrade step from version 815 to version 816.
Database 'twentyMillion' running the upgrade step from version 816 to version 817.
Database 'twentyMillion' running the upgrade step from version 817 to version 818.
Database 'twentyMillion' running the upgrade step from version 818 to version 819.
Database 'twentyMillion' running the upgrade step from version 819 to version 820.
Database 'twentyMillion' running the upgrade step from version 820 to version 821.
Database 'twentyMillion' running the upgrade step from version 821 to version 822.
Database 'twentyMillion' running the upgrade step from version 822 to version 823.
Database 'twentyMillion' running the upgrade step from version 823 to version 824.
Database 'twentyMillion' running the upgrade step from version 824 to version 825.
Database 'twentyMillion' running the upgrade step from version 825 to version 826.
Database 'twentyMillion' running the upgrade step from version 826 to version 827.
Database 'twentyMillion' running the upgrade step from version 827 to version 828.
Database 'twentyMillion' running the upgrade step from version 828 to version 829.
Database 'twentyMillion' running the upgrade step from version 829 to version 830.
Database 'twentyMillion' running the upgrade step from version 830 to version 831.
Database 'twentyMillion' running the upgrade step from version 831 to version 832.
Database 'twentyMillion' running the upgrade step from version 832 to version 833.
Database 'twentyMillion' running the upgrade step from version 833 to version 834.
Database 'twentyMillion' running the upgrade step from version 834 to version 835.
Database 'twentyMillion' running the upgrade step from version 835 to version 836.
Database 'twentyMillion' running the upgrade step from version 836 to version 837.
Database 'twentyMillion' running the upgrade step from version 837 to version 838.
Database 'twentyMillion' running the upgrade step from version 838 to version 839.
Database 'twentyMillion' running the upgrade step from version 839 to version 840.
Database 'twentyMillion' running the upgrade step from version 840 to version 841.
Database 'twentyMillion' running the upgrade step from version 841 to version 842.
Database 'twentyMillion' running the upgrade step from version 842 to version 843.
Database 'twentyMillion' running the upgrade step from version 843 to version 844.
Database 'twentyMillion' running the upgrade step from version 844 to version 845.
Database 'twentyMillion' running the upgrade step from version 845 to version 846.
Database 'twentyMillion' running the upgrade step from version 846 to version 847.
Database 'twentyMillion' running the upgrade step from version 847 to version 848.
Database 'twentyMillion' running the upgrade step from version 848 to version 849.
Database 'twentyMillion' running the upgrade step from version 849 to version 850.
Database 'twentyMillion' running the upgrade step from version 850 to version 851.
Database 'twentyMillion' running the upgrade step from version 851 to version 852.
Database 'twentyMillion' running the upgrade step from version 852 to version 853.
Database 'twentyMillion' running the upgrade step from version 853 to version 854.
Database 'twentyMillion' running the upgrade step from version 854 to version 855.
Database 'twentyMillion' running the upgrade step from version 855 to version 856.
Database 'twentyMillion' running the upgrade step from version 856 to version 857.
Database 'twentyMillion' running the upgrade step from version 857 to version 858.
Database 'twentyMillion' running the upgrade step from version 858 to version 859.
Database 'twentyMillion' running the upgrade step from version 859 to version 860.
Database 'twentyMillion' running the upgrade step from version 860 to version 861.
Database 'twentyMillion' running the upgrade step from version 861 to version 862.
Database 'twentyMillion' running the upgrade step from version 862 to version 863.
Database 'twentyMillion' running the upgrade step from version 863 to version 864.
Database 'twentyMillion' running the upgrade step from version 864 to version 865.
Database 'twentyMillion' running the upgrade step from version 865 to version 866.
Database 'twentyMillion' running the upgrade step from version 866 to version 867.
Database 'twentyMillion' running the upgrade step from version 867 to version 868.
Database 'twentyMillion' running the upgrade step from version 868 to version 869.
Database 'twentyMillion' running the upgrade step from version 869 to version 875.
Database 'twentyMillion' running the upgrade step from version 875 to version 876.
Database 'twentyMillion' running the upgrade step from version 876 to version 877.
Database 'twentyMillion' running the upgrade step from version 877 to version 878.
Database 'twentyMillion' running the upgrade step from version 878 to version 879.
Database 'twentyMillion' running the upgrade step from version 879 to version 880.
Database 'twentyMillion' running the upgrade step from version 880 to version 881.
Database 'twentyMillion' running the upgrade step from version 881 to version 882.
Database 'twentyMillion' running the upgrade step from version 882 to version 883.
Database 'twentyMillion' running the upgrade step from version 883 to version 884.
Database 'twentyMillion' running the upgrade step from version 884 to version 885.
Database 'twentyMillion' running the upgrade step from version 885 to version 886.
Database 'twentyMillion' running the upgrade step from version 886 to version 887.
Database 'twentyMillion' running the upgrade step from version 887 to version 888.
Database 'twentyMillion' running the upgrade step from version 888 to version 889.
Database 'twentyMillion' running the upgrade step from version 889 to version 890.
Database 'twentyMillion' running the upgrade step from version 890 to version 891.
Database 'twentyMillion' running the upgrade step from version 891 to version 892.
Database 'twentyMillion' running the upgrade step from version 892 to version 893.
Database 'twentyMillion' running the upgrade step from version 893 to version 894.
Database 'twentyMillion' running the upgrade step from version 894 to version 895.
Database 'twentyMillion' running the upgrade step from version 895 to version 896.
Database 'twentyMillion' running the upgrade step from version 896 to version 897.
Database 'twentyMillion' running the upgrade step from version 897 to version 898.
Database 'twentyMillion' running the upgrade step from version 898 to version 899.
Database 'twentyMillion' running the upgrade step from version 899 to version 900.
Database 'twentyMillion' running the upgrade step from version 900 to version 901.
Database 'twentyMillion' running the upgrade step from version 901 to version 902.
Database 'twentyMillion' running the upgrade step from version 902 to version 903.
Database 'twentyMillion' running the upgrade step from version 903 to version 904.
RESTORE DATABASE successfully processed 980173 pages in 53.944 seconds (141.954 MB/sec).
恢复成功
使用Navicat Premium
登录查看即可
我一般用的是mysql,所以最后还需要用Navicat Premium
连接SQL Server再将数据导入到mysql,然后删除刚才创建的容器和写入的数据即可