Sha256: fea3a3aeb9263c22a6d6c25082c9bfd6f09bdde4fa26121640dd7fcd1ede8114

Contents?: true

Size: 1.95 KB

Versions: 3

Compression:

Stored size: 1.95 KB

Contents

class String
   def truncate(limit = 1)
     self.match(%r{^(.{0,#{limit}})})[1]
   end
end

module EY
  module Backup
    class Dumper < Base
      require 'shellwords'
      include Logging

      attr_reader :database

      def self.run(databases, split_size)
        exceptions = []
        completed = []
        databases.each do |database|
          begin
            backup_size = new(database).run(split_size)
            completed << "#{database.name} (#{backup_size})"
          rescue => e
            puts e
            exceptions << database.name
            next
          end
        end
        message = ''
        message = message + "Failures: #{exceptions}" if ! exceptions.empty?
        message = message + ", " if ! exceptions.empty? and ! completed.empty?
        message = message + "Completed successfully: #{completed}" if ! completed.empty?
        
        alert_level=exceptions.empty? ? 'OKAY' : 'FAILURE'
        
        # we don't provide alert here unless its a failure
        unless alert_level == 'OKAY'
          message.gsub!("\n", '\n')
          message = Shellwords.escape(message).truncate(255)
          full_txt= "Severity: #{alert_level}\n" \
                  + "Time: #{Time.now.to_i}\n" \
                  + "Type: process-dbbackup summary\n" \
                  + "Plugin: exec\n"
          full_txt = Shellwords.escape(full_txt)
          full_txt += "raw_message:\\ \\'#{message}\\'"
          alert_command = %Q(echo #{full_txt} | /engineyard/bin/ey-alert.rb 2>&1)
          system(alert_command)
        end
      end

      def initialize(database)
        @database  = database
      end

      def run(split_size)
        info("Doing database: #{@database.name}")

        backup_set = @database.dump
        backup_set.split!(split_size)
        backup_set.upload!

        okay(@database.name, @database.backup_size)
        backup_set.cleanup
        backup_set.rm!
        @database.backup_size
      end
      
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ey_cloud_server-1.5.0 lib/ey_backup/dumper.rb
ey_cloud_server-1.4.61 lib/ey_backup/dumper.rb
ey_cloud_server-1.4.60 lib/ey_backup/dumper.rb