class SwarmClusterCliOpe::SyncConfigs::MongoDb
Public Instance Methods
pull()
click to toggle source
@return [TrueClass, FalseClass]
# File lib/swarm_cluster_cli_ope/sync_configs/mongo_db.rb, line 6 def pull resume('pull') if yes?("Confermare il comando?[y,yes]") tmp_file = make_dump(remote, container) local_container.copy_in(tmp_file, tmp_file) restore(tmp_file, remote, local, local_container) end true end
push()
click to toggle source
@return [TrueClass, FalseClass]
# File lib/swarm_cluster_cli_ope/sync_configs/mongo_db.rb, line 20 def push resume('PUSH') if yes?("ATTENZIONE !!!!!!PUSH!!!!! - Confermare il comando?[y,yes]") tmp_file = make_dump(local, local_container) container.copy_in(tmp_file, tmp_file) restore(tmp_file, local, remote, container) end true end
Private Instance Methods
make_dump(environment, cnt)
click to toggle source
@param [EnvConfigs] environment @param [SwarmClusterCliOpe::Models::Container] cnt
# File lib/swarm_cluster_cli_ope/sync_configs/mongo_db.rb, line 74 def make_dump(environment, cnt) tmp_file = "/tmp/dump.#{Time.now.to_i}.archive" command = [] command << "bash -c '" command << "mongodump --db #{environment.database_name} " environment.excluded_collections.each do |collection| command << " --excludeCollection \"#{collection}\" " end command << "--username \"#{environment.username}\" " if environment.username command << "--password \"#{environment.password}\" " if environment.password command << "--archive --gzip" command << "' > #{tmp_file}" cnt.exec(command.join " ") tmp_file end
restore(tmp_file, from_env, to_env, cnt)
click to toggle source
@param [String] tmp_file @param [EnvConfigs] from_env environment sorgente (per rinominare anche il nome del DB) @param [EnvConfigs] to_env environment di arrivo (per rinominare anche il nome del DB) @param [SwarmClusterCliOpe::Models::Container] cnt in cui eseguire l'import
# File lib/swarm_cluster_cli_ope/sync_configs/mongo_db.rb, line 60 def restore(tmp_file, from_env, to_env, cnt) command = [] command << "bash -c '" command << "mongorestore" command << "--nsFrom '#{from_env.database_name}.*'" command << "--nsTo '#{to_env.database_name}.*'" command << "--drop --archive=#{tmp_file} --gzip" command << "'" cnt.exec(command.join " ") end