Wiki source code of migrate to managed instance

Version 8.10 by Rudi Marais on 2024/03/07 14:42

Show last authors
1 * compressed file
2 * contains ddl and dml data
3 * doesnt support encrypted objects
4 * cant have any stored procs with string that contain $( character sequence reserved sequence
5 ** break up sequence ie 'test$(test' become 'test$' + '(test'
6 * [[https:~~/~~/learn.microsoft.com/en-us/azure/azure-sql/database/database-import>>https://learn.microsoft.com/en-us/azure/azure-sql/database/database-import]]
7 * sqlpackage
8 ** [[https:~~/~~/download.microsoft.com/download/7/c/8/7c877288-a0d9-4d22-b1dc-2086e262d82f/x64/DacFramework.msi>>https://download.microsoft.com/download/7/c/8/7c877288-a0d9-4d22-b1dc-2086e262d82f/x64/DacFramework.msi]]
9 ** [[https:~~/~~/learn.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage-download>>https://learn.microsoft.com/en-us/sql/tools/sqlpackage/sqlpackage-download]]
10 ** C:\Program Files\Microsoft SQL Server\160\DAC\bin
11 * turn off real time scan (anti virus)
12
13 1. run extract with [[sql-script-db.ps1>>doc:technical-documentation.Source Control.migration.sql.sql-db-export.WebHome]] with validate set to true and raw objects set to true, only need tbl-triggers, functions and sp
14 11. reason for this is to identify any procedure/triggers/functions that dont compile
15 1. once this is done examine results and fix stored procedures on database so that they can compile, ie add missing columns or modify code to not require them
16 11. repeat step 1 and 2 until you get zero objects that can't compile
17 1. check sql code for any reserved varables ie... and fix on DB
18 1. run dacpac export
19 11. make sure nothing is running on source DB
20 11. upgrade source DB to high level for quicker export and set back to what it was once done
21 11. cmd
22 1. run dacpac publish to managed instance
23 1.
24
25 * (((
26 (% class="wikigeneratedid" id="Hhttps:2F2Fgithub.com2Fmicrosoft2Fmssql-scripter" %)
27 [[https:~~/~~/github.com/microsoft/mssql-scripter>>https://github.com/microsoft/mssql-scripter]]
28
29 * C:\Users\alliancetest\.mssqlscripter
30 * mssql-scripter -S "kula.database.windows.net" -d Everest_Test -U ebsadmin -P xxx -r -f E:\temp\khula_test.sql ~-~-display-progress ~-~-enable-toolsservice-logging
31 )))
32
33 (% class="wikigeneratedid" id="H" %)
34 {{code language="sql"}}-- index
35 select concat('echo ''',SCHEMA_NAME(schema_id), '_', BASE64_ENCODE (cast(name as varbinary)), '.bcp ',SCHEMA_NAME(schema_id), '.', name , ''' >> test.log')
36 from sys.tables
37 where type = 'U'
38 and is_ms_shipped = 0
39
40 --and temporal_type in (0,2);
41
42 -- export
43
44 select '$path = "E:\temp\test"'
45 select '$server = "server.name"'
46 select '$username = "user.name"'
47 select '$password = "pass.word"'
48 select 'New-Item -ItemType Directory -Force -Path "$path\export_log"'
49 select 'New-Item -ItemType Directory -Force -Path "$path\data"'
50
51 select export = concat('bcp "', DB_NAME(), '.',
52 SCHEMA_NAME(schema_id), '.', replace(name,'$','`$'),
53 '" out "$path\data\', SCHEMA_NAME(schema_id), '_', BASE64_ENCODE (cast(name as varbinary)), '.bcp" ',
54 ' -e "$path\export_log\', SCHEMA_NAME(schema_id), '_', BASE64_ENCODE (cast(name as varbinary)), '.log" ',
55 ' -S "', '$server','"',
56 ' -N -U "$username" -P "$password"',
57 ' | Out-Null')
58 from sys.tables
59 where type = 'U'
60 and is_ms_shipped = 0
61 --and temporal_type in (0,2);
62
63 -- import
64
65
66 select '$path = "E:\temp\test"'
67 select '$target_server = "server.name"'
68 select '$target_username = "user.name"'
69 select '$target_password = "pass.word"'
70 select 'New-Item -ItemType Directory -Force -Path "$path\import_log"'
71 select 'New-Item -ItemType Directory -Force -Path "$path\data"'
72
73 select import = concat('bcp "', '$target_db', '.',
74 SCHEMA_NAME(schema_id), '.', replace(name,'$','`$'),
75 '" in "$path\data\', SCHEMA_NAME(schema_id), '_', BASE64_ENCODE (cast(name as varbinary)) , '.bcp" ',
76 ' -e "$path\import_log\', SCHEMA_NAME(schema_id), '_', BASE64_ENCODE (cast(name as varbinary)) , '.log" ',
77 ' -S "', '$target_server','"',
78 ' -N -U "$target_username" -P "$target_password"',
79 ' -b 1000 -E -k -N -q',
80 ' | Out-Null')
81 from sys.tables
82 where type = 'U'
83 and is_ms_shipped = 0
84 --and temporal_type in (0,2);
85 {{/code}}
86
87
88 * disable anti-virus real time scan
89
90 (% class="wikigeneratedid" %)
91 placeholder
92
93 = Exporting =
94
95 * no encrypted objects, they need to be decrypted or removed prior to exporting.
96
97 SQL 2012
98
99
100
101 EXEC sp_configure 'show advanced options', 1;
102 GO
103 RECONFIGURE;
104 GO
105
106 EXEC sp_configure 'xp_cmdshell',1
107 GO
108 RECONFIGURE
109 GO
110
111
112 EXEC XP_CMDSHELL 'net use O: ~\~\zagpebslab.file.core.windows.net\sqlshare /user:"localhost\zagpebslab" "access_key"'
113
114 EXEC XP_CMDSHELL 'Dir O:'
115
116
117 BACKUP DATABASE Everest_TEST
118 TO DISK = N'O:\ENS_Everest_Test_20230721_1806.bak'
119 WITH COMPRESSION,
120 STATS = 10;
121
122
123 GO
124
125
126 SELECT 
127 session_id as SPID, command, a.text AS Query, start_time, percent_complete,
128 dateadd(second,estimated_completion_time/1000, getdate()) as estimated_completion_time
129 FROM sys.dm_exec_requests r 
130 CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) a 
131 WHERE r.command in ('BACKUP DATABASE','RESTORE DATABASE')
132
133 GO
134
135
136 = Importing =
137
138
139 = Modifying and Troubleshooting =
140
141 * Get-FileHash 'C:\temp\lfs\LifeSense_Everest_Test2-2023-5-17-7-37\model.xml'
142 ** place in Origin.xml
143 *** <Checksum Uri="/model.xml">DEADD2734B789135ED627061A385FC2C1096718A7D3398658DF9097196C1F571</Checksum>
144
145 == Recalculate Signature ==
146
147 * incubator/ebsphere.crm/ebs-devops-devops-sql/calc-signature-bacpac.ps1
148 * modify Origin.xml
149 ** Checksum attribute for model.xml