Professional Documents
Culture Documents
Jay Liu
E: LJJYX@yahoo.com C: 647-833-5887
1
2.4b.1. Server-level preparation from SQL2016PRD
1. Script out the server configuration
2. Script out logins with password
3. Script out role_member, server-level permission
4. Script out job
5. Backup userDB
2
2.4b.1.1 Script out the server configuration
- Open script [2.4b 1.ExportServerConfigurations.sql]
- Run it in PROD-PP-1216\SQL2016PRD instance
3
2.4b.1.1 Script out the server configuration
- Export all the configuration scripting
- Copy and paste the result as below for [2.4b 1.
ExportServerConfigurations.sql] into notepad
- Save as [2.4b OUTPUT_1.ExportServerConfigurations.sql]
4
2.4b.1.2 Script out the server configuration
- Open script [2.4b 2. ExportLoginsWithPassword.sql]
- Run it in PROD-PP-1216\SQL2016PRD instance
5
2.4b.1.2 Script out logins with password
- Export all create logins with password scripting
- Copy and paste the result below for [2.4b 2.
ExportLoginsWithPassword.sql] into notepad
- Save as [2.4b OUTPUT_2. ExportLoginsWithPassword.sql]
/* Script out the server logins with password, [usp_help_revlogin] script
** Generated May 23 2020 11:26PM on PROD-PP-1216\SQL2016PRD */
USE master
GO
BEGIN TRY
CREATE LOGIN [SQL2K8\SQLDBAGRP] FROM WINDOWS WITH DEFAULT_DATABASE = [master]
END TRY
BEGIN CATCH
PRINT 'The server login: [SQL2K8\SQLDBAGRP] already exists.'
END CATCH
BEGIN TRY
CREATE LOGIN [SQL2K8\SQLSRVGRP] FROM WINDOWS WITH DEFAULT_DATABASE = [master]
END TRY
BEGIN CATCH
PRINT 'The server login: [SQL2K8\SQLSRVGRP] already exists.'
END CATCH
6
2.4b.1.2 Script out logins with password
(Continued 1)
BEGIN TRY
CREATE LOGIN [SQL2K8\SQLService] FROM WINDOWS WITH DEFAULT_DATABASE = [master]
END TRY
BEGIN CATCH
PRINT 'The server login: [SQL2K8\SQLService] already exists.'
END CATCH
BEGIN TRY
CREATE LOGIN [SQL2K8\SQLDBA1] FROM WINDOWS WITH DEFAULT_DATABASE = [master]; REVOKE
CONNECT SQL TO [SQL2K8\SQLDBA1]
END TRY
BEGIN CATCH
PRINT 'The server login: [SQL2K8\SQLDBA1] already exists.'
END CATCH
BEGIN TRY
CREATE LOGIN [login1] WITH PASSWORD =
0x0200A8A0AC30ACCBA3945907F0D3D07F5E6791AB1C104FC77A481DD605AB00DE78C755B285249F9D80FF63EEF
B5159A835D432114A3BC0ED56386FEDEBDD5CB79A02642591D4 HASHED, SID =
0x1A5E34A41F335A4ABC51DD8A0EC9C919, DEFAULT_DATABASE = [master], CHECK_POLICY = OFF,
CHECK_EXPIRATION = OFF
END TRY
BEGIN CATCH
PRINT 'The server login: [login1] already exists.'
END CATCH
7
2.4b.1.2 Script out logins with password
(Continued 2)
BEGIN TRY
CREATE LOGIN [login2] WITH PASSWORD =
0x020092C38E466546D81B313FB848A6F940A2BD67C886DD0108E999A3FF3971F6308783DC3DCB5889EF3079B2D3F0
61515FD2BBF18C0893942671A72B71356171B39498F47433 HASHED, SID = 0x5F5F256B63F28140B9B92DDF05C42666,
DEFAULT_DATABASE = [master], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF
END TRY
BEGIN CATCH
PRINT 'The server login: [login2] already exists.'
END CATCH
BEGIN TRY
CREATE LOGIN [login3] WITH PASSWORD =
0x0200B27B751DB6BAF2839F657085731C3E3AAB42C138C433C68D11D97757BCB47554659AE4B75D3F0CF234EAE4D
F984F45293CCA5F7CAE5F60F0947283DFBDFDC9A55CF5BB88 HASHED, SID =
0xCCDBB2D942BFA340953001CCC9A0EC46, DEFAULT_DATABASE = [master], CHECK_POLICY = OFF,
CHECK_EXPIRATION = OFF
END TRY
BEGIN CATCH
PRINT 'The server login: [login3] already exists.'
END CATCH
8
2.4b.1.2 Script out logins with password
(Continued 3)
BEGIN TRY
CREATE LOGIN [data_reader] WITH PASSWORD =
0x02003BCB83BCF8A00E65E95E52614F39CECA1A443A45B7B8A00C91EFCE52F4D69BF7C036D3BF639A3BE8186F3B
320F96A44661654DB5D549A6D46BA29133FED7F0F13EC368C4 HASHED, SID =
0x3E339D5CBF761E49A9DEF0030B1EF9AC, DEFAULT_DATABASE = [master], CHECK_POLICY = OFF,
CHECK_EXPIRATION = OFF
END TRY
BEGIN CATCH
PRINT 'The server login: [data_reader] already exists.'
END CATCH
9
2.4b.1.3 Script out role_member, server-level permission
- Open script [2.4b 3. ExportServerLevelPermission.sql]
- Run it in PROD-PP-1216\SQL2016PRD instance
10
2.4b.1.3 Script out role_member, server-level permission
- Export all server level role member
- Copy and paste the result below for [2.4b 3.
ExportServerLevelPermission.sql] into notepad
- Save as [2.4b OUTPUT_3. ExportServerLevelPermission.sql]
/* script out the server role members
** Generated May 24 2020 1:24AM on PROD-PP-1216\SQL2016PRD */
USE MASTER
GO
11
2.4b.1.4 Script out job
- Open script [2.4b 4. CreateJobSampleScripting.sql]
- Run it in PROD-PP-1216\SQL2016PRD instance to create sample job:
[job_insert_tblJobExample]
- Attached a schedule to this job to kick off the job in every 30 second
12
2.4b.1.4 Script out job
- This job is to insert timestamp into table [tblJobSample] in DB [Testing]
- It also call the stored procedure [usp_insert_tblJobExample]
13
2.4b.1.4 Script out job
- Check steps inside job
- Right click job [job_insert_tblJobExample]
- Properties > Steps > [step_insert_tblJobExample]
14
2.4b.1.4 Script out job
- Check schedule inside job
- Right click job [job_insert_tblJobExample]
- Properties > Schedules > [schedule_insert_tblJobExample]
15
2.4b.1.4 Script out job
- Steps to script out job
- In SSMS, press F7 to launch [Object Explorer Details]
- select the job [job_insert_tblJobExample], right click >
Script Job as > Create To > New Query Editor Window
16
2.4b.1.4 Script out job
- Script result into a text file:
[2.4b OUTPUT_4. CreateJobSampleScripting.txt]
17
2.4b.1.5 Backup user DB from SQL2016PRD
- Open script [2.4b 5. Backup All UserDBs.sql]
- Run it to backup all user databases in SQL2016PRD
- The script will change the user DB’s logical name to [Data] and [Log]
18
2.4b.1.5 Backup user DB from SQL2016PRD
- The script will backup the user DB into path: C:\PROD\Backup in the
old server PROD-PP-1216
- Need to copy and paste all the .bak file into new server PROD-PP-1216,
under the path: C:\SQL2017PRD\Backup, for restore in SQL2017PRD
19
2.4b.2 Standing up SQL2017PRD
- Run all the scripting we save in the OUTPUT files to restore the
configuration, server logins and server-level permission
- We will also use the scripting to restore all the user DBs under the path:
C:\SQL2017PRD\Backup in SQL2017PRD
20
2.4b.2.1 Restore the server configuration
- Connect to server: PROD-PP-1216\SQL2017PRD
- Open scripting [2.4b OUTPUT_1.ExportServerConfigurations.sql]
21
2.4b.2.1 Restore the server configuration
- Run scripting [2.4b OUTPUT_1.ExportServerConfigurations.sql]
- See the result
22
2.4b.2.1 Restore the server configuration
- Right-click server SQL2017PRD Facets Server Configuration
- Check if the setting meet your requirements.
- Example: the scripting turn on ‘xp_cmdshell’, 1
When we check facets > XPCmdShellEnabled = True
23
2.4b.2.2 Restore logins with password
- Connect to server: PROD-PP-1216\SQL2017PRD
- Open scripting [2.4b OUTPUT_2. ExportLoginsWithPassword.sql]
24
2.4b.2.2 Restore logins with password
- Run scripting [2.4b OUTPUT_2. ExportLoginsWithPassword.sql]
- The scripting will create logins, if the logins already existing, will show
the message as below.
25
2.4b.2.2 Restore logins with password
- Refresh server SQL2017PRD Security Logins
- Check all the logins are imported from SQL2016PRD
26
2.4b.2.3 Restore role_member, server-level permission
- Connect to server: PROD-PP-1216\SQL2017PRD
- Open scripting [2.4b OUTPUT_3. ExportServerLevelPermission.sql]
27
2.4b.2.3 Restore role_member, server-level permission
- Run scripting [2.4b OUTPUT_3. ExportServerLevelPermission.sql]
- See the result
28
2.4b.2.3 Restore role_member, server-level permission
- Go to Security > Server Roles > sysadmin > right click > Properties
- Go to Security > Server Roles > processadmin > right click > Properties
- Check the members for each role
29
2.4b.2.4 Restore user DB to SQL2017PRD
- Open script [2.4b 6. Restore All UserDBs.sql]
- It will create Restore database command for each user DB
30
2.4b.2.4 Restore user DB to SQL2017PRD
- Open script [2.4b 6. Restore All UserDBs.sql]
- It locates all .bak files in the path: C:\SQL2017PRD\Backup
31
2.4b.2.4 Restore user DB to SQL2017PRD
- Run the script, all user DBs will be restored
- They can be shown in the [Object Exploer]
32
2.4b.2.5 Compatibility level, DB owner, recovery mode and growth
mode
- For restored DBs, we need to fix the compatibility level to make them
compatible to SQL Server 2017 (140)
- We also need to change the DB owner as ‘sa’
33
2.4b.2.5 Compatibility level, DB owner, recovery mode and growth
mode
- Open script [2.4b 7. Compatibilty, ChangeDBOwner, RecoveryMode,
GrowthMode.sql]
- Run step 1 to change the compatibility level
34
2.4b.2.5 Compatibility level, DB owner, recovery mode and growth
mode
- Open script [2.4b 7. Compatibilty, ChangeDBOwner, RecoveryMode,
GrowthMode.sql]
- Run step 2 to change the DB owner to ‘sa’
35
2.4b.2.5 Compatibility level, DB owner, recovery mode and growth
mode
- Verify the compatibility level and DB owner as below
36
2.4b.2.5 Compatibility level, DB owner, recovery mode and growth
mode
- There is no need to run Step 3 since all user DBs are in Full recovery mode
- Run Step 4 to change the all user DBs growth mode to filegrowth = 50MB,
maxsize = unlimited
37
2.4b.2.5 Compatibility level, DB owner, recovery mode and growth
mode
- To verify [filegrowth] and [maxsize], take [AdventureWorks] as example
- Go to [AdventureWorks] > properties > File (on the left side pane)
38
2.4b.2.6 Restore job in SQL2017PRD
- In SQL2017PRD, database [Testing], check table and stored procedure
- Check Tables > [dbo.tblJobExample]
- Check Programmability > Stored Procedures >
[dbo.usp_insert_tblJobExample]
39
2.4b.2.6 Restore job in SQL2017PRD
- Go to [Sql Sever Configuration Manager]
- Turn on the SQL Server Agent (SQL2017PRD)
40
2.4b.2.6 Restore job in SQL2017PRD
- Open script [2.4b OUTPUT_4. CreateJobSampleScripting.sql]
- Run the script to restore the job [job_insert_tblJobExample]
41
2.4b.2.6 Restore job in SQL2017PRD
- The [job_insert_tblJobExample] will be showing under [SQL Server Agent]
42
2.4b.2.6 Restore job in SQL2017PRD
- Open SQL Sever Agent > Jobs > [job_insert_tblJobExample]
- Check the [Step] and [Schedule]
43
2.4b.2.6 Restore job in SQL2017PRD
- Open table [tblJobExample] in database [Testing]
- Check the table result created by the job
44
Q&A
45