Class: EyBackup::PostgresqlBackup

Inherits:
MysqlBackup show all
Defined in:
lib/postgresql_backup.rb

Instance Method Summary collapse

Methods inherited from MysqlBackup

#cleanup, #download, #find_obj, #initialize, #list, #new_backup, #normalize_name

Constructor Details

This class inherits a constructor from EyBackup::MysqlBackup

Instance Method Details

#backup_database(database) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/postgresql_backup.rb', line 3

def backup_database(database)
  full_path_to_backup = "#{self.backup_dir}/#{database}.#{@tmpname}"
  posgrecmd = "PGPASSWORD='#{@dbpass}' pg_dump --clean --no-owner --no-privileges -U#{@dbuser} #{database} | gzip - > #{full_path_to_backup}"
  if system(posgrecmd)
    AWS::S3::S3Object.store(
       "/#{@id}.#{database}/#{database}.#{@tmpname}",
       open(full_path_to_backup),
       @bucket,
       :access => :private
    )
    FileUtils.rm full_path_to_backup
    puts "successful backup: #{database}.#{@tmpname}"
  else
    raise "Unable to dump database#{database} wtf?"
  end
end

#restore(index) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/postgresql_backup.rb', line 20

def restore(index)
  name = download(index)
  db = name.split('.').first
  cmd = "gunzip -c #{name} | PGPASSWORD='#{@dbpass}' psql -U#{@dbuser} #{db}"
  if system(cmd)
    puts "successfully restored backup: #{name}"
  else
    puts "FAIL"
  end    
end