Sha256: 4a42eb4a2c5149184478335ef454ea2c7273290f49daa28e149337cafd30f8b3

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

if File.exist? Rails.root.join('config/mongoid.yml')
  namespace :mongodb do
    config = YAML.load(File.read(Rails.root.join('config/mongoid.yml')))[Rails.env.to_s]['sessions']['default']
    db = config['database']
    host = config['hosts'][0].split(':')[0]
    port = config['hosts'][0].split(':')[1]

    desc 'Start Mongodb'
    task :start do
      zfben_rails_rake_system "mkdir #{Rails.root}/mongo" unless File.exists?(Rails.root.join('mongo'))
      zfben_rails_rake_system "mkdir #{Rails.root}/log" unless File.exists?(Rails.root.join('log'))
      zfben_rails_rake_system "mongod --nohttpinterface --nojournal --port #{port} --bind_ip #{host} --dbpath #{Rails.root}/mongo --fork --logpath #{Rails.root}/log/mongodb.log"
    end

    desc 'Stop Mongodb'
    task :stop do
      path = Rails.root.join('mongo/mongod.lock').to_s
      if File.exists?(path)
        zfben_rails_rake_system "kill `cat #{path}`"
        zfben_rails_rake_system 'rm ' + path
      end
    end

    desc 'Clear mongo folder'
    task :clear do
      zfben_rails_rake_system 'rm -r mongo/*'
    end
    
    backup = "mongodump --host #{host} --port #{port} --db #{db}"
    desc backup
    task :dump do
      zfben_rails_rake_system backup
    end

    restore = "mongorestore --host #{host} --port #{port}"
    desc restore
    task :restore do
      zfben_rails_rake_system restore
    end
    
    desc 'Repair Mongodb'
    task :repair do
      "mongod --nohttpinterface --nojournal --port #{port} --bind_ip #{host} --dbpath #{Rails.root}/mongo --repair"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
h2ocube_rails_tasks-0.0.1 lib/h2ocube_rails_tasks/tasks/mongodb.rb