Class: PoringBackup::Databases::PostgreSQL

Inherits:
PoringBackup::Database show all
Defined in:
lib/poring_backup/databases/postgresql.rb

Instance Attribute Summary

Attributes inherited from PoringBackup::Database

#created_at, #db_name, #file, #file_dir, #file_path, #path, #setting, #tmp_dir, #tmp_file_path

Instance Method Summary collapse

Methods inherited from PoringBackup::Database

#clear_tmp!

Constructor Details

#initialize(setting, &block) ⇒ PostgreSQL

Returns a new instance of PostgreSQL.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/poring_backup/databases/postgresql.rb', line 5

def initialize setting, &block
  @db_name = nil
  @host = 'localhost'
  @port = nil
  @username = nil
  @password = nil

  instance_eval(&block) if block_given?
  @file = "#{db_name}.pgsql"
  super
end

Instance Method Details

#backupObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/poring_backup/databases/postgresql.rb', line 17

def backup
  PoringBackup.logger.info "PostgreSQL backup processing"
  super
  begin
    system db_dump
    PoringBackup.logger.info "#{' '*18}success"
  rescue => e
    PoringBackup.logger.warn "#{' '*18}failed!"
    PoringBackup.logger.debug "#{' '*18}tmp_file: #{tmp_file_path}"
    PoringBackup.logger.debug "#{' '*18}errors => #{e}"
  end
  PoringBackup.logger.info "#{' '*18}finished"
end

#database(name) ⇒ Object



37
38
39
# File 'lib/poring_backup/databases/postgresql.rb', line 37

def database name
  @db_name = name
end

#db_dumpObject



57
58
59
60
# File 'lib/poring_backup/databases/postgresql.rb', line 57

def db_dump
  "#{password_option}" +
  "pg_dump #{connection_options} #{general_options} #{db_name}"
end

#host(name) ⇒ Object



41
42
43
# File 'lib/poring_backup/databases/postgresql.rb', line 41

def host name
  @host = name
end

#notify_messageObject



62
63
64
# File 'lib/poring_backup/databases/postgresql.rb', line 62

def notify_message
  @notify_message ||= db_name
end

#password(password = nil) ⇒ Object



53
54
55
# File 'lib/poring_backup/databases/postgresql.rb', line 53

def password password=nil
  @password = password
end

#port(number) ⇒ Object



45
46
47
# File 'lib/poring_backup/databases/postgresql.rb', line 45

def port number
  @port = number
end

#restoreObject



31
32
33
34
35
# File 'lib/poring_backup/databases/postgresql.rb', line 31

def restore
  #psql -U {user-name} -d {desintation_db} -f {dumpfilename.sql}
  #psql -U <username> -d <dbname> -1 -f <filename>.sql
  #pg_restore -U <username> -d <dbname> -1 -f <filename>.dump
end

#username(name) ⇒ Object



49
50
51
# File 'lib/poring_backup/databases/postgresql.rb', line 49

def username name
  @username = name
end