sql_cmd 0.3.1 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/optional_dependencies.rb +3 -13
- data/lib/sql_cmd/always_on.rb +5 -3
- data/lib/sql_cmd/database.rb +18 -4
- data/lib/sql_cmd/query.rb +1 -0
- data/sql_scripts/Agent/JobRunStatus.sql +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2026009b040577e9e545648215f0bed077ff75c6b901aeb0144643a07be6262e
|
4
|
+
data.tar.gz: 45656864eaae255a6eb8103605f33e2ec5fd87c3375af4e3750bd935bf32abab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05e96b27be968770e656dddcd91e56969c6a4ec71b6deb38e50b352380fe1afed015de25f10e59ba55bb8181a8b39e3bcf65008be731fadb69c22f600e93d115
|
7
|
+
data.tar.gz: 699ebf6a150ff70284d6c3a81ccf2538d7f0965143d8efa253ed6925082ca9032da4e4b9e2c1679f19e2eed3029a7179cdd380a61eb10b8f4bef5e45d4eff3eb
|
@@ -3,18 +3,8 @@ module OptionalDepedencies
|
|
3
3
|
|
4
4
|
def load_azure_blob_storage_dependencies
|
5
5
|
azure_blob_storage_dependencies = {
|
6
|
-
|
7
|
-
|
8
|
-
# 'faraday-net_http_persistent' => '1.1.0',
|
9
|
-
# 'ruby2_keywords' => '0.0.4',
|
10
|
-
# 'faraday' => '1.4.1',
|
11
|
-
# 'faraday_middleware' => '1.0.0',
|
12
|
-
# 'connection_pool' => '2.2.5'
|
13
|
-
# 'net-http-persistent' => '4.0.1',
|
14
|
-
# 'racc' => '1.5.2',
|
15
|
-
# 'nokogiri' => '1.11.4',
|
16
|
-
'azure/storage/common' => '2.0.2',
|
17
|
-
'azure/storage/blob' => '2.0.1',
|
6
|
+
'azure/storage/common' => '>= 2.0.4',
|
7
|
+
'azure/storage/blob' => '>= 2.0.3',
|
18
8
|
}
|
19
9
|
load_gem_list(azure_blob_storage_dependencies)
|
20
10
|
end
|
@@ -25,6 +15,6 @@ module OptionalDepedencies
|
|
25
15
|
require current_gem
|
26
16
|
end
|
27
17
|
rescue Gem::LoadError => e
|
28
|
-
raise Gem::LoadError, "You are using functionality requiring the optional gem dependency '#{e.name}', but the gem is not
|
18
|
+
raise Gem::LoadError, "You are using functionality requiring the optional gem dependency '#{e.name}', but the gem is not installed, or is not using a version matching '#{e.requirement}'.\n\n#{e.message}"
|
29
19
|
end
|
30
20
|
end
|
data/lib/sql_cmd/always_on.rb
CHANGED
@@ -62,8 +62,10 @@ module SqlCmd
|
|
62
62
|
EasyIO.logger.header 'AlwaysOn Permissions Migration to Replica'
|
63
63
|
EasyIO.logger.debug 'Migrating logins to replica...'
|
64
64
|
import_script_filename = SqlCmd.export_logins(start_time, primary_connection_string, database_name)
|
65
|
-
|
66
|
-
|
65
|
+
unless import_script_filename.nil?
|
66
|
+
EasyIO.logger.info "Importing logins on [#{SqlCmd.connection_string_part(replica_connection_string, :server)}]..."
|
67
|
+
SqlCmd.execute_script_file(replica_connection_string, import_script_filename)
|
68
|
+
end
|
67
69
|
EasyIO.logger.debug 'Running database_status script...'
|
68
70
|
database_info = SqlCmd::Database.info(connection_string, database_name)
|
69
71
|
replica_database_info = SqlCmd::Database.info(replica_connection_string, database_name)
|
@@ -266,7 +268,7 @@ module SqlCmd
|
|
266
268
|
|
267
269
|
def enabled?(connection_string)
|
268
270
|
server_info = SqlCmd.get_sql_server_settings(connection_string)
|
269
|
-
server_info['AvailabilityGroup'].nil?
|
271
|
+
!server_info['AvailabilityGroup'].nil? && !server_info['SecondaryReplica'].nil?
|
270
272
|
end
|
271
273
|
end
|
272
274
|
end
|
data/lib/sql_cmd/database.rb
CHANGED
@@ -137,7 +137,7 @@ module SqlCmd
|
|
137
137
|
connection_string = SqlCmd.remove_connection_string_part(connection_string, :database)
|
138
138
|
sql_server = SqlCmd.connection_string_part(connection_string, :server)
|
139
139
|
database_info = info(connection_string, database_name)
|
140
|
-
import_script_path =
|
140
|
+
import_script_path = import_security_script_path(start_time, connection_string, database_name, backup_url)
|
141
141
|
unless database_info['DatabaseNotFound']
|
142
142
|
raise "Failed to restore database: [#{database_name}] on [#{sql_server}]! Database already exists!" unless overwrite || force_restore
|
143
143
|
unless options['logonly'] || database_info['state_desc'] != 'ONLINE' || permissions == :no_permissions
|
@@ -214,6 +214,8 @@ module SqlCmd
|
|
214
214
|
raise "Insufficient free space on #{sql_server} to restore database! Must have greater than #{free_space_threshold}% space remaining after restore." if insufficient_space
|
215
215
|
end
|
216
216
|
|
217
|
+
database_backup_types = %w(1 5)
|
218
|
+
drop(connection_string, database_name) if options['drop_before_restoring'] && !database_info['DatabaseNotFound'] && database_backup_types.include?(sql_backup_header['BackupType'])
|
217
219
|
run_restore_as_job(connection_string, sql_server_settings, backup_files, database_name, options: options)
|
218
220
|
monitor_restore(minimum_restore_date, connection_string, database_name, backup_files, options) unless asynchronous
|
219
221
|
end
|
@@ -477,7 +479,7 @@ module SqlCmd
|
|
477
479
|
end
|
478
480
|
failure_message = 'Restore appears to have failed! '
|
479
481
|
failure_message += job_status == 'NoJob' ? 'The job could not be found and the restored database is not up to date!' : "The job did not start in time. Check sql job 'Restore: #{database_name}' history on [#{server_name}] for details."
|
480
|
-
raise failure_message + "
|
482
|
+
raise failure_message + "\nRestore destination: #{server_name}\\#{database_name}"
|
481
483
|
end
|
482
484
|
|
483
485
|
def check_restore_date(start_time, connection_string, database_name, messages = :none, log_only: false)
|
@@ -535,7 +537,11 @@ module SqlCmd
|
|
535
537
|
end
|
536
538
|
|
537
539
|
def apply_recovery_model(connection_string, database_name, options)
|
538
|
-
|
540
|
+
if recovery_model_set?(connection_string, database_name, options)
|
541
|
+
EasyIO.logger.info "Recovery model already set to '#{options['recovery_model']}'. No change needed."
|
542
|
+
return
|
543
|
+
end
|
544
|
+
EasyIO.logger.info "Setting recovery model to '#{options['recovery_model']}'..."
|
539
545
|
options['recovery_model'] ||= 'FULL'
|
540
546
|
options['rollback'] ||= 'ROLLBACK IMMEDIATE' # other options: ROLLBACK AFTER 30, NO_WAIT
|
541
547
|
sql_script = "ALTER DATABASE [#{database_name}] SET RECOVERY #{options['recovery_model']} WITH #{options['rollback']}"
|
@@ -547,6 +553,7 @@ module SqlCmd
|
|
547
553
|
#{'=' * 120}\n"
|
548
554
|
EOS
|
549
555
|
raise failure_message unless recovery_model_set?(connection_string, database_name, options)
|
556
|
+
EasyIO.logger.info "Recovery model updated to '#{options['recovery_model']}'."
|
550
557
|
end
|
551
558
|
|
552
559
|
def recovery_model_set?(connection_string, database_name, options)
|
@@ -555,12 +562,19 @@ module SqlCmd
|
|
555
562
|
SqlCmd.execute_query(connection_string, sql_script, return_type: :scalar, readonly: true) || false
|
556
563
|
end
|
557
564
|
|
558
|
-
def
|
565
|
+
def import_security_script_path(start_time, connection_string, database_name, storage_url = nil)
|
559
566
|
start_time = SqlCmd.unify_start_time(start_time)
|
560
567
|
server_name = SqlCmd.connection_string_part(connection_string, :server)
|
561
568
|
export_folder = "#{SqlCmd.config['paths']['cache']}/sql_cmd/logins"
|
562
569
|
basename_prefix = storage_url.nil? ? "#{EasyFormat::File.windows_friendly_name(server_name)}_" : ''
|
563
570
|
import_script_path = "#{export_folder}/#{basename_prefix}#{database_name}_database_permissions_#{EasyTime.yyyymmdd(start_time)}.sql"
|
571
|
+
end
|
572
|
+
|
573
|
+
def export_security(start_time, connection_string, database_name, storage_url = nil, options = {})
|
574
|
+
start_time = SqlCmd.unify_start_time(start_time)
|
575
|
+
server_name = SqlCmd.connection_string_part(connection_string, :server)
|
576
|
+
export_folder = "#{SqlCmd.config['paths']['cache']}/sql_cmd/logins"
|
577
|
+
import_script_path = import_security_script_path(start_time, connection_string, database_name, storage_url)
|
564
578
|
if ::File.exist?(import_script_path) && ::File.mtime(import_script_path) > start_time
|
565
579
|
content = ::File.read(import_script_path)
|
566
580
|
SqlCmd::Azure::AttachedStorage.upload(::File.basename(import_script_path), content, options['storage_account_name'], options['storage_access_key'], storage_url: storage_url) unless storage_url.nil?
|
data/lib/sql_cmd/query.rb
CHANGED
@@ -245,6 +245,7 @@ module SqlCmd
|
|
245
245
|
def migrate_logins(start_time, source_connection_string, destination_connection_string, database_name)
|
246
246
|
start_time = SqlCmd.unify_start_time(start_time)
|
247
247
|
import_script_filename = export_logins(start_time, source_connection_string, database_name)
|
248
|
+
return if import_script_filename.nil?
|
248
249
|
if ::File.exist?(import_script_filename)
|
249
250
|
EasyIO.logger.info "Importing logins on [#{connection_string_part(destination_connection_string, :server)}]..."
|
250
251
|
execute_script_file(destination_connection_string, import_script_filename)
|
@@ -6,7 +6,7 @@ SELECT
|
|
6
6
|
j.name AS job_name,
|
7
7
|
ja.start_execution_date,
|
8
8
|
ISNULL(last_executed_step_id,0)+1 AS current_executed_step_id,
|
9
|
-
|
9
|
+
js.step_name
|
10
10
|
FROM msdb.dbo.sysjobactivity ja
|
11
11
|
LEFT JOIN msdb.dbo.sysjobhistory jh
|
12
12
|
ON ja.job_history_id = jh.instance_id
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_cmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Munoz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: easy_json_config
|