Class: RBarman::Backup
- Inherits:
-
Object
- Object
- RBarman::Backup
- Defined in:
- lib/rbarman/backup.rb
Overview
Represents a barman Backup
Instance Attribute Summary collapse
- #backup_end ⇒ Object
- #backup_start ⇒ Object
- #begin_wal ⇒ Object
-
#deleted ⇒ Boolean
readonly
If the backup has been deleted.
- #end_wal ⇒ Object
- #error ⇒ Object
- #id ⇒ Object
-
#pg_version ⇒ Integer?
The backup’s PostgreSQL version.
- #pgdata ⇒ Object
-
#server ⇒ String?
Name of the server to which the backup belongs.
- #size ⇒ Object
- #status ⇒ Object
- #timeline ⇒ Object
- #wal_file_size ⇒ Object
- #wal_files ⇒ Object
Class Method Summary collapse
-
.backup_id_valid?(id) ⇒ Boolean
If id is a valid backup id.
-
.by_id(server, backup_id, opts = {}) ⇒ Backup
Get a specific backup.
-
.create(server) ⇒ Backup
Instructs the underlying (barman) command to create a new backup.
Instance Method Summary collapse
-
#add_wal_file(wal_file) ⇒ void
Adds a wal file to the backup.
-
#delete ⇒ Object
Instructs the underlying (barman) command to delete the backup and sets its flag #deleted to true.
-
#initialize ⇒ Backup
constructor
A new instance of Backup.
-
#missing_wal_files ⇒ WalFiles
All wal files which don’t exist in this backup.
-
#needed_wal_files ⇒ WalFiles
All wal files which should exist in this backup.
-
#recover(path, opts = {}) ⇒ void
Instructs the underlying (barman) command to recover this backup.
-
#wal_file_already_added?(wal_file) ⇒ Boolean
If the wal file is already added to the backup.
-
#xlog_range ⇒ Array, String
A range of available xlog entries.
Constructor Details
#initialize ⇒ Backup
Returns a new instance of Backup.
114 115 116 |
# File 'lib/rbarman/backup.rb', line 114 def initialize @deleted = false end |
Instance Attribute Details
#backup_end ⇒ Time? #backup_end= ⇒ Object
41 42 43 |
# File 'lib/rbarman/backup.rb', line 41 def backup_end @backup_end end |
#backup_start ⇒ Time? #backup_start= ⇒ Object
34 35 36 |
# File 'lib/rbarman/backup.rb', line 34 def backup_start @backup_start end |
#begin_wal ⇒ WalFile? #begin_wal= ⇒ Object
78 79 80 |
# File 'lib/rbarman/backup.rb', line 78 def begin_wal @begin_wal end |
#deleted ⇒ Boolean (readonly)
Returns if the backup has been deleted.
112 113 114 |
# File 'lib/rbarman/backup.rb', line 112 def deleted @deleted end |
#end_wal ⇒ WalFile? #end_wal= ⇒ Object
85 86 87 |
# File 'lib/rbarman/backup.rb', line 85 def end_wal @end_wal end |
#error ⇒ String? #error= ⇒ Object
108 109 110 |
# File 'lib/rbarman/backup.rb', line 108 def error @error end |
#pg_version ⇒ Integer?
Returns the backup’s PostgreSQL version.
17 18 19 |
# File 'lib/rbarman/backup.rb', line 17 def pg_version @pg_version end |
#pgdata ⇒ String? #pgdata= ⇒ Object
101 102 103 |
# File 'lib/rbarman/backup.rb', line 101 def pgdata @pgdata end |
#server ⇒ String?
Returns name of the server to which the backup belongs.
14 15 16 |
# File 'lib/rbarman/backup.rb', line 14 def server @server end |
#size ⇒ Integer? #size= ⇒ Object
64 65 66 |
# File 'lib/rbarman/backup.rb', line 64 def size @size end |
#status ⇒ Symbol? #status= ⇒ Object
49 50 51 |
# File 'lib/rbarman/backup.rb', line 49 def status @status end |
#timeline ⇒ Integer? #timeline= ⇒ Object
93 94 95 |
# File 'lib/rbarman/backup.rb', line 93 def timeline @timeline end |
#wal_file_size ⇒ Integer? #wal_file_size= ⇒ Object
71 72 73 |
# File 'lib/rbarman/backup.rb', line 71 def wal_file_size @wal_file_size end |
#wal_files ⇒ WalFiles? #wal_files= ⇒ Object
57 58 59 |
# File 'lib/rbarman/backup.rb', line 57 def wal_files @wal_files end |
Class Method Details
.backup_id_valid?(id) ⇒ Boolean
Returns if id is a valid backup id.
197 198 199 200 |
# File 'lib/rbarman/backup.rb', line 197 def self.backup_id_valid?(id) return false if id.nil? return !id.to_s.match(/\d{8,8}T\d{6,6}/).nil? end |
.by_id(server, backup_id, opts = {}) ⇒ Backup
Get a specific backup
296 297 298 299 |
# File 'lib/rbarman/backup.rb', line 296 def self.by_id(server, backup_id, opts = {}) cmd = CliCommand.new return cmd.backup(server, backup_id, opts) end |
.create(server) ⇒ Backup
Instructs the underlying (barman) command to create a new backup.
283 284 285 286 287 288 |
# File 'lib/rbarman/backup.rb', line 283 def self.create(server) cmd = CliCommand.new cmd.create(server) backups = Backups.all(server, { :with_wal_files => false }) return Backup.by_id(server, backups.latest.id, { :with_wal_files => true }) end |
Instance Method Details
#add_wal_file(wal_file) ⇒ void
This method returns an undefined value.
Adds a wal file to the backup
180 181 182 183 |
# File 'lib/rbarman/backup.rb', line 180 def add_wal_file(wal_file) @wal_files = WalFiles.new if @wal_files.nil? @wal_files << WalFile.parse(wal_file) end |
#delete ⇒ Object
Instructs the underlying (barman) command to delete the backup and sets its flag #deleted to true
203 204 205 206 207 |
# File 'lib/rbarman/backup.rb', line 203 def delete cmd = CliCommand.new cmd.delete(@server, @id) @deleted = true end |
#missing_wal_files ⇒ WalFiles
Returns all wal files which don’t exist in this backup.
248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/rbarman/backup.rb', line 248 def missing_wal_files missing = Array.new needed_wal_files.each do |needed| existing = nil @wal_files.each do |f| if f == needed existing = f break end end missing << needed unless existing end WalFiles.new(missing) end |
#needed_wal_files ⇒ WalFiles
Returns all wal files which should exist in this backup.
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/rbarman/backup.rb', line 221 def needed_wal_files needed = Array.new xlog_range.each do |xlog| start = 0 if @begin_wal.xlog == xlog.to_s.rjust(8,'0') start = @begin_wal.segment.to_i(16) end # http://wiki.postgresql.org/wiki/What's_new_in_PostgreSQL_9.3#WAL_filenames_may_end_in_FF end_segment = 255 if @pg_version.nil? || @pg_version < 90300 end_segment = 254 end (start..end_segment).each do |seg| n_timeline = @begin_wal.timeline n_xlog = xlog.rjust(8,'0') n_segment = seg.to_s(16).rjust(8,'0').upcase w = WalFile.parse(n_timeline + n_xlog + n_segment) needed << w break if w == @wal_files.last end end WalFiles.new(needed) end |
#recover(path, opts = {}) ⇒ void
when :remote_ssh_cmd is passed in options, ‘path’ is the path on the remote host, otherwise local
This method returns an undefined value.
Instructs the underlying (barman) command to recover this backup
275 276 277 278 |
# File 'lib/rbarman/backup.rb', line 275 def recover(path, opts = {}) cmd = CliCommand.new cmd.recover(@server, @id, path, opts) end |
#wal_file_already_added?(wal_file) ⇒ Boolean
Returns if the wal file is already added to the backup.
187 188 189 190 |
# File 'lib/rbarman/backup.rb', line 187 def wal_file_already_added?(wal_file) return false if @wal_files.nil? return @wal_files.include?(WalFile.parse(wal_file)) end |
#xlog_range ⇒ Array, String
Returns a range of available xlog entries.
210 211 212 213 214 215 216 217 218 |
# File 'lib/rbarman/backup.rb', line 210 def xlog_range start_xlog = @begin_wal.xlog end_xlog = @wal_files.last.xlog xlog_range = Array.new (start_xlog.to_i(16)..end_xlog.to_i(16)).to_a.each do |i| xlog_range << i.to_s(16).upcase end xlog_range end |