<commit_before>require 'open3'

module MysqlTools
  class Backup

    def self.init
      desc "Backup a database"
      long_desc <<-EOS
		Dump the seletected database using 'mysqldump'.
		EOS
      arg_name "database_name"
      command :backup do |c|

        c.desc "Output filename"
        c.arg_name "FILENAME"
        c.default_value '#{database_name}-#{timestamp}.sql.gz'
        c.flag [:'output-file']

        c.desc "Output path"
        c.arg_name "PATH"
        c.default_value '.'
        c.flag [:'output-path']

        c.action do |global,command,args|
          MysqlTools::Backup.new(global, command,args).run
        end
      end
    end

    def self.pre(global, options, args)
      verbose "Backup command, pre check."
      raise "Required parameter missing" if (global[:username].nil? or
                                             global[:password].nil? or
                                             global[:host].nil? or
                                             args.nil? or args.first.nil?)
      true
    end

    # ----------------------------------------

    def initialize(global, options, args)
      @global, @options, @args = global, options, args
    end

    def run
      @args.each do |database_name|
        mysqldump = ["mysqldump",
                     # consistent DB dumps
                     "--single-transaction",
                     # make dump "nicer", so my_obfuscate can read it and Ruby does not choke
                     "--complete-insert", "--default-character-set=utf8", "--hex-blob",
                     "--user=#{@global[:username]}", "--password=#{@global[:password]}", database_name]
        gzip = ["nice", "pigz"]

        timestamp = Time.now.strftime("%Y%m%d-%H%M%S")
        output_file = eval( '"' + @options[:'output-file'] + '"' )
        output = File.join(@options[:'output-path'], output_file)<commit_msg>Consistent timestamp when dumping multiple Dbs.<commit_after>require 'open3'

module MysqlTools
  class Backup

    def self.init
      desc "Backup a database"
      long_desc <<-EOS
		Dump the seletected database using 'mysqldump'.
		EOS
      arg_name "database_name"
      command :backup do |c|

        c.desc "Output filename"
        c.arg_name "FILENAME"
        c.default_value '#{database_name}-#{timestamp}.sql.gz'
        c.flag [:'output-file']

        c.desc "Output path"
        c.arg_name "PATH"
        c.default_value '.'
        c.flag [:'output-path']

        c.action do |global,command,args|
          MysqlTools::Backup.new(global, command,args).run
        end
      end
    end

    def self.pre(global, options, args)
      verbose "Backup command, pre check."
      raise "Required parameter missing" if (global[:username].nil? or
                                             global[:password].nil? or
                                             global[:host].nil? or
                                             args.nil? or args.first.nil?)
      true
    end

    # ----------------------------------------

    def initialize(global, options, args)
      @global, @options, @args = global, options, args
    end

    def run
      timestamp = Time.now.strftime("%Y%m%d-%H%M%S")

      @args.each do |database_name|
        mysqldump = ["mysqldump",
                     # consistent DB dumps
                     "--single-transaction",
                     # make dump "nicer", so my_obfuscate can read it and Ruby does not choke
                     "--complete-insert", "--default-character-set=utf8", "--hex-blob",
                     "--user=#{@global[:username]}", "--password=#{@global[:password]}", database_name]
        gzip = ["nice", "pigz"]

        output_file = eval( '"' + @options[:'output-file'] + '"' )
        output = File.join(@options[:'output-path'], output_file)
{'fraction_non_alphanumeric': 0.14652686762778505, 'fraction_numerical': 0.0010484927916120576, 'mean_word_length': 1.6610878661087867, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1748478', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1048, 'n_words': 262}