<commit_before>require "right_aws"
require "yaml"

class S3dbBackup

  class << self
    attr_accessor :rails_env
    attr_accessor :version
    @version = File.open(File.expand_path(File.dirname(__FILE__)) + "/../VERSION", "r").read
    puts "s3db-backup Version #{@version}" if ::Rails.env == "development"
  end

  def self.backup
    aws = YAML::load_file(File.join(Rails.root, "config", "s3_config.yml"))
    config = ActiveRecord::Base.configurations[::Rails.env]

    mysqldump = `which mysqldump`.strip
    raise "Please make sure that 'mysqldump' is installed and in your path!" if mysqldump.empty?

    gzip = `which gzip`.strip
    raise "Please make sure that 'gzip' is installed and in your path!" if gzip.empty?

    ccrypt = `which ccrypt`.strip
    raise "Please make sure that 'ccrypt' is installed and in your path!" if ccrypt.empty?

    raise "Please specify a bucket for your #{::Rails.env} environment in config/s3config.yml" if aws[::Rails.env].nil?

    latest_dump = "mysql-#{config['database']}-#{Time.now.strftime('%d-%m-%Y-%Hh%Mm%Ss')}.sql.gz"
    mysql_dump_path = Tempfile.new(latest_dump).path


    system("#{mysqldump} --user=#{config['username']} --password=#{config['password']} #{config['host'] ? "-h #{config['host']}" : ''} #{config['database']} | #{gzip} -9 > #{mysql_dump_path}")

    encrypted_file_path = Tempfile.new("ccrypt_tempfile").path
    ccrypt_command = "cat #{mysql_dump_path} | #{ccrypt} -k #{File.join(Rails.root, "db", "secret.txt")} -e > #{encrypted_file_path}"
    `#{ccrypt_command}`
<commit_msg>make backup filenames chronologically sortable<commit_after>require "right_aws"
require "yaml"

class S3dbBackup

  class << self
    attr_accessor :rails_env
    attr_accessor :version
    @version = File.open(File.expand_path(File.dirname(__FILE__)) + "/../VERSION", "r").read
    puts "s3db-backup Version #{@version}" if ::Rails.env == "development"
  end

  def self.backup
    aws = YAML::load_file(File.join(Rails.root, "config", "s3_config.yml"))
    config = ActiveRecord::Base.configurations[::Rails.env]

    mysqldump = `which mysqldump`.strip
    raise "Please make sure that 'mysqldump' is installed and in your path!" if mysqldump.empty?

    gzip = `which gzip`.strip
    raise "Please make sure that 'gzip' is installed and in your path!" if gzip.empty?

    ccrypt = `which ccrypt`.strip
    raise "Please make sure that 'ccrypt' is installed and in your path!" if ccrypt.empty?

    raise "Please specify a bucket for your #{::Rails.env} environment in config/s3config.yml" if aws[::Rails.env].nil?

    latest_dump = "mysql-#{config['database']}-#{Time.now.strftime('%Y-%m-%d-%Hh%Mm%Ss')}.sql.gz"
    mysql_dump_path = Tempfile.new(latest_dump).path


    system("#{mysqldump} --user=#{config['username']} --password=#{config['password']} #{config['host'] ? "-h #{config['host']}" : ''} #{config['database']} | #{gzip} -9 > #{mysql_dump_path}")

    encrypted_file_path = Tempfile.new("ccrypt_tempfile").path
    ccrypt_command = "cat #{mysql_dump_path} | #{ccrypt} -k #{File.join(Rails.root, "db", "secret.txt")} -e > #{encrypted_file_path}"
    `#{ccrypt_command}`

{'fraction_non_alphanumeric': 0.1693728112066221, 'fraction_numerical': 0.003183699458771092, 'mean_word_length': 4.426597582037997, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2836399', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1076, 'n_words': 250}