Class: Yob::Database::Postgresql
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #full_backup ⇒ Object
-
#initialize(configuration) ⇒ Postgresql
constructor
A new instance of Postgresql.
- #partial_backup ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Postgresql
Returns a new instance of Postgresql.
74 75 76 77 |
# File 'lib/yob/database.rb', line 74 def initialize(configuration) super require 'archive/tar/minitar' end |
Instance Method Details
#full_backup ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/yob/database.rb', line 79 def full_backup require 'pg' connect_and_execute "SELECT pg_start_backup('yob')" begin writer = yield Time.now.strftime("%Y%m%d-%H%M%S#{random_filename_string}.tar.gpg"), nil tar = Archive::Tar::Minitar::Output.new(writer) begin Find.find(configuration.postgresql_data_directory) do |entry| Archive::Tar::Minitar.pack_file(entry, tar) unless entry.include?("/pg_xlog/") end ensure tar.close end writer.close ensure connect_and_execute "SELECT pg_stop_backup()" end end |
#partial_backup ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/yob/database.rb', line 100 def partial_backup raise "yob partial must be called with two more arguments - the full path and the destination filename - for a postgresql partial backup" unless ARGV.length == 3 full_path = ARGV[1] destination_filename = ARGV[2] File.open(full_path, "r") do |file| yield "#{destination_filename}#{random_filename_string}", file end end |