Skip to content

Commit

Permalink
Remove EvmDatabaseOps and related rake tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
NickLaMuro committed Aug 4, 2021
1 parent c3bd4a0 commit ef83ee7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 670 deletions.
243 changes: 0 additions & 243 deletions lib/evm_database_ops.rb

This file was deleted.

113 changes: 28 additions & 85 deletions lib/tasks/evm_dba.rake
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,34 @@ namespace :evm do
opt :table, "Tablename to reindex (if only perorm on one)", :type => :string
end

opts = opts.delete_if { |_, v| v == false }
EvmDatabaseOps.gc(opts)
args = {}
opts = opts.delete_if { |_, v| v == false }
options = (options[:aggressive] ? GC_AGGRESSIVE_DEFAULTS : GC_DEFAULTS).merge(opts)

pg_env = {"PGUSER" => options[:username], "PGPASSWORD" => options[:password]}.delete_blanks

raise "Vacuum requires database" unless options[:dbname]

vacuum_args = {}
vacuum_args[:analyze] = nil if options[:analyze]
vacuum_args[:full] = nil if options[:full]
vacuum_args[:verbose] = nil if options[:verbose]
vacuum_args[:table] = options[:table] if options[:table]

run_command("vacuumdb", opts, args)

$log.info("Running command... #{AwesomeSpawn.build_command_line("vacuumdb", params)}")
output = AwesomeSpawn.run!("vacuumdb", :params => params, :env => pg_env).output
$log.info("Output... #{result}") if output.to_s.length > 0

if options[:reindex]
reindex_args = {}
reindex_args[:table] = options[:table] if options[:table]

$log.info("Running command... #{AwesomeSpawn.build_command_line("reindexdb", params)}")
output = AwesomeSpawn.run!("reindexdb", :params => params, :env => pg_env).output
$log.info("Output... #{result}") if output.to_s.length > 0
end

exit # exit so that parameters to the first rake task are not run as rake tasks
end
Expand Down Expand Up @@ -188,89 +214,6 @@ namespace :evm do

exit # exit so that parameters to the first rake task are not run as rake tasks
end

# Example usage:
# bin/rake evm:db:backup:local -- --local-file /tmp/db_backup_test --dbname vmdb_production
# bin/rake evm:db:backup:remote -- --uri smb://dev005.manageiq.com/share1 --uri-username samba_one --uri-password "abc" --remote-file-name region1
# bin/rake evm:db:restore:local -- --local-file /tmp/db_backup_test
# bin/rake evm:db:restore:remote -- --uri smb://dev005.manageiq.com/share1/db_backup/region1 --uri-username samba_one --uri-password "abc"

namespace :backup do
require File.expand_path(File.join(Rails.root, "lib", "evm_database_ops"))
desc 'Backup the local ManageIQ EVM Database (VMDB) to a local file'
task :local do
opts = EvmDba.with_options(:local_file, :splitable, :db_credentials)

EvmDatabaseOps.backup(opts)

exit # exit so that parameters to the first rake task are not run as rake tasks
end

desc 'Backup the local ManageIQ EVM Database (VMDB) to a remote file'
task :remote do
opts = EvmDba.with_options(:remote_uri, :aws, :remote_file, :splitable, :db_credentials)

db_opts = EvmDba.collect_db_opts(opts)
connect_opts = EvmDba.collect_connect_opts(opts)

EvmDatabaseOps.backup(db_opts, connect_opts)

exit # exit so that parameters to the first rake task are not run as rake tasks
end
end

namespace :dump do
require Rails.root.join("lib", "evm_database_ops").expand_path.to_s
desc 'Dump the local ManageIQ EVM Database (VMDB) to a local file'
task :local do
opts = EvmDba.with_options(:local_file, :splitable, :db_credentials, :exclude_table_data)

EvmDatabaseOps.dump(opts)

exit # exit so that parameters to the first rake task are not run as rake tasks
end

desc 'Dump the local ManageIQ EVM Database (VMDB) to a remote file'
task :remote do
opts = EvmDba.with_options(:remote_uri, :aws, :remote_file, :splitable, :db_credentials, :exclude_table_data)

db_opts = EvmDba.collect_db_opts(opts)
connect_opts = EvmDba.collect_connect_opts(opts)

EvmDatabaseOps.dump(db_opts, connect_opts)

exit # exit so that parameters to the first rake task are not run as rake tasks
end
end

namespace :restore do
desc 'Restore the local ManageIQ EVM Database (VMDB) from a local backup file'
task :local => :environment do
opts = EvmDba.with_options(:local_file, :db_credentials)

# If running through runner, disconnect any local connections
ActiveRecord::Base.clear_all_connections! if ActiveRecord && ActiveRecord::Base

EvmDatabaseOps.restore(opts)

exit # exit so that parameters to the first rake task are not run as rake tasks
end

desc 'Restore the local ManageIQ EVM Database (VMDB) from a remote backup file'
task :remote => :environment do
opts = EvmDba.with_options(:remote_uri, :aws, :db_credentials)

db_opts = EvmDba.collect_db_opts(opts)
connect_opts = EvmDba.collect_connect_opts(opts)

# If running through runner, disconnect any local connections
ActiveRecord::Base.clear_all_connections! if ActiveRecord && ActiveRecord::Base

EvmDatabaseOps.restore(db_opts, connect_opts)

exit # exit so that parameters to the first rake task are not run as rake tasks
end
end
end
end

Expand Down
Loading

0 comments on commit ef83ee7

Please sign in to comment.