<commit_before>
namespace "db" do

  task :reload => [:drop, :download_and_install]

  desc "Drops the database for mongodb"
  task :drop do
    if (Rails.env == "production")
      raise "FUCK OFF, you're trying to reset the database in production"
      return
    end
    db = Mongoid::Config.master
    conn = db.connection

    puts "DROPPING MONGO DATABASE NAMED #{db.name}"
    conn.drop_database( db.name )
  end

  desc "Reloads the database based the the latest backup from production"
  task :download_and_install do
    if (Rails.env == "production")
      raise "FUCK OFF, you're trying to reset the database in production"
      return
    end
    db = Mongoid::Config.master

    if File.exists?('/tmp/mongodb-latest.tgz')
      file = File.new('/tmp/mongodb-latest.tgz', 'r')
      puts "current file in temp is timestamp: " + file.mtime.to_s
    end

    if file.nil? or file.mtime < 1.day.ago
      puts "getting new backup"
      puts `scp -P 11235 <EMAIL>:/chatham_backups/latest/mongodb-latest.tgz /tmp/mongodb-latest.tgz`
      puts `rm -rf /tmp/MONGOBACKUP`
      puts `mkdir /tmp/MONGOBACKUP`
      puts `tar -C /tmp/MONGOBACKUP -xzvf /tmp/mongodb-latest.tgz`
    end

    # this is a little hacky, but works for now
    puts `/usr/local/mongodb/bin/mongorestore -h #{db.connection.host} -d chatham_#{Rails.env} /tmp/MONGOBACKUP/*/chatham_production/`
    Rake::Task["db:mongoid:create_indexes"].invoke
  end
end
<commit_msg>should be responsibility of the host to have mongorestore on the path, not here<commit_after>
namespace "db" do

  task :reload => [:drop, :download_and_install]

  desc "Drops the database for mongodb"
  task :drop do
    if (Rails.env == "production")
      raise "FUCK OFF, you're trying to reset the database in production"
      return
    end
    db = Mongoid::Config.master
    conn = db.connection

    puts "DROPPING MONGO DATABASE NAMED #{db.name}"
    conn.drop_database( db.name )
  end

  desc "Reloads the database based the the latest backup from production"
  task :download_and_install do
    if (Rails.env == "production")
      raise "FUCK OFF, you're trying to reset the database in production"
      return
    end
    db = Mongoid::Config.master

    if File.exists?('/tmp/mongodb-latest.tgz')
      file = File.new('/tmp/mongodb-latest.tgz', 'r')
      puts "current file in temp is timestamp: " + file.mtime.to_s
    end

    if file.nil? or file.mtime < 1.day.ago
      puts "getting new backup"
      puts `scp -P 11235 <EMAIL>:/chatham_backups/latest/mongodb-latest.tgz /tmp/mongodb-latest.tgz`
      puts `rm -rf /tmp/MONGOBACKUP`
      puts `mkdir /tmp/MONGOBACKUP`
      puts `tar -C /tmp/MONGOBACKUP -xzvf /tmp/mongodb-latest.tgz`
    end

    # this is a little hacky, but works for now
    puts `mongorestore -h #{db.connection.host} -d chatham_#{Rails.env} /tmp/MONGOBACKUP/*/chatham_production/`
    Rake::Task["db:mongoid:create_indexes"].invoke
  end
end

{'fraction_non_alphanumeric': 0.11220673240394424, 'fraction_numerical': 0.004080244814688882, 'mean_word_length': 2.970310391363023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1330239', 'n_tokens_mistral': 1058, 'n_tokens_neox': 1000, 'n_words': 293}