Top Level Namespace

Defined Under Namespace

Modules: S3mybackup

Instance Method Summary collapse

Instance Method Details

#execute_sql(sql, user, password) ⇒ Object



8
9
10
11
12
# File 'lib/s3mybackup.rb', line 8

def execute_sql(sql,user,password)
  cmd = "mysql -u #{user} -e \"#{sql}\""
  cmd += " -p'#{password}' " unless password.nil?
  run_system cmd
end

#get_bucket(global_options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/s3mybackup.rb', line 14

def get_bucket(global_options)
  s3 = AWS::S3.new

  bucket_name = global_options[:bucket]
  bucket = s3.buckets[bucket_name]

  if not bucket.exists? then
    bucket = s3.buckets.create(bucket_name)
  end
  bucket
end

#get_database_dir(database, ip = get_ip) ⇒ Object



30
31
32
# File 'lib/s3mybackup.rb', line 30

def get_database_dir(database,ip = get_ip)
  database_dir = "#{ip}/#{database}"
end

#get_full_backup_file_name(time_string = (Time.now).strftime('%Y%m%d%H%M%S')) ⇒ Object



34
35
36
# File 'lib/s3mybackup.rb', line 34

def get_full_backup_file_name(time_string = (Time.now).strftime('%Y%m%d%H%M%S'))
  "#{time_string}dump.sql.gz"
end

#get_ipObject



26
27
28
# File 'lib/s3mybackup.rb', line 26

def get_ip
  IPSocket.getaddress(Socket.gethostname).gsub!(/\./, "")
end

#retrieve_file(bucket, database_dir, file_name) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/s3mybackup.rb', line 38

def retrieve_file(bucket,database_dir,file_name)

  full_dump = bucket.objects["#{database_dir}/#{file_name}"]

  File.open("#{@temp_dir}/#{file_name}", 'w') do |f|
    full_dump.read do |chunk|
      f.write(chunk)
    end
  end
end

#run_system(command) ⇒ Object



3
4
5
6
# File 'lib/s3mybackup.rb', line 3

def run_system(command)
  result = system(command)
  raise("error, process exited with status #{$?.exitstatus}") unless result
end