module Validations

Common methods used for setting up or verifing

Public Instance Methods

check_backup_path(raise_msg = 'backup_path is not a valid directory') click to toggle source

Check that the backup_path is valid @param [String] raise_msg exception to raise if the backup_path is not a valid direcotry. if set to nil no exception will be rasied @return [Bool]

# File lib/validations.rb, line 20
def check_backup_path(raise_msg = 'backup_path is not a valid directory')
  if !File.directory?($backup_path)
    raise raise_msg if raise_msg
    return false
  end
  true
end
check_mogile_domain(domain, raise_msg = 'Domain does not exist in MogileFS') click to toggle source

Check if mogile domain is valid @param [String] raise_msg exception to raise if domain does not exist. if set to nil no exception will be raised @return [Bool]

# File lib/validations.rb, line 110
def check_mogile_domain(domain, raise_msg = 'Domain does not exist in MogileFS')
  require('domain')
  domain = Domain.find_by_namespace(self.domain)
  if !domain
    raise raise_msg if raise_msg
    return false
  end
  true
end
check_settings_file(raise_msg = 'settings.yml not found in path. This must not be a backup profile. See: mogbak help create') click to toggle source

Check that the settings.yml file exists in the backup_path @param [String] raise_msg exception to raise if the file is missing. if set to nil no exception will be rasied @return [Bool]

# File lib/validations.rb, line 7
def check_settings_file(raise_msg = 'settings.yml not found in path.  This must not be a backup profile. See: mogbak help create')
  if File.exists?("#{$backup_path}/settings.yml")
    return true
  else
    raise raise_msg if raise_msg
    return false
  end
end
connect_sqlite(raise_msg = nil) click to toggle source

Connect to sqlite metadata db @param [String] raise_msg exception to raise if we cannot connect. if set to nil no exception will be rasied @return [Bool]

# File lib/validations.rb, line 46
def connect_sqlite(raise_msg = nil)
  begin
    ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => "#{$backup_path}/db.sqlite", :timeout => 10000)
  rescue Exception => e
    raise raise_msg if raise_msg
    raise e if $debug
    return false
  end
  true
end
create_sqlite_db(raise_msg = "Could not create click to toggle source

Create database for metadata @param [String] raise_msg exception to raise if database cannot be created. nil will raise no exception @return [Bool]

# File lib/validations.rb, line 31
def create_sqlite_db(raise_msg = "Could not create #{$backup_path}/db.sqlite - check permissions")
  begin
    if !File.exists?("#{$backup_path}/db.sqlite")
      SQLite3::Database.new("#{$backup_path}/db.sqlite")
    end
  rescue Exception => e
    raise raise_msg if raise_msg
    return false
  end
  true
end
migrate_sqlite(raise_msg = "could not run migrations on click to toggle source

Run ActiveRecord migrations on the sqlite database @param [String] raise_msg exception to raise if migrations fail. if set to nil no exception will be rasied @return [Bool]

# File lib/validations.rb, line 60
def migrate_sqlite(raise_msg = "could not run migrations on #{$backup_path}/db.sqlite")
  #run migrations
  begin
    ActiveRecord::Migrator.up(File.expand_path(File.dirname(__FILE__)) + '/../db/migrate/')
  rescue
    raise raise_msg if raise_msg
    return false
  end
  true
end
mogile_db_connect(raise_msg = 'Could not connect to MySQL database') click to toggle source

Connect to MogileFS mysql server @param [String] raise_msg exception to raise if we cannot connect. if set to nil no exception will be rasied @return [Bool]

# File lib/validations.rb, line 74
def mogile_db_connect(raise_msg = 'Could not connect to MySQL database')
  #Verify that we can connect to the mogilefs mysql server
  begin
    ActiveRecord::Base.establish_connection({:adapter => "mysql2",
                                             :host => @db_host,
                                             :port => @db_port,
                                             :username => @db_user,
                                             :password => @db_pass,
                                             :database => @db,
                                             :reconnect => true})
  rescue Exception => e
    raise raise_msg if raise_msg
    return false
  end
  true
end
mogile_tracker_connect(raise_msg = 'Could not connect to MogileFS tracker') click to toggle source

Connect to mogile tracker @param [String] raise_msg exception to raise if we cannot connect. if set to nil no exception will be raised @return [Bool]

# File lib/validations.rb, line 94
def mogile_tracker_connect(raise_msg = 'Could not connect to MogileFS tracker')
  host = ["#{@tracker_ip}:#{@tracker_port}"]
  begin
  $mg = MogileFS::MogileFS.new(:domain => @domain, :hosts => host)
  rescue Exception => e
    if $debug
      raise e
    end
    raise raise_msg if raise_msg
    return false
  end
end