<commit_before>require 'AWS'
require 'shell_command'
require 'yaml'
require 'socket'

class EbsSnapshot
  VERSION = '0.0.2'
  attr_reader :config
  
  def self.snapshot
    new.snapshot
  end
  
  def initialize
    check_config
    @config   = YAML::load(File.open('/etc/ebs_snapshot.yml'))
    @suspend  = ShellCommand.new("/usr/sbin/xfs_freeze -f")
    @resume   = ShellCommand.new("/usr/sbin/xfs_freeze -u")
    ec2_connect
  end
  
  def snapshot
    self.config['snapshots'].each do |snapshot|
      if snapshot['db']
        self.db_snapshot(snapshot['path'],snapshot['volume'])
      else
        self.fs_snapshot(snapshot['path'],snapshot['volume'])
      end
    end
  end
  
  def db_snapshot(path,volume)
    require 'sequel' unless Object.const_defined?('Sequel')
    begin
      db_connect
      master_status = lock_db
      description = <<-EOD
DB backup on #{hostname} at #{timestamp}
 volume: #{volume}
 path: #{path}
 master_file: #{master_status[:File]}
 master_pos: #{master_status[:Position]}
      EOD
      snap_out = take_snapshot(path,volume,description)
      unlock_db
      snap_out["snapshotId"]
    rescue StandardError => e
      unlock_db
      puts e.message
      exit(3)
    end
  end
  
  def fs_snapshot(path,volume)
    begin
      description = <<-EOD
FS backup on #{hostname} at #{timestamp}
 volume: #{volume}
 path: #{path}
      EOD
      snap_out = take_snapshot(path,volume,description)
      snap_out["snapshotId"]
    rescue StandardError => e
      puts e.message
      exit(3)
    end
  end
  <commit_msg>another change on output description<commit_after>require 'AWS'
require 'shell_command'
require 'yaml'
require 'socket'

class EbsSnapshot
  VERSION = '0.0.2'
  attr_reader :config
  
  def self.snapshot
    new.snapshot
  end
  
  def initialize
    check_config
    @config   = YAML::load(File.open('/etc/ebs_snapshot.yml'))
    @suspend  = ShellCommand.new("/usr/sbin/xfs_freeze -f")
    @resume   = ShellCommand.new("/usr/sbin/xfs_freeze -u")
    ec2_connect
  end
  
  def snapshot
    self.config['snapshots'].each do |snapshot|
      if snapshot['db']
        self.db_snapshot(snapshot['path'],snapshot['volume'])
      else
        self.fs_snapshot(snapshot['path'],snapshot['volume'])
      end
    end
  end
  
  def db_snapshot(path,volume)
    require 'sequel' unless Object.const_defined?('Sequel')
    begin
      db_connect
      master_status = lock_db
      file = master_status[:File]
      pos  = master_status[:Position]
      description = "#{hostname}:#{path} (#{file}, #{pos})"
      snap_out = take_snapshot(path,volume,description)
      unlock_db
      snap_out["snapshotId"]
    rescue StandardError => e
      unlock_db
      puts e.message
      exit(3)
    end
  end
  
  def fs_snapshot(path,volume)
    begin
      description = "#{hostname}:#{path}"
      snap_out = take_snapshot(path,volume,description)
      snap_out["snapshotId"]
    rescue StandardError => e
      puts e.message
      exit(3)
    end
  end
  
{'fraction_non_alphanumeric': 0.11817576564580559, 'fraction_numerical': 0.0039946737683089215, 'mean_word_length': 2.933246073298429, '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': '308868', 'n_tokens_mistral': 975, 'n_tokens_neox': 1017, 'n_words': 206}