Sha256: 3e15e701d5b290b890f99dac6f8fec4855a523ae05f90e6d12522fe8bef955d5

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

module Dumper
  module Database
    class MongoDB < Base
      DUMP_TOOL = 'mongodump'
      FILE_EXT = 'tar.gz'

      def command
        "cd #{tmpdir} && #{dump_tool_path} #{connection_options} #{additional_options} && tar -czf #{filename} --exclude='#{filename}' ."
      end

      def connection_options
        [ :database, :host, :port, :username, :password ].map do |option|
          next if @config[option].blank?
          "--#{option}='#{@config[option]}'".gsub('--database', '--db')
        end.compact.join(' ')
      end

      def additional_options
        "--out='#{tmpdir}'"
      end

      def set_config_for(rails_env=nil)
        return unless defined?(Mongo::DB) &&
          (mongo = find_instance_in_object_space(Mongo::DB))

        @config = {
          :host => mongo.connection.host,
          :port => mongo.connection.port,
          :database => mongo.name,
          :dump_tool => dump_tool_path
        }.tap do |h|
          if auth = mongo.connection.auths.first
            h.update(:username => auth['username'], :password => auth['password'])
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dumper-1.1.3 lib/dumper/database/mongodb.rb
dumper-1.1.2 lib/dumper/database/mongodb.rb